UNPKG

@codex-storage/marketplace-ui-components

Version:
31 lines (30 loc) 990 B
import { useState as u } from "react"; const h = 10; function w(o, a = !0) { const [r, s] = u([]), [d, l] = u(""); return { uploadFiles: (e) => { if (l(""), e.length === 0) return; if (!a && r.length) { l( "You already uploaded a file, please delete the current file before uploading a new one." ); return; } o === "single" && e.length > 1 && l( "You tried to upload multiple files but this upload accept only one file, the first file will be used and the rest will be ignored." ); const n = o === "multiple" ? e : [e[0]], i = [], f = Math.min(n.length, h); for (let t = 0; t < f; t++) { const p = Date.now() + "-" + t; i.push({ file: n[t], id: p }); } return s((t) => [...i, ...t]), { error: !1, data: null }; }, deleteFile: (e) => { l(""), s((n) => n.filter((i) => i.id !== e)); }, files: r, warning: d }; } export { w as useUploadStategy }; //# sourceMappingURL=useUploadStrategy.js.map