Add toast on copy

This commit is contained in:
Arnaud 2024-10-21 16:28:16 +02:00
parent 14da122bea
commit 6729e64be7
No known key found for this signature in database
GPG Key ID: 69D6CE281FCAE663

View File

@ -1,35 +1,48 @@
import { import {
ButtonIcon, ButtonIcon,
Cell, Cell,
Toast,
WebFileIcon, WebFileIcon,
} from "@codex-storage/marketplace-ui-components"; } from "@codex-storage/marketplace-ui-components";
import { CodexDataContent } from "@codex-storage/sdk-js"; import { CodexDataContent } from "@codex-storage/sdk-js";
import { Copy } from "lucide-react"; import { Copy } from "lucide-react";
import { useState } from "react";
type Props = { type Props = {
content: CodexDataContent; content: CodexDataContent;
}; };
export function FileCell({ content }: Props) { export function FileCell({ content }: Props) {
const onCopy = (cid: string) => navigator.clipboard.writeText(cid); const [toast, setToast] = useState({ time: 0, message: "" });
const onCopy = (cid: string) => {
navigator.clipboard.writeText(cid);
setToast({ message: "CID copied to the clipboard.", time: Date.now() });
};
return ( return (
<Cell> <>
<div className="files-cell-file"> <Cell>
<WebFileIcon type={content.manifest.mimetype} /> <div className="files-cell-file">
<WebFileIcon type={content.manifest.mimetype} />
<div>
<b>{content.manifest.filename}</b>
<div> <div>
<small className="files-fileMeta">{content.cid}</small> <b>{content.manifest.filename}</b>
<ButtonIcon <div className="files-fileMeta">
variant="small" <small className="files-fileMeta-cid">{content.cid}</small>
onClick={() => onCopy(content.cid)} <ButtonIcon
animation="buzz" variant="small"
Icon={(props) => <Copy size={"1rem"} {...props} />}></ButtonIcon> onClick={() => onCopy(content.cid)}
animation="buzz"
Icon={(props) => (
<Copy size={"1rem"} {...props} />
)}></ButtonIcon>
</div>
</div> </div>
</div> </div>
</div>
</Cell> <Toast message={toast.message} time={toast.time} variant={"success"} />
</Cell>
</>
); );
} }