Customize the upload success message and remove to copy feature on upload
This commit is contained in:
parent
0c2faf02be
commit
2312007a4c
|
@ -1,12 +1,12 @@
|
||||||
{
|
{
|
||||||
"name": "@codex-storage/marketplace-ui-components",
|
"name": "@codex-storage/marketplace-ui-components",
|
||||||
"version": "0.0.12",
|
"version": "0.0.14",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "@codex-storage/marketplace-ui-components",
|
"name": "@codex-storage/marketplace-ui-components",
|
||||||
"version": "0.0.12",
|
"version": "0.0.14",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"lucide-react": "^0.441.0"
|
"lucide-react": "^0.441.0"
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/codex-storage/codex-marketplace-ui-components"
|
"url": "https://github.com/codex-storage/codex-marketplace-ui-components"
|
||||||
},
|
},
|
||||||
"version": "0.0.13",
|
"version": "0.0.14",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"prepack": "npm run build",
|
"prepack": "npm run build",
|
||||||
|
|
|
@ -79,6 +79,12 @@ type Props = {
|
||||||
* --codex-color-warning
|
* --codex-color-warning
|
||||||
*/
|
*/
|
||||||
style?: CustomStyleCSS;
|
style?: CustomStyleCSS;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Success message displayed when a file is updated.
|
||||||
|
* Default: File uploaded successfully.
|
||||||
|
*/
|
||||||
|
successMessage?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
export function Upload({
|
export function Upload({
|
||||||
|
@ -91,6 +97,7 @@ export function Upload({
|
||||||
onDeleteItem,
|
onDeleteItem,
|
||||||
onSuccess,
|
onSuccess,
|
||||||
codexData,
|
codexData,
|
||||||
|
successMessage = "File uploaded successfully",
|
||||||
// useWorker = !!window.Worker,
|
// useWorker = !!window.Worker,
|
||||||
}: Props) {
|
}: Props) {
|
||||||
const { deleteFile, files, uploadFiles, warning } = useUploadStategy(
|
const { deleteFile, files, uploadFiles, warning } = useUploadStategy(
|
||||||
|
@ -174,6 +181,7 @@ export function Upload({
|
||||||
id={id}
|
id={id}
|
||||||
onSuccess={onSuccess}
|
onSuccess={onSuccess}
|
||||||
codexData={codexData}
|
codexData={codexData}
|
||||||
|
successMessage={successMessage}
|
||||||
// useWorker={useWorker}
|
// useWorker={useWorker}
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
|
|
|
@ -1,14 +1,6 @@
|
||||||
import {
|
import { useRef, useReducer, Reducer, useEffect, useCallback } from "react";
|
||||||
useRef,
|
|
||||||
useState,
|
|
||||||
useReducer,
|
|
||||||
Reducer,
|
|
||||||
useEffect,
|
|
||||||
useCallback,
|
|
||||||
} from "react";
|
|
||||||
import { attributes } from "../utils/attributes";
|
import { attributes } from "../utils/attributes";
|
||||||
import { PrettyBytes } from "../utils/bytes";
|
import { PrettyBytes } from "../utils/bytes";
|
||||||
import { Toast } from "../Toast/Toast";
|
|
||||||
import { UploadStatus } from "./types";
|
import { UploadStatus } from "./types";
|
||||||
import { CircleCheck, TriangleAlert, CircleX, CircleStop } from "lucide-react";
|
import { CircleCheck, TriangleAlert, CircleX, CircleStop } from "lucide-react";
|
||||||
import { Spinner } from "../Spinner/Spinner";
|
import { Spinner } from "../Spinner/Spinner";
|
||||||
|
@ -23,6 +15,7 @@ type UploadFileProps = {
|
||||||
id: string;
|
id: string;
|
||||||
onSuccess: ((cid: string, file: File) => void) | undefined;
|
onSuccess: ((cid: string, file: File) => void) | undefined;
|
||||||
codexData: CodexData;
|
codexData: CodexData;
|
||||||
|
successMessage: string;
|
||||||
// useWorker: boolean;
|
// useWorker: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -128,11 +121,11 @@ export function UploadFile({
|
||||||
id,
|
id,
|
||||||
onSuccess,
|
onSuccess,
|
||||||
codexData,
|
codexData,
|
||||||
|
successMessage,
|
||||||
// useWorker,
|
// useWorker,
|
||||||
}: UploadFileProps) {
|
}: UploadFileProps) {
|
||||||
const abort = useRef<(() => void) | null>(null);
|
const abort = useRef<(() => void) | null>(null);
|
||||||
// const worker = useRef<Worker | null>(null);
|
// const worker = useRef<Worker | null>(null);
|
||||||
const [toast, setToast] = useState({ time: 0, message: "" });
|
|
||||||
const [state, dispatch] = useReducer<Reducer<State, Action>>(reducer, {
|
const [state, dispatch] = useReducer<Reducer<State, Action>>(reducer, {
|
||||||
progress: { loaded: 0, total: 0 },
|
progress: { loaded: 0, total: 0 },
|
||||||
cid: "",
|
cid: "",
|
||||||
|
@ -250,16 +243,6 @@ export function UploadFile({
|
||||||
onClose(id);
|
onClose(id);
|
||||||
};
|
};
|
||||||
|
|
||||||
const onCopy = () => {
|
|
||||||
if (cid) {
|
|
||||||
navigator.clipboard.writeText(cid);
|
|
||||||
setToast({
|
|
||||||
time: Date.now(),
|
|
||||||
message: "The CID has been copied to your clipboard.",
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const parts = file.name.split(".");
|
const parts = file.name.split(".");
|
||||||
const extension = parts.pop();
|
const extension = parts.pop();
|
||||||
const filename = parts.join(".");
|
const filename = parts.join(".");
|
||||||
|
@ -271,78 +254,72 @@ export function UploadFile({
|
||||||
const ActionIcon = () => <UploadActionIcon status={status} />;
|
const ActionIcon = () => <UploadActionIcon status={status} />;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={"uploadFile"}>
|
<>
|
||||||
<div className="uploadFile-info">
|
<div className={"uploadFile"}>
|
||||||
<div className="uploadFile-infoLeft">
|
<div className="uploadFile-info">
|
||||||
{preview ? (
|
<div className="uploadFile-infoLeft">
|
||||||
<img
|
{preview ? (
|
||||||
src={preview}
|
<img
|
||||||
width="24"
|
src={preview}
|
||||||
alt="Preview"
|
width="24"
|
||||||
className="uploadFile-preview"
|
alt="Preview"
|
||||||
/>
|
className="uploadFile-preview"
|
||||||
) : (
|
/>
|
||||||
<WebFileIcon type={file.type} />
|
) : (
|
||||||
)}
|
<WebFileIcon type={file.type} />
|
||||||
<div className="uploadFile-infoText">
|
)}
|
||||||
<b
|
<div className="uploadFile-infoText">
|
||||||
className="uploadFile-name"
|
<b
|
||||||
{...attributes({
|
className="uploadFile-name"
|
||||||
"aria-invalid": status === "error",
|
{...attributes({
|
||||||
"data-done": status === "done",
|
"aria-invalid": status === "error",
|
||||||
})}
|
"data-done": status === "done",
|
||||||
>
|
})}
|
||||||
<span className="uploadFile-filename">{filename}</span>
|
>
|
||||||
<span>.{extension}</span>
|
<span className="uploadFile-filename">{filename}</span>
|
||||||
</b>
|
<span>.{extension}</span>
|
||||||
<div>
|
</b>
|
||||||
<small>{PrettyBytes(file.size)}</small>
|
<div>
|
||||||
|
<small>{PrettyBytes(file.size)}</small>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
<div className="uploadFile-infoRight">
|
||||||
<div className="uploadFile-infoRight">
|
<UploadStatusIcon status={status} />
|
||||||
<UploadStatusIcon status={status} />
|
|
||||||
|
|
||||||
<ButtonIcon
|
<ButtonIcon
|
||||||
variant="small"
|
variant="small"
|
||||||
onClick={onAction}
|
onClick={onAction}
|
||||||
Icon={ActionIcon}
|
Icon={ActionIcon}
|
||||||
></ButtonIcon>
|
></ButtonIcon>
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="uploadFile-progress">
|
|
||||||
<progress
|
|
||||||
className="uploadFile-progressBar"
|
|
||||||
{...attributes({
|
|
||||||
max: file ? progress.total.toString() : false,
|
|
||||||
value: file ? progress.loaded.toString() : false,
|
|
||||||
"aria-invalid": status === "error",
|
|
||||||
})}
|
|
||||||
/>
|
|
||||||
<span className="uploadFile-progressBarPercent">
|
|
||||||
{percent.toFixed(2)} %
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{!!cid && (
|
|
||||||
<>
|
|
||||||
<div className="text--primary">
|
|
||||||
<span>Success !</span> Click on the CID to copy it to your
|
|
||||||
clipboard.
|
|
||||||
</div>
|
</div>
|
||||||
<a>
|
</div>
|
||||||
<small className="uploadFile-cid" onClick={onCopy}>
|
|
||||||
{cid}
|
|
||||||
</small>
|
|
||||||
</a>
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
|
|
||||||
<SimpleText variant="error">{error ? error : <> </>}</SimpleText>
|
<div className="uploadFile-progress">
|
||||||
|
<progress
|
||||||
|
className="uploadFile-progressBar"
|
||||||
|
{...attributes({
|
||||||
|
max: file ? progress.total.toString() : false,
|
||||||
|
value: file ? progress.loaded.toString() : false,
|
||||||
|
"aria-invalid": status === "error",
|
||||||
|
})}
|
||||||
|
/>
|
||||||
|
<span className="uploadFile-progressBarPercent">
|
||||||
|
{percent.toFixed(2)} %
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
<Toast message={toast.message} time={toast.time} variant="success" />
|
<div className="uploadFile-message">
|
||||||
</div>
|
{cid ? (
|
||||||
|
<div className="text--primary">{successMessage}</div>
|
||||||
|
) : (
|
||||||
|
<SimpleText variant="error">
|
||||||
|
{error ? error : <> </>}
|
||||||
|
</SimpleText>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -106,6 +106,10 @@
|
||||||
text-align: right;
|
text-align: right;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.uploadFile-message {
|
||||||
|
font-size: 0.85rem;
|
||||||
|
}
|
||||||
|
|
||||||
.upload-progress-check {
|
.upload-progress-check {
|
||||||
color: var(--codex-color-primary);
|
color: var(--codex-color-primary);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue