From 82cd3bb8fa2814b7e27b610682cd04d6f471ac2d Mon Sep 17 00:00:00 2001 From: Mohamed Bassem Date: Sun, 17 Nov 2024 02:39:06 +0000 Subject: feature: Allow setting bookmark metadata during creation --- apps/web/components/settings/ImportExport.tsx | 29 +++++++++------------------ 1 file changed, 9 insertions(+), 20 deletions(-) (limited to 'apps/web/components') diff --git a/apps/web/components/settings/ImportExport.tsx b/apps/web/components/settings/ImportExport.tsx index 5cb35def..34e069da 100644 --- a/apps/web/components/settings/ImportExport.tsx +++ b/apps/web/components/settings/ImportExport.tsx @@ -22,7 +22,6 @@ import { Download, Upload } from "lucide-react"; import { useCreateBookmarkWithPostHook, - useUpdateBookmark, useUpdateBookmarkTags, } from "@hoarder/shared-react/hooks/bookmarks"; import { @@ -57,7 +56,6 @@ export function ImportExportRow() { } | null>(null); const { mutateAsync: createBookmark } = useCreateBookmarkWithPostHook(); - const { mutateAsync: updateBookmark } = useUpdateBookmark(); const { mutateAsync: createList } = useCreateBookmarkList(); const { mutateAsync: addToList } = useAddBookmarkToList(); const { mutateAsync: updateTags } = useUpdateBookmarkTags(); @@ -71,8 +69,13 @@ export function ImportExportRow() { if (bookmark.content === undefined) { throw new Error("Content is undefined"); } - const created = await createBookmark( - bookmark.content.type === BookmarkTypes.LINK + const created = await createBookmark({ + title: bookmark.title, + createdAt: bookmark.addDate + ? new Date(bookmark.addDate * 1000) + : undefined, + note: bookmark.notes, + ...(bookmark.content.type === BookmarkTypes.LINK ? { type: BookmarkTypes.LINK, url: bookmark.content.url, @@ -80,24 +83,10 @@ export function ImportExportRow() { : { type: BookmarkTypes.TEXT, text: bookmark.content.text, - }, - ); + }), + }); await Promise.all([ - // Update title and createdAt if they're set - bookmark.title.length > 0 || bookmark.addDate - ? updateBookmark({ - bookmarkId: created.id, - title: bookmark.title, - createdAt: bookmark.addDate - ? new Date(bookmark.addDate * 1000) - : undefined, - note: bookmark.notes, - }).catch(() => { - /* empty */ - }) - : undefined, - // Add to import list addToList({ bookmarkId: created.id, -- cgit v1.2.3-70-g09d2