Skip to content

Papermark is the open-source DocSend alternative and secure data rooms with built-in analytics and custom domains.

feat: update progress bar for file uploads

Marc Seitz1a7ec1d3c46d
diff --git a/components/datarooms/dataroom-document-card.tsx b/components/datarooms/dataroom-document-card.tsx
index ba25f15c..94616a29 100644
--- a/components/datarooms/dataroom-document-card.tsx
+++ b/components/datarooms/dataroom-document-card.tsx
@@ -285,25 +285,27 @@ export default function DataroomDocumentCard({
</div>
</div>
- {(teamInfo?.currentTeam?.id === "cluqtfmcr0001zkza4xcgqatw" ||
- teamInfo?.currentTeam?.id === "clup33by90000oewh4rfvp2eg") &&
+ {
+ // (teamInfo?.currentTeam?.id === "cluqtfmcr0001zkza4xcgqatw" ||
+ // teamInfo?.currentTeam?.id === "clup33by90000oewh4rfvp2eg") &&
["pdf", "docs", "slides", "cad"].includes(
dataroomDocument.document.type,
) &&
- !dataroomDocument.document.versions?.[0]?.hasPages &&
- dataroomDocument.document.versions?.[0]?.id && (
- <FileProcessStatusBar
- documentVersionId={dataroomDocument.document.versions[0].id}
- className="rounded-b-lg border-t border-gray-200 dark:border-gray-700"
- mutateDocument={() => {
- setIsProcessing(false);
- mutate(
- `/api/teams/${teamInfo?.currentTeam?.id}/datarooms/${dataroomId}/documents`,
- );
- }}
- onProcessingChange={(processing) => setIsProcessing(processing)}
- />
- )}
+ !dataroomDocument.document.versions?.[0]?.hasPages &&
+ dataroomDocument.document.versions?.[0]?.id && (
+ <FileProcessStatusBar
+ documentVersionId={dataroomDocument.document.versions[0].id}
+ className="rounded-b-lg border-t border-gray-200 dark:border-gray-700"
+ mutateDocument={() => {
+ setIsProcessing(false);
+ mutate(
+ `/api/teams/${teamInfo?.currentTeam?.id}/datarooms/${dataroomId}/documents`,
+ );
+ }}
+ onProcessingChange={(processing) => setIsProcessing(processing)}
+ />
+ )
+ }
</div>
{addDataRoomOpen ? (
<AddToDataroomModal
diff --git a/components/documents/file-process-status-bar.tsx b/components/documents/file-process-status-bar.tsx
index 8d778142..e5972006 100644
--- a/components/documents/file-process-status-bar.tsx
+++ b/components/documents/file-process-status-bar.tsx
@@ -1,4 +1,4 @@
-import { useEffect } from "react";
+import { useEffect, useState } from "react";
import useSWRImmutable from "swr/immutable";
@@ -7,6 +7,13 @@ import { Progress } from "@/components/ui/progress";
import { cn, fetcher } from "@/lib/utils";
import { useDocumentProgressStatus } from "@/lib/utils/use-progress-status";
+const QUEUED_MESSAGES = [
+ "Converting document...",
+ "Optimizing for viewing...",
+ "Preparing preview...",
+ "Almost ready...",
+];
+
export default function FileProcessStatusBar({
documentVersionId,
className,
@@ -18,6 +25,7 @@ export default function FileProcessStatusBar({
mutateDocument: () => void;
onProcessingChange?: (processing: boolean) => void;
}) {
+ const [messageIndex, setMessageIndex] = useState(0);
const { data } = useSWRImmutable<{ publicAccessToken: string }>(
`/api/progress-token?documentVersionId=${documentVersionId}`,
fetcher,
@@ -36,11 +44,29 @@ export default function FileProcessStatusBar({
}
}, [progressStatus.state, onProcessingChange]);
- if (progressStatus.state === "QUEUED") {
+ // Cycle through messages when queued or executing
+ useEffect(() => {
+ let interval: NodeJS.Timeout;
+
+ if (progressStatus.state === "QUEUED") {
+ interval = setInterval(() => {
+ setMessageIndex((current) => (current + 1) % QUEUED_MESSAGES.length);
+ }, 5000); // Change message every 5 seconds
+ }
+
+ return () => {
+ if (interval) clearInterval(interval);
+ };
+ }, [progressStatus.state]);
+
+ console.log("status", progressStatus);
+ console.log("error", progressError);
+
+ if (progressStatus.state === "QUEUED" && !progressError) {
return (
<Progress
value={0}
- text="Processing document..."
+ text={QUEUED_MESSAGES[messageIndex]}
className={cn(
"w-full rounded-none text-[8px] font-semibold",
className,
@@ -77,6 +103,7 @@ export default function FileProcessStatusBar({
return null;
}
+ // For EXECUTING state
return (
<Progress
value={progressStatus.progress || 0}
diff --git a/components/links/links-table.tsx b/components/links/links-table.tsx
index 5e6f40ed..13db069d 100644
--- a/components/links/links-table.tsx
+++ b/components/links/links-table.tsx
@@ -321,23 +321,27 @@ export default function LinksTable({
{/* Progress bar */}
{primaryVersion &&
!primaryVersion.hasPages &&
- primaryVersion.type === "pdf" && (
- <>
- {teamInfo?.currentTeam?.id !==
- "cluqtfmcr0001zkza4xcgqatw" ? (
- <ProcessStatusBar
- documentVersionId={primaryVersion.id}
- className="absolute bottom-0 left-0 right-0 top-0 z-20 flex h-full items-center gap-x-8"
- />
- ) : (
- <FileProcessStatusBar
- documentVersionId={primaryVersion.id}
- className="absolute bottom-0 left-0 right-0 top-0 z-20 flex h-full items-center gap-x-8"
- // @ts-ignore: mutateDocument is not present on datarooms but on document pages
- mutateDocument={mutateDocument}
- />
- )}
- </>
+ ["pdf", "slides", "docs", "cad"].includes(
+ primaryVersion.type!,
+ ) && (
+ // <>
+ // {teamInfo?.currentTeam?.id !==
+ // "cluqtfmcr0001zkza4xcgqatw" &&
+ // teamInfo?.currentTeam?.id !==
+ // "clup33by90000oewh4rfvp2eg" ? (
+ // <ProcessStatusBar
+ // documentVersionId={primaryVersion.id}
+ // className="absolute bottom-0 left-0 right-0 top-0 z-20 flex h-full items-center gap-x-8"
+ // />
+ // ) : (
+ <FileProcessStatusBar
+ documentVersionId={primaryVersion.id}
+ className="absolute bottom-0 left-0 right-0 top-0 z-20 flex h-full items-center gap-x-8"
+ // @ts-ignore: mutateDocument is not present on datarooms but on document pages
+ mutateDocument={mutateDocument}
+ />
+ // )}
+ // </>
)}
<div className="flex w-full whitespace-nowrap text-sm group-hover/cell:opacity-0">
diff --git a/lib/trigger/pdf-to-image.ts b/lib/trigger/pdf-to-image.ts
index d18da226..5019d3bd 100644
--- a/lib/trigger/pdf-to-image.ts
+++ b/lib/trigger/pdf-to-image.ts
@@ -201,7 +201,7 @@ export const convertPdfToImage = task({
logger.info("Streaming PDF to temporary file");
await pipeline(response.body, createWriteStream(pdfPath));
- updateStatus({ progress: 20, text: "Converting document..." });
+ updateStatus({ progress: 10, text: "Converting document..." });
// Get total pages and first page dimensions
const getDimensions = execSync(
diff --git a/lib/utils/use-progress-status.ts b/lib/utils/use-progress-status.ts
index 89675b85..859f6000 100644
--- a/lib/utils/use-progress-status.ts
+++ b/lib/utils/use-progress-status.ts
@@ -23,23 +23,59 @@ export function useDocumentProgressStatus(
},
);
- const run = runs[0];
+ // Find the most recent active run (QUEUED or EXECUTING)
+ const activeRun = runs.find((run) =>
+ ["QUEUED", "EXECUTING"].includes(run.status),
+ );
+
const status: IDocumentProgressStatus = {
- state: run?.status ?? "QUEUED",
+ state: "QUEUED",
progress: 0,
text: "Initializing...",
};
- // Parse metadata if available
- if (run?.metadata) {
- const { progress, text } = parseStatus(run.metadata);
- status.progress = progress;
- status.text = text;
+ // If we have no runs at all
+ if (runs.length === 0) {
+ return { status, error, run: undefined };
+ }
+
+ // If we found an active run, use its status
+ if (activeRun) {
+ status.state = activeRun.status;
+ if (activeRun.metadata) {
+ const { progress, text } = parseStatus(activeRun.metadata);
+ status.progress = progress;
+ status.text = text;
+ }
+ return { status, error, run: activeRun };
+ }
+
+ // Check if any run has failed
+ const failedRun = runs.find((run) =>
+ ["FAILED", "CRASHED", "CANCELED", "SYSTEM_FAILURE"].includes(run.status),
+ );
+
+ if (failedRun) {
+ status.state = failedRun.status;
+ if (failedRun.metadata) {
+ const { progress, text } = parseStatus(failedRun.metadata);
+ status.progress = progress;
+ status.text = text;
+ }
+ return { status, error, run: failedRun };
+ }
+
+ // If all runs are completed
+ const allCompleted = runs.every((run) => run.status === "COMPLETED");
+ if (allCompleted) {
+ status.state = "COMPLETED";
+ status.progress = 100;
+ status.text = "Processing complete";
}
return {
status,
error,
- run,
+ run: runs[0], // Return most recent run
};
}