@muhgholy/next-drive 3.2.0 → 3.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"upload.d.ts","sourceRoot":"","sources":["../../../../src/client/components/drive/upload.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAwC,MAAM,OAAO,CAAC;AA8G7D,eAAO,MAAM,WAAW,GAAI,OAAO,QAAQ,CAAC;IACxC,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,UAAU,CAAC,EAAE,CAAC,IAAI,EAAE,OAAO,KAAK,IAAI,CAAC;IACrC,MAAM,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC,sBAgQD,CAAC"}
1
+ {"version":3,"file":"upload.d.ts","sourceRoot":"","sources":["../../../../src/client/components/drive/upload.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAwC,MAAM,OAAO,CAAC;AA8G7D,eAAO,MAAM,WAAW,GAAI,OAAO,QAAQ,CAAC;IACxC,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,UAAU,CAAC,EAAE,CAAC,IAAI,EAAE,OAAO,KAAK,IAAI,CAAC;IACrC,MAAM,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC,sBAoQD,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"useUpload.d.ts","sourceRoot":"","sources":["../../../src/client/hooks/useUpload.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAYxD,eAAO,MAAM,SAAS,GAAI,aAAa,MAAM,EAAE,iBAAiB,MAAM,GAAG,IAAI,EAAE,kBAAiB,OAAe,EAAE,mBAAmB,CAAC,IAAI,EAAE,GAAG,KAAK,IAAI;;yBAgKrG,IAAI,EAAE,YAAY,MAAM,GAAG,IAAI;uBAuB9D,MAAM;;CA+CxB,CAAC"}
1
+ {"version":3,"file":"useUpload.d.ts","sourceRoot":"","sources":["../../../src/client/hooks/useUpload.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAYxD,eAAO,MAAM,SAAS,GAAI,aAAa,MAAM,EAAE,iBAAiB,MAAM,GAAG,IAAI,EAAE,kBAAiB,OAAe,EAAE,mBAAmB,CAAC,IAAI,EAAE,GAAG,KAAK,IAAI;;yBAiKrG,IAAI,EAAE,YAAY,MAAM,GAAG,IAAI;uBAuB9D,MAAM;;CA+CxB,CAAC"}
@@ -304,8 +304,9 @@ var useUpload = (apiEndpoint, activeAccountId, withCredentials = false, onUpload
304
304
  try {
305
305
  const headers = {};
306
306
  if (activeAccountId) headers["x-drive-account"] = activeAccountId;
307
- addLog(uploadId, "info", `Sending chunk to ${apiEndpoint}?action=upload`);
308
- const response = await fetch(`${apiEndpoint}?action=upload`, {
307
+ const url = `${apiEndpoint.replace(/\/$/, "")}?action=upload`;
308
+ addLog(uploadId, "info", `Sending chunk to ${url}`);
309
+ const response = await fetch(url, {
309
310
  method: "POST",
310
311
  body: formData,
311
312
  headers,
@@ -440,7 +441,7 @@ var useUpload = (apiEndpoint, activeAccountId, withCredentials = false, onUpload
440
441
  }
441
442
  const upload = uploads.find((u) => u.id === id);
442
443
  if (upload?.driveId) {
443
- fetch(`${apiEndpoint}?action=cancel&id=${upload.driveId}`, {
444
+ fetch(`${apiEndpoint.replace(/\/$/, "")}?action=cancel&id=${upload.driveId}`, {
444
445
  method: "POST",
445
446
  credentials: withCredentials ? "include" : "same-origin"
446
447
  }).catch(() => {
@@ -2125,6 +2126,8 @@ var DriveUpload = (props) => {
2125
2126
  const [isDragging, setIsDragging] = useState(false);
2126
2127
  const [showUploadsDialog, setShowUploadsDialog] = useState(false);
2127
2128
  const [logViewerUpload, setLogViewerUpload] = useState(null);
2129
+ const [manuallyOpened, setManuallyOpened] = useState(false);
2130
+ const hasAutoClosedRef = useRef(false);
2128
2131
  const inputRef = useRef(null);
2129
2132
  const { currentFolderId, setItems, apiEndpoint, activeAccountId, withCredentials, fetchItems, isLoading } = useDrive();
2130
2133
  const { uploads, uploadFiles, cancelUpload, cancelAllUploads } = useUpload(apiEndpoint, activeAccountId, withCredentials, (uploadedItem) => {
@@ -2134,17 +2137,18 @@ var DriveUpload = (props) => {
2134
2137
  onComplete?.(uploadedItem);
2135
2138
  });
2136
2139
  React3__default.useEffect(() => {
2137
- if (!showUploadsDialog || uploads.length === 0) return;
2140
+ if (!showUploadsDialog || uploads.length === 0 || manuallyOpened || hasAutoClosedRef.current) return;
2138
2141
  const allFinished = uploads.every(
2139
2142
  (u) => ["complete", "error", "cancelled"].includes(u.status)
2140
2143
  );
2141
2144
  if (allFinished) {
2142
2145
  const timer = setTimeout(() => {
2143
2146
  setShowUploadsDialog(false);
2147
+ hasAutoClosedRef.current = true;
2144
2148
  }, 2e3);
2145
2149
  return () => clearTimeout(timer);
2146
2150
  }
2147
- }, [uploads, showUploadsDialog]);
2151
+ }, [uploads, showUploadsDialog, manuallyOpened]);
2148
2152
  const filterFiles = useCallback((files) => {
2149
2153
  if (!accept) return files;
2150
2154
  return files.filter((file) => matchesMimeFilter(file.type, false, accept));
@@ -2154,6 +2158,7 @@ var DriveUpload = (props) => {
2154
2158
  const filteredFiles = filterFiles(Array.from(files));
2155
2159
  if (filteredFiles.length === 0) return;
2156
2160
  uploadFiles(filteredFiles, currentFolderId);
2161
+ setManuallyOpened(false);
2157
2162
  setShowUploadsDialog(true);
2158
2163
  }, [uploadFiles, currentFolderId, filterFiles]);
2159
2164
  const handleDrag = useCallback((e, dragging) => {
@@ -2300,7 +2305,10 @@ var DriveUpload = (props) => {
2300
2305
  type: "button",
2301
2306
  variant: "outline",
2302
2307
  size: "sm",
2303
- onClick: () => setShowUploadsDialog(true),
2308
+ onClick: () => {
2309
+ setManuallyOpened(true);
2310
+ setShowUploadsDialog(true);
2311
+ },
2304
2312
  children: [
2305
2313
  activeUploads.length > 0 ? /* @__PURE__ */ jsx(Loader2, { className: "!size-4 shrink-0 animate-spin" }) : /* @__PURE__ */ jsx(CheckCircle2, { className: "!size-4 shrink-0" }),
2306
2314
  /* @__PURE__ */ jsx("span", { children: activeUploads.length > 0 ? `(${activeUploads.length})` : "Status" })
@@ -2350,7 +2358,10 @@ var DriveUpload = (props) => {
2350
2358
  ]
2351
2359
  }
2352
2360
  ),
2353
- hasUploadsInProgress && /* @__PURE__ */ jsx("div", { className: "mt-4 text-center", children: /* @__PURE__ */ jsx(Button, { variant: "link", onClick: () => setShowUploadsDialog(true), children: "View Upload Progress" }) }),
2361
+ hasUploadsInProgress && /* @__PURE__ */ jsx("div", { className: "mt-4 text-center", children: /* @__PURE__ */ jsx(Button, { variant: "link", onClick: () => {
2362
+ setManuallyOpened(true);
2363
+ setShowUploadsDialog(true);
2364
+ }, children: "View Upload Progress" }) }),
2354
2365
  renderDialog(),
2355
2366
  logViewerUpload && /* @__PURE__ */ jsx(
2356
2367
  LogViewerDialog,