Skip to content

Commit

Permalink
ui: dialog for viewing individual PDFs
Browse files Browse the repository at this point in the history
  • Loading branch information
Nyumat committed Nov 4, 2024
1 parent 0508203 commit 12e4592
Showing 1 changed file with 72 additions and 0 deletions.
72 changes: 72 additions & 0 deletions src/components/pdf-item.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import { Button } from "@/components/ui/button";
import {
Dialog,
DialogContent,
DialogTitle,
DialogTrigger,
} from "@/components/ui/dialog";
import { Label } from "@/components/ui/label";
import { useState } from "react";

type PdfItemProps = {
file: {
id: string;
title: string;
description: string;
fileUrl: string;
};
onPreview: (id: string) => Promise<string>;
};

export function PdfItem({ file, onPreview }: PdfItemProps) {
const [previewUrl, setPreviewUrl] = useState<string | null>(null);

const handlePreviewClick = async () => {
const url = await onPreview(file.id);
if (!url) return;
setPreviewUrl(url);
};

return (
<li className="border-b pb-2">
<div className="flex justify-between items-center">
<div>
<Label className="font-semibold">{file.title}</Label>
<p className="text-sm text-gray-500">{file.description}</p>
</div>
<div className="ml-12 flex space-x-2">
<Dialog>
<DialogTrigger asChild>
<Button variant="outline" onClick={handlePreviewClick}>
Preview
</Button>
</DialogTrigger>
<DialogContent>
<DialogTitle>Preview</DialogTitle>
<div className="h-96 overflow-auto">
{previewUrl && (
<iframe
src={`https://docs.google.com/gview?url=${encodeURIComponent(
previewUrl,
)}&embedded=true`}
width="100%"
height="500"
frameBorder="0"
scrolling="no"
></iframe>
)}
</div>
</DialogContent>
</Dialog>

<Button
variant="default"
onClick={() => window.open(previewUrl!, "_blank")}
>
Download
</Button>
</div>
</div>
</li>
);
}

0 comments on commit 12e4592

Please sign in to comment.