Skip to content

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

feat: add upload notification drawer

Marc Seitz3af41c1dc4ab
diff --git a/components/ui/drawer.tsx b/components/ui/drawer.tsx
new file mode 100644
index 00000000..7e02ac2a
--- /dev/null
+++ b/components/ui/drawer.tsx
@@ -0,0 +1,119 @@
+import * as React from "react";
+
+import { Drawer as DrawerPrimitive } from "vaul";
+
+import { cn } from "@/lib/utils";
+
+const Drawer = ({
+ shouldScaleBackground = false,
+ ...props
+}: React.ComponentProps<typeof DrawerPrimitive.Root>) => (
+ <DrawerPrimitive.Root
+ shouldScaleBackground={shouldScaleBackground}
+ {...props}
+ />
+);
+Drawer.displayName = "Drawer";
+
+const DrawerTrigger = DrawerPrimitive.Trigger;
+
+const DrawerPortal = DrawerPrimitive.Portal;
+
+const DrawerClose = DrawerPrimitive.Close;
+
+const DrawerOverlay = React.forwardRef<
+ React.ElementRef<typeof DrawerPrimitive.Overlay>,
+ React.ComponentPropsWithoutRef<typeof DrawerPrimitive.Overlay>
+>(({ className, ...props }, ref) => (
+ <DrawerPrimitive.Overlay
+ ref={ref}
+ className={cn("fixed inset-0 z-50 bg-black/80", className)}
+ {...props}
+ />
+));
+DrawerOverlay.displayName = DrawerPrimitive.Overlay.displayName;
+
+const DrawerContent = React.forwardRef<
+ React.ElementRef<typeof DrawerPrimitive.Content>,
+ React.ComponentPropsWithoutRef<typeof DrawerPrimitive.Content>
+>(({ className, children, ...props }, ref) => (
+ <DrawerPortal>
+ {/* <DrawerOverlay /> */}
+ <DrawerPrimitive.Content
+ ref={ref}
+ className={cn(
+ "fixed inset-x-0 bottom-0 z-50 mt-24 flex h-auto flex-col rounded-t-[10px] border bg-background",
+ className,
+ )}
+ onEscapeKeyDown={(e) => e.preventDefault()}
+ onPointerDownOutside={(e) => e.preventDefault()}
+ {...props}
+ >
+ {/* <div className="mx-auto mt-4 h-2 w-[100px] rounded-full bg-muted" /> */}
+ {children}
+ </DrawerPrimitive.Content>
+ </DrawerPortal>
+));
+DrawerContent.displayName = "DrawerContent";
+
+const DrawerHeader = ({
+ className,
+ ...props
+}: React.HTMLAttributes<HTMLDivElement>) => (
+ <div
+ className={cn("grid gap-1.5 p-4 text-center sm:text-left", className)}
+ {...props}
+ />
+);
+DrawerHeader.displayName = "DrawerHeader";
+
+const DrawerFooter = ({
+ className,
+ ...props
+}: React.HTMLAttributes<HTMLDivElement>) => (
+ <div
+ className={cn("mt-auto flex flex-col gap-2 p-4", className)}
+ {...props}
+ />
+);
+DrawerFooter.displayName = "DrawerFooter";
+
+const DrawerTitle = React.forwardRef<
+ React.ElementRef<typeof DrawerPrimitive.Title>,
+ React.ComponentPropsWithoutRef<typeof DrawerPrimitive.Title>
+>(({ className, ...props }, ref) => (
+ <DrawerPrimitive.Title
+ ref={ref}
+ className={cn(
+ "text-lg font-semibold leading-none tracking-tight",
+ className,
+ )}
+ {...props}
+ />
+));
+DrawerTitle.displayName = DrawerPrimitive.Title.displayName;
+
+const DrawerDescription = React.forwardRef<
+ React.ElementRef<typeof DrawerPrimitive.Description>,
+ React.ComponentPropsWithoutRef<typeof DrawerPrimitive.Description>
+>(({ className, ...props }, ref) => (
+ <DrawerPrimitive.Description
+ ref={ref}
+ className={cn("text-sm text-muted-foreground", className)}
+ {...props}
+ />
+));
+DrawerDescription.displayName = DrawerPrimitive.Description.displayName;
+
+export {
+ Drawer,
+ DrawerPortal,
+ DrawerOverlay,
+ DrawerTrigger,
+ DrawerClose,
+ DrawerContent,
+ DrawerHeader,
+ DrawerFooter,
+ DrawerTitle,
+ DrawerDescription,
+};
diff --git a/components/upload-notification.tsx b/components/upload-notification.tsx
new file mode 100644
index 00000000..2355bdf7
--- /dev/null
+++ b/components/upload-notification.tsx
@@ -0,0 +1,100 @@
+import { useState } from "react";
+
+import { XIcon } from "lucide-react";
+
+import {
+ Drawer,
+ DrawerClose,
+ DrawerContent,
+ DrawerHeader,
+ DrawerTitle,
+} from "@/components/ui/drawer";
+
+import { cn } from "@/lib/utils";
+
+export function UploadNotificationDrawer({
+ open,
+ onOpenChange,
+ uploads,
+ setUploads,
+ rejectedFiles,
+ setRejectedFiles,
+}: {
+ open: boolean;
+ onOpenChange: (open: boolean) => void;
+ uploads: { fileName: string; progress: number }[];
+ setUploads: (uploads: { fileName: string; progress: number }[]) => void;
+ rejectedFiles: { fileName: string; message: string }[];
+ setRejectedFiles: (rejected: { fileName: string; message: string }[]) => void;
+}) {
+ const uploadCount = uploads.length;
+ const failedCount = rejectedFiles.length;
+ const [activeSnap, setActiveSnap] = useState<number | string | null>("250px");
+
+ const onOpenChangeHandler = (open: boolean) => {
+ onOpenChange(open);
+ if (!open) {
+ setUploads([]);
+ setRejectedFiles([]);
+ } else {
+ setActiveSnap("250px");
+ }
+ };
+
+ return (
+ <div className="h-50 fixed bottom-0 right-20">
+ <Drawer
+ modal={false}
+ open={open}
+ onOpenChange={onOpenChangeHandler}
+ snapPoints={["40px", "250px"]}
+ 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">
+ <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>)
+ </p>
+ ) : null}
+ </div>
+ <DrawerClose className="rounded-full p-1 hover:bg-gray-200">
+ <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",
+ {
+ "mb-[742px] overflow-y-auto": activeSnap === "250px",
+ "overflow-hidden": activeSnap !== "250px",
+ },
+ )}
+ >
+ {uploads.map((upload, index) => (
+ <div
+ key={index}
+ className="flex items-center justify-between p-2"
+ >
+ <span>{upload.fileName}</span>
+ <span>{upload.progress}%</span>
+ </div>
+ ))}
+ {rejectedFiles.map((rejected, index) => (
+ <div
+ key={index}
+ className="flex items-center justify-between p-2 text-red-600"
+ >
+ <span>{rejected.fileName}</span>
+ <span>{rejected.message}</span>
+ </div>
+ ))}
+ </div>
+ </DrawerContent>
+ </Drawer>
+ </div>
+ );
+}