Skip to content

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

feat: improve notification for multiple uploads

Marc Seitz16046243828a
diff --git a/components/documents/documents-list.tsx b/components/documents/documents-list.tsx
index 0998558b..9da1e3a8 100644
--- a/components/documents/documents-list.tsx
+++ b/components/documents/documents-list.tsx
@@ -26,7 +26,7 @@ export function DocumentsList({
folderPathName?: string[];
}) {
const [uploads, setUploads] = useState<
- { fileName: string; progress: number }[]
+ { fileName: string; progress: number; documentId?: string }[]
>([]);
const [rejectedFiles, setRejectedFiles] = useState<
{ fileName: string; message: string }[]
@@ -42,10 +42,10 @@ export function DocumentsList({
setUploads(newUploads);
setShowDrawer(true);
}}
- onUploadProgress={(index, progress) => {
+ onUploadProgress={(index, progress, documentId) => {
setUploads((prevUploads) =>
prevUploads.map((upload, i) =>
- i === index ? { ...upload, progress } : upload,
+ i === index ? { ...upload, progress, documentId } : upload,
),
);
}}
diff --git a/components/upload-notification.tsx b/components/upload-notification.tsx
index 2355bdf7..3b73fef3 100644
--- a/components/upload-notification.tsx
+++ b/components/upload-notification.tsx
@@ -1,6 +1,6 @@
import { useState } from "react";
-import { XIcon } from "lucide-react";
+import { CheckIcon, XIcon } from "lucide-react";
import {
Drawer,
@@ -12,6 +12,8 @@ import {
import { cn } from "@/lib/utils";
+import { Gauge } from "./ui/gauge";
+
export function UploadNotificationDrawer({
open,
onOpenChange,
@@ -22,8 +24,10 @@ export function UploadNotificationDrawer({
}: {
open: boolean;
onOpenChange: (open: boolean) => void;
- uploads: { fileName: string; progress: number }[];
- setUploads: (uploads: { fileName: string; progress: number }[]) => void;
+ uploads: { fileName: string; progress: number; documentId?: string }[];
+ setUploads: (
+ uploads: { fileName: string; progress: number; documentId?: string }[],
+ ) => void;
rejectedFiles: { fileName: string; message: string }[];
setRejectedFiles: (rejected: { fileName: string; message: string }[]) => void;
}) {
@@ -51,23 +55,26 @@ export function UploadNotificationDrawer({
activeSnapPoint={activeSnap}
setActiveSnapPoint={setActiveSnap}
>
- <DrawerContent className="inset-x-auto right-6 h-full w-1/5 min-w-[350px] shadow-md">
- <DrawerHeader className="flex h-10 items-center justify-between rounded-t-lg border-b border-transparent bg-gray-100">
+ <DrawerContent className="inset-x-auto right-6 h-full w-1/5 min-w-[350px] shadow-md focus-visible:outline-none">
+ <DrawerHeader className="flex h-10 items-center justify-between rounded-t-lg border-b border-transparent bg-gray-100 dark:bg-gray-900">
<div className="flex items-center space-x-1">
<DrawerTitle>{uploadCount} uploads</DrawerTitle>
{failedCount > 0 ? (
<p className="text-sm">
- (<span className="text-red-600">{failedCount} failed</span>)
+ (
+ <span className="text-destructive">{failedCount} failed</span>
+ )
</p>
) : null}
</div>
- <DrawerClose className="rounded-full p-1 hover:bg-gray-200">
+ <DrawerClose className="rounded-full p-1 hover:bg-gray-200 hover:dark:bg-gray-800">
<XIcon className="h-6 w-6" />
</DrawerClose>
</DrawerHeader>
<div
className={cn(
- "mx-auto flex w-full max-w-md grow flex-col divide-y *:px-4 *:py-3",
+ "mx-auto flex w-full max-w-md grow flex-col *:px-4 *:py-3",
+
{
"mb-[742px] overflow-y-auto": activeSnap === "250px",
"overflow-hidden": activeSnap !== "250px",
@@ -77,16 +84,32 @@ export function UploadNotificationDrawer({
{uploads.map((upload, index) => (
<div
key={index}
- className="flex items-center justify-between p-2"
+ className="p-2 hover:bg-gray-100 hover:dark:bg-gray-900"
>
- <span>{upload.fileName}</span>
- <span>{upload.progress}%</span>
+ <a
+ href={`/documents/${upload.documentId}`}
+ className="flex items-center justify-between"
+ >
+ <span>{upload.fileName}</span>
+ {upload.progress === 100 ? (
+ <CheckIcon
+ className="h-6 w-6 rounded-full bg-emerald-500 p-1 text-background"
+ strokeWidth={3}
+ />
+ ) : (
+ <Gauge
+ value={upload.progress}
+ size={"xs"}
+ showValue={true}
+ />
+ )}
+ </a>
</div>
))}
{rejectedFiles.map((rejected, index) => (
<div
key={index}
- className="flex items-center justify-between p-2 text-red-600"
+ className="flex items-center justify-between p-2 text-destructive hover:bg-gray-100 hover:dark:bg-gray-900"
>
<span>{rejected.fileName}</span>
<span>{rejected.message}</span>
diff --git a/components/upload-zone.tsx b/components/upload-zone.tsx
index ff40b482..8adb03bb 100644
--- a/components/upload-zone.tsx
+++ b/components/upload-zone.tsx
@@ -67,11 +67,19 @@ export default function UploadZone({
setRejectedFiles,
}: {
children: React.ReactNode;
- onUploadStart: (uploads: { fileName: string; progress: number }[]) => void;
- onUploadProgress: (index: number, progress: number) => void;
+ onUploadStart: (
+ uploads: { fileName: string; progress: number; documentId?: string }[],
+ ) => void;
+ onUploadProgress: (
+ index: number,
+ progress: number,
+ documentId?: string,
+ ) => void;
onUploadRejected: (rejected: { fileName: string; message: string }[]) => void;
setUploads: React.Dispatch<
- React.SetStateAction<{ fileName: string; progress: number }[]>
+ React.SetStateAction<
+ { fileName: string; progress: number; documentId?: string }[]
+ >
>;
setRejectedFiles: React.Dispatch<
React.SetStateAction<{ fileName: string; message: string }[]>
@@ -121,7 +129,10 @@ export default function UploadZone({
file, // File
onProgress: (bytesUploaded, bytesTotal) => {
uploadProgress.current[index] = (bytesUploaded / bytesTotal) * 100;
- onUploadProgress(index, Math.round(uploadProgress.current[index]));
+ onUploadProgress(
+ index,
+ Math.min(Math.round(uploadProgress.current[index]), 99),
+ );
const _progress = uploadProgress.current.reduce(
(acc, progress) => acc + progress,
@@ -159,7 +170,11 @@ export default function UploadZone({
`/api/teams/${teamInfo?.currentTeam?.id}/folders/documents/${folderPathName}`,
);
- return await response.json();
+ const document = await response.json();
+ // update progress to 100%
+ onUploadProgress(index, 100, document.id);
+
+ return document;
});
const documents = Promise.all(uploadPromises);