From 1e5c575e16c8a9e6bd7592e83bea53af7f359e15 Mon Sep 17 00:00:00 2001 From: MohamedBassem Date: Sun, 6 Oct 2024 14:33:40 +0000 Subject: refactor: Start tracking bookmark assets in the assets table --- .../components/dashboard/preview/AttachmentBox.tsx | 112 +++++++++++---------- 1 file changed, 57 insertions(+), 55 deletions(-) (limited to 'apps/web/components') diff --git a/apps/web/components/dashboard/preview/AttachmentBox.tsx b/apps/web/components/dashboard/preview/AttachmentBox.tsx index a8eaf0f4..436f1026 100644 --- a/apps/web/components/dashboard/preview/AttachmentBox.tsx +++ b/apps/web/components/dashboard/preview/AttachmentBox.tsx @@ -16,6 +16,7 @@ import { ChevronsDownUp, Download, Image, + Paperclip, Pencil, Plus, Trash2, @@ -35,6 +36,7 @@ import { import { humanFriendlyNameForAssertType, isAllowedToAttachAsset, + isAllowedToDetachAsset, } from "@hoarder/trpc/lib/attachments"; export default function AttachmentBox({ bookmark }: { bookmark: ZBookmark }) { @@ -42,6 +44,8 @@ export default function AttachmentBox({ bookmark }: { bookmark: ZBookmark }) { screenshot: , fullPageArchive: , bannerImage: , + bookmarkAsset: , + unknown: , }; const { mutate: attachAsset, isPending: isAttaching } = @@ -100,11 +104,6 @@ export default function AttachmentBox({ bookmark }: { bookmark: ZBookmark }) { bookmark.assets.sort((a, b) => a.assetType.localeCompare(b.assetType)); - if (bookmark.content.type == BookmarkTypes.ASSET) { - // Currently, we don't allow attaching assets to assets types. - return null; - } - return ( @@ -156,59 +155,62 @@ export default function AttachmentBox({ bookmark }: { bookmark: ZBookmark }) { )} - ( - - detachAsset( - { bookmarkId: bookmark.id, assetId: asset.id }, - { onSettled: () => setDialogOpen(false) }, - ) - } - > - - Delete - - )} - > - - + {isAllowedToDetachAsset(asset.assetType) && ( + ( + + detachAsset( + { bookmarkId: bookmark.id, assetId: asset.id }, + { onSettled: () => setDialogOpen(false) }, + ) + } + > + + Delete + + )} + > + + + )} ))} - {!bookmark.assets.some((asset) => asset.assetType == "bannerImage") && ( - - uploadAsset(file, { - onSuccess: (resp) => { - attachAsset({ - bookmarkId: bookmark.id, - asset: { - id: resp.assetId, - assetType: "bannerImage", - }, - }); - }, - }) - } - > - - Attach a Banner - - )} + {!bookmark.assets.some((asset) => asset.assetType == "bannerImage") && + bookmark.content.type != BookmarkTypes.ASSET && ( + + uploadAsset(file, { + onSuccess: (resp) => { + attachAsset({ + bookmarkId: bookmark.id, + asset: { + id: resp.assetId, + assetType: "bannerImage", + }, + }); + }, + }) + } + > + + Attach a Banner + + )} ); -- cgit v1.2.3-70-g09d2