aboutsummaryrefslogtreecommitdiffstats
path: root/apps/web/components/dashboard/preview/LinkContentSection.tsx
diff options
context:
space:
mode:
authorMohamedBassem <me@mbassem.com>2024-04-19 20:01:51 +0100
committerMohamed Bassem <me@mbassem.com>2024-04-20 00:05:31 +0100
commit4402e6f04170cbb0613d35fe94471162253e91b2 (patch)
tree696f6511cefa7d1c6bc3a1f8bc2de755870310cc /apps/web/components/dashboard/preview/LinkContentSection.tsx
parentb4a13ce3d92ee505124fc98804935c1122978550 (diff)
downloadkarakeep-4402e6f04170cbb0613d35fe94471162253e91b2.tar.zst
feature: Download images and screenshots
Diffstat (limited to 'apps/web/components/dashboard/preview/LinkContentSection.tsx')
-rw-r--r--apps/web/components/dashboard/preview/LinkContentSection.tsx77
1 files changed, 77 insertions, 0 deletions
diff --git a/apps/web/components/dashboard/preview/LinkContentSection.tsx b/apps/web/components/dashboard/preview/LinkContentSection.tsx
new file mode 100644
index 00000000..ff08c661
--- /dev/null
+++ b/apps/web/components/dashboard/preview/LinkContentSection.tsx
@@ -0,0 +1,77 @@
+import { useState } from "react";
+import {
+ Select,
+ SelectContent,
+ SelectGroup,
+ SelectItem,
+ SelectTrigger,
+ SelectValue,
+} from "@/components/ui/select";
+import { ScrollArea } from "@radix-ui/react-scroll-area";
+
+import { ZBookmark, ZBookmarkedLink } from "@hoarder/shared/types/bookmarks";
+
+function ScreenshotSection({ link }: { link: ZBookmarkedLink }) {
+ // eslint-disable-next-line @next/next/no-img-element
+ return <img alt="screenshot" src={`/api/assets/${link.screenshotAssetId}`} />;
+}
+
+function CachedContentSection({ link }: { link: ZBookmarkedLink }) {
+ let content;
+ if (!link.htmlContent) {
+ content = (
+ <div className="text-destructive">Failed to fetch link content ...</div>
+ );
+ } else {
+ content = (
+ <div
+ dangerouslySetInnerHTML={{
+ __html: link.htmlContent || "",
+ }}
+ className="prose mx-auto dark:prose-invert"
+ />
+ );
+ }
+ return content;
+}
+
+export default function LinkContentSection({
+ bookmark,
+}: {
+ bookmark: ZBookmark;
+}) {
+ const [section, setSection] = useState<string>("cached");
+
+ if (bookmark.content.type != "link") {
+ throw new Error("Invalid content type");
+ }
+
+ let content;
+ if (section === "cached") {
+ content = <CachedContentSection link={bookmark.content} />;
+ } else {
+ content = <ScreenshotSection link={bookmark.content} />;
+ }
+
+ return (
+ <div className="flex flex-col items-center gap-2">
+ <Select onValueChange={setSection} value={section}>
+ <SelectTrigger className="w-fit">
+ <SelectValue />
+ </SelectTrigger>
+ <SelectContent>
+ <SelectGroup>
+ <SelectItem value="cached">Cached Content</SelectItem>
+ <SelectItem
+ value="screenshot"
+ disabled={!bookmark.content.screenshotAssetId}
+ >
+ Screenshot
+ </SelectItem>
+ </SelectGroup>
+ </SelectContent>
+ </Select>
+ <ScrollArea className="h-full">{content}</ScrollArea>
+ </div>
+ );
+}