Skip to content

Commit e048bc7

Browse files
authored
Merge pull request #274 from Aashish-Upadhyay-101/clickable-docs-links
feat: Clickable docs links
2 parents 4fb9bf7 + 75d2034 commit e048bc7

File tree

7 files changed

+63
-11
lines changed

7 files changed

+63
-11
lines changed

Diff for: components/view/PagesViewer.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export default function PagesViewer({
2020
versionNumber,
2121
brand,
2222
}: {
23-
pages: { file: string; pageNumber: string }[];
23+
pages: { file: string; pageNumber: string; embeddedLinks: string[] }[];
2424
linkId: string;
2525
documentId: string;
2626
viewId: string;
@@ -154,6 +154,7 @@ export default function PagesViewer({
154154
brand={brand}
155155
viewId={viewId}
156156
linkId={linkId}
157+
embeddedLinks={pages[pageNumber - 1].embeddedLinks}
157158
/>
158159
<div
159160
style={{ height: "calc(100vh - 64px)" }}

Diff for: components/view/document-view.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { useRouter } from "next/router";
1616
export type DEFAULT_DOCUMENT_VIEW_TYPE = {
1717
viewId: string;
1818
file: string | null;
19-
pages: { file: string; pageNumber: string }[] | null;
19+
pages: { file: string; pageNumber: string; embeddedLinks: string[] }[] | null;
2020
};
2121

2222
export default function DocumentView({

Diff for: components/view/nav.tsx

+43-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
11
import Link from "next/link";
22
import { Button } from "../ui/button";
33
import PapermarkSparkle from "../shared/icons/papermark-sparkle";
4-
import { Download } from "lucide-react";
4+
import { ArrowUpRight, Download } from "lucide-react";
55
import { Brand } from "@prisma/client";
66
import Image from "next/image";
77
import { toast } from "sonner";
8+
import {
9+
DropdownMenu,
10+
DropdownMenuContent,
11+
DropdownMenuTrigger,
12+
DropdownMenuItem,
13+
DropdownMenuLabel,
14+
DropdownMenuSeparator,
15+
DropdownMenuShortcut,
16+
} from "@/components/ui/dropdown-menu";
817

918
export default function Nav({
1019
pageNumber,
@@ -15,12 +24,14 @@ export default function Nav({
1524
viewId,
1625
linkId,
1726
type,
27+
embeddedLinks,
1828
}: {
1929
pageNumber?: number;
2030
numPages?: number;
2131
allowDownload?: boolean;
2232
assistantEnabled?: boolean;
2333
brand?: Brand;
34+
embeddedLinks?: string[];
2435
viewId?: string;
2536
linkId?: string;
2637
type?: "pdf" | "notion";
@@ -79,7 +90,37 @@ export default function Nav({
7990
)}
8091
</div>
8192
</div>
82-
<div className="absolute inset-y-0 right-0 flex items-center pr-2 sm:static sm:inset-auto sm:ml-6 sm:pr-0 space-x-2">
93+
<div className="absolute inset-y-0 right-0 flex items-center pr-2 sm:static sm:inset-auto sm:ml-6 sm:pr-0 space-x-4">
94+
{embeddedLinks && embeddedLinks.length > 0 ? (
95+
<DropdownMenu>
96+
<DropdownMenuTrigger>
97+
<Button className="text-sm font-medium text-white bg-gray-900 hover:bg-gray-900/80">
98+
Links on Page
99+
</Button>
100+
</DropdownMenuTrigger>
101+
<DropdownMenuContent className="space-y-2" align="end">
102+
<DropdownMenuLabel>Links on current page</DropdownMenuLabel>
103+
<DropdownMenuSeparator />
104+
{embeddedLinks.map((link, index) => (
105+
<Link
106+
href={link}
107+
target="_blank"
108+
rel="noopener noreferrer"
109+
key={index}
110+
>
111+
<DropdownMenuItem className="group h-10">
112+
<span className="w-[200px] truncate group-focus:text-clip group-focus:overflow-x-auto">
113+
{link}
114+
</span>
115+
<DropdownMenuShortcut className="pl-2 opacity-0 group-hover:opacity-60 group-focus:opacity-60">
116+
<ArrowUpRight />
117+
</DropdownMenuShortcut>
118+
</DropdownMenuItem>
119+
</Link>
120+
))}
121+
</DropdownMenuContent>
122+
</DropdownMenu>
123+
) : null}
83124
{assistantEnabled ? (
84125
<Link href={`/view/${linkId}/chat`}>
85126
<Button

Diff for: pages/api/mupdf/convert-page.ts

+6
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ export default async (req: NextApiRequest, res: NextApiResponse) => {
3131
var doc = mupdf.Document.openDocument(pdfData, "application/pdf");
3232

3333
var page = doc.loadPage(pageNumber - 1); // 0-based page index
34+
35+
// get links
36+
const links = page.getLinks();
37+
const embeddedLinks = links.map((link: any) => link.getURI());
38+
3439
var pixmap = page.toPixmap(
3540
// mupdf.Matrix.identity,
3641
[3, 0, 0, 3, 0, 0], // scale 3x
@@ -53,6 +58,7 @@ export default async (req: NextApiRequest, res: NextApiResponse) => {
5358
versionId: documentVersionId,
5459
pageNumber: pageNumber,
5560
file: blob.url,
61+
embeddedLinks: embeddedLinks,
5662
},
5763
});
5864

Diff for: pages/api/views.ts

+1
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ export default async function handle(
194194
select: {
195195
file: true,
196196
pageNumber: true,
197+
embeddedLinks: true,
197198
},
198199
});
199200
console.timeEnd("get-pages");
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
-- AlterTable
2+
ALTER TABLE "DocumentPage" ADD COLUMN "embeddedLinks" TEXT[];

Diff for: prisma/schema.prisma

+8-7
Original file line numberDiff line numberDiff line change
@@ -155,13 +155,14 @@ model DocumentVersion {
155155
}
156156

157157
model DocumentPage {
158-
id String @id @default(cuid())
159-
version DocumentVersion @relation(fields: [versionId], references: [id], onDelete: Cascade)
160-
versionId String
161-
pageNumber Int // e.g., 1, 2, 3 for
162-
file String // This should be a reference to where the file / page is stored (S3, Google Cloud Storage, etc.)
163-
createdAt DateTime @default(now())
164-
updatedAt DateTime @updatedAt
158+
id String @id @default(cuid())
159+
version DocumentVersion @relation(fields: [versionId], references: [id], onDelete: Cascade)
160+
versionId String
161+
pageNumber Int // e.g., 1, 2, 3 for
162+
embeddedLinks String[]
163+
file String // This should be a reference to where the file / page is stored (S3, Google Cloud Storage, etc.)
164+
createdAt DateTime @default(now())
165+
updatedAt DateTime @updatedAt
165166
166167
@@unique([pageNumber, versionId])
167168
@@index([versionId])

0 commit comments

Comments
 (0)