Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(web): add support to copy asset url from asset dashboard #1195

Merged
merged 12 commits into from
Oct 29, 2024
11 changes: 8 additions & 3 deletions web/src/beta/features/AssetsManager/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -112,21 +112,26 @@ const AssetsManager: FC<AssetsManagerProps> = ({
{layout === "list" && (
<ListHeader size={size} width={contentWidth}>
<ThumbnailSpacer />
<Col width={50}>
<Col width={40}>
<Typography weight="bold" size="body">
{t("Name")}
</Typography>
</Col>
<Col width={30}>
<Col width={20}>
<Typography weight="bold" size="body">
{t("Uploaded At")}
</Typography>
</Col>
<Col width={30}>
<Col width={10}>
<Typography weight="bold" size="body">
{t("Size")}
</Typography>
</Col>
<Col width={30}>
<Typography weight="bold" size="body">
{t("Path")}
</Typography>
</Col>
</ListHeader>
)}
<AssetsWrapper ref={assetsWrapperRef}>
Expand Down
46 changes: 38 additions & 8 deletions web/src/beta/features/AssetsManager/item/AssetListItem.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { Icon, Typography } from "@reearth/beta/lib/reearth-ui";
import { Icon, IconButton, Typography } from "@reearth/beta/lib/reearth-ui";
import { formatRelativeTime } from "@reearth/beta/utils/time";
import { useT } from "@reearth/services/i18n";
import { useNotification } from "@reearth/services/state";
import { styled, useTheme } from "@reearth/services/theme";
import { FC, MouseEvent, useCallback, useMemo } from "react";

Expand All @@ -15,6 +17,8 @@ const AssetListItem: FC<AssetItemProps> = ({
() => selectedAssetIds.includes(asset.id),
[selectedAssetIds, asset.id]
);
const t = useT();
const [, setNotification] = useNotification();

const type = useMemo(() => getAssetType(asset), [asset]);

Expand All @@ -28,6 +32,18 @@ const AssetListItem: FC<AssetItemProps> = ({
[asset, onSelect]
);

const handleIconClick = useCallback(
(e: MouseEvent) => {
e.stopPropagation();
navigator.clipboard.writeText(asset.url);
setNotification({
type: "success",
text: t("Asset url copied")
});
},
[asset.url, setNotification, t]
);

const formattedDate = useMemo(
() => formatRelativeTime(new Date(asset.createdAt)),
[asset.createdAt]
Expand All @@ -44,15 +60,25 @@ const AssetListItem: FC<AssetItemProps> = ({
size={20}
/>
</Thumbnail>
<AssetName>
<Typography size="body">{asset.name}</Typography>
</AssetName>
<Col width={30}>
<Col width={40}>
<AssetName>
<Typography size="body">{asset.name}</Typography>
</AssetName>
</Col>
<Col width={20}>
<Typography size="body">{formattedDate}</Typography>
</Col>
<Col width={30}>
<Col width={10}>
<Typography size="body">{formattedSize}</Typography>
</Col>
<Col width={30} title={asset.url}>
<IconButton
appearance="simple"
icon="copy"
onClick={handleIconClick}
size="medium"
/>
</Col>
</Wrapper>
);
};
Expand Down Expand Up @@ -96,10 +122,14 @@ const AssetName = styled("div")(() => ({
flexShrink: 0
}));

const Col = styled("div")<{ width: number }>(({ width }) => ({
const Col = styled("div")<{
width: number;
}>(({ width }) => ({
width: `${width}%`,
flexGrow: 0,
flexShrink: 0
flexShrink: 0,
display: "flex",
alignItems: "center"
}));

function formatBytes(bytes: number): string {
Expand Down
2 changes: 2 additions & 0 deletions web/src/services/i18n/translations/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ Assets selected: ''
Asset selected: ''
Uploaded At: ''
Size: ''
Path: ''
No Asset has been uploaded yet: ''
Asset url copied: ''
Use Name or Email: ''
Find Member: ''
No Member match your search.: ''
Expand Down
2 changes: 2 additions & 0 deletions web/src/services/i18n/translations/ja.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ Assets selected: ''
Asset selected: ''
Uploaded At: ''
Size: ''
Path: 'パス'
No Asset has been uploaded yet: ''
Asset url copied: 'アセットURLをコピーしました'
Use Name or Email: ''
Find Member: ''
No Member match your search.: ''
Expand Down
Loading