aboutsummaryrefslogtreecommitdiffstats
path: root/apps/web/components/dashboard/preview/AssetContentSection.tsx
blob: 03ab8a4313c792de59fc2c755adfd2802e4b91db (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import Image from "next/image";
import Link from "next/link";

import { BookmarkTypes, ZBookmark } from "@hoarder/shared/types/bookmarks";

export function AssetContentSection({ bookmark }: { bookmark: ZBookmark }) {
  if (bookmark.content.type != BookmarkTypes.ASSET) {
    throw new Error("Invalid content type");
  }

  switch (bookmark.content.assetType) {
    case "image": {
      return (
        <div className="relative h-full min-w-full">
          <Link
            href={`/api/assets/${bookmark.content.assetId}`}
            target="_blank"
          >
            <Image
              alt="asset"
              fill={true}
              className="object-contain"
              src={`/api/assets/${bookmark.content.assetId}`}
            />
          </Link>
        </div>
      );
    }
    case "pdf": {
      return (
        <iframe
          title={bookmark.content.assetId}
          className="h-full w-full"
          src={`/api/assets/${bookmark.content.assetId}`}
        />
      );
    }
    default: {
      return <div>Unsupported asset type</div>;
    }
  }
}