This repository has been archived by the owner on Sep 9, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #127 from OcularEngineering/files-page
Files Dialog
- Loading branch information
Showing
9 changed files
with
231 additions
and
152 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
"use client"; | ||
|
||
import { useRouter } from 'next/router'; | ||
import { buttonVariants, Button } from "@/components/ui/button"; | ||
import { | ||
Dialog, | ||
DialogClose, | ||
DialogContent, | ||
DialogDescription, | ||
DialogFooter, | ||
DialogHeader, | ||
DialogTitle, | ||
DialogTrigger, | ||
} from "@/components/ui/dialog"; | ||
import { | ||
Tooltip, | ||
TooltipContent, | ||
TooltipTrigger, | ||
TooltipProvider | ||
} from "@/components/ui/tooltip"; | ||
import { | ||
File | ||
} from "lucide-react" | ||
|
||
|
||
import SectionContainer from "@/components/section-container" | ||
import { UploadedFilesCard } from "@/components/files/uploaded-files-card" | ||
import { useUploadFile } from "@/lib/hooks/files/use-upload-file" | ||
import { FileUploader } from "@/components/files/file-uploader" | ||
|
||
export default function FilesDialog({ link }) { | ||
const router = useRouter(); | ||
const isActive = (href) => router.pathname === href; | ||
|
||
const { uploadFiles, progresses, uploadedFiles, isUploading } = useUploadFile( | ||
"fileUploader", | ||
{ defaultUploadedFiles: [] } | ||
) | ||
|
||
return ( | ||
<Dialog> | ||
<Tooltip> | ||
<div className="flex items-center space-x-3"> | ||
<TooltipTrigger asChild> | ||
<DialogTrigger asChild> | ||
<div className="flex items-center space-x-3 cursor-pointer"> | ||
<div | ||
className={`${ | ||
buttonVariants({ variant: link.variant, size: "icon" }) | ||
} h-9 w-9 ${ | ||
isActive(link.link) ? 'bg-accent rounded-md' : 'bg-transparent' | ||
} ${ | ||
link.variant === "default" && "dark:bg-muted dark:text-muted-foreground dark:hover:bg-muted dark:hover:text-white" | ||
}`} | ||
> | ||
<File style={{ height: '19px', width: '19px' }} /> | ||
<span className="sr-only">{link.title}</span> | ||
</div> | ||
</div> | ||
</DialogTrigger> | ||
</TooltipTrigger> | ||
<TooltipContent side="right" className="flex items-center gap-4"> | ||
{link.title} | ||
{link.label && ( | ||
<span className="text-muted-foreground ml-auto"> | ||
{link.label} | ||
</span> | ||
)} | ||
</TooltipContent> | ||
</div> | ||
</Tooltip> | ||
|
||
<DialogContent className="flex flex-col w-[60vw] h-[90vh] max-h-[90vh] justify-between overflow-auto"> | ||
|
||
<UploadedFilesCard uploadedFiles={uploadedFiles} /> | ||
|
||
<DialogFooter className="justify-end sticky bottom-0"> | ||
<FileUploader | ||
maxFiles={Infinity} | ||
maxSize={Infinity} | ||
progresses={progresses} | ||
onUpload={uploadFiles} | ||
disabled={isUploading} | ||
/> | ||
</DialogFooter> | ||
</DialogContent> | ||
</Dialog> | ||
); | ||
} |
77 changes: 39 additions & 38 deletions
77
packages/ocular-ui/components/files/uploaded-files-card.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,55 @@ | ||
import Image from "next/image" | ||
import type { UploadedFile } from "@/types/types" | ||
|
||
import { | ||
Card, | ||
CardContent, | ||
CardDescription, | ||
CardHeader, | ||
CardTitle, | ||
} from "@/components/ui/card" | ||
import type { Files } from "@/types/types" | ||
import { ScrollArea, ScrollBar } from "@/components/ui/scroll-area" | ||
import { EmptyCard } from "@/components/files/empty-card" | ||
|
||
interface UploadedFilesCardProps { | ||
uploadedFiles: UploadedFile[] | ||
uploadedFiles: Files[] | ||
} | ||
|
||
export function UploadedFilesCard({ uploadedFiles }: UploadedFilesCardProps) { | ||
|
||
console.log("File Object: ", uploadedFiles) | ||
return ( | ||
<Card> | ||
<CardHeader> | ||
<CardTitle>Uploaded files</CardTitle> | ||
<CardDescription>View the uploaded files here</CardDescription> | ||
</CardHeader> | ||
<CardContent> | ||
{uploadedFiles.length > 0 ? ( | ||
<ScrollArea className="pb-4"> | ||
<div className="flex w-max space-x-2.5"> | ||
{uploadedFiles.map((file) => ( | ||
<div key={file.key} className="relative aspect-video w-64"> | ||
<Image | ||
src={file.url} | ||
alt={file.name} | ||
<div> | ||
{uploadedFiles.length > 0 ? ( | ||
<ScrollArea className="pb-4"> | ||
<div className="flex flex-col space-y-4"> | ||
{uploadedFiles.map((file, key) => ( | ||
<div key={key} className="flex items-center space-x-4 p-4 hover:bg-gray-100/50 rounded-2xl"> | ||
<div className="w-12 h-12 bg-gray-100 rounded-xl relative"> | ||
{/* <Image | ||
src={""} | ||
alt={file.title} | ||
fill | ||
sizes="(min-width: 640px) 640px, 100vw" | ||
loading="lazy" | ||
className="rounded-md object-cover" | ||
/> | ||
/> */} | ||
</div> | ||
<div className="flex flex-col space-y-1"> | ||
<p className="text-md font-semibold text-gray-800">{file.title}</p> | ||
<p className="text-sm text-gray-500"> | ||
{new Date(file.created_at).toLocaleDateString(undefined, { | ||
day: 'numeric', | ||
month: 'long', | ||
hour: '2-digit', | ||
minute: '2-digit' | ||
})} | ||
</p> | ||
</div> | ||
))} | ||
</div> | ||
<ScrollBar orientation="horizontal" /> | ||
</ScrollArea> | ||
) : ( | ||
<EmptyCard | ||
title="No files uploaded" | ||
description="Upload some files to see them here" | ||
className="w-full" | ||
/> | ||
)} | ||
</CardContent> | ||
</Card> | ||
</div> | ||
))} | ||
</div> | ||
<ScrollBar orientation="vertical" /> | ||
</ScrollArea> | ||
) : ( | ||
<EmptyCard | ||
title="No files uploaded" | ||
description="Upload some files to see them here" | ||
className="w-full" | ||
/> | ||
)} | ||
</div> | ||
) | ||
} |
Oops, something went wrong.