diff options
| author | Mohamed Bassem <me@mbassem.com> | 2024-11-17 02:39:06 +0000 |
|---|---|---|
| committer | Mohamed Bassem <me@mbassem.com> | 2024-11-17 02:39:33 +0000 |
| commit | 82cd3bb8fa2814b7e27b610682cd04d6f471ac2d (patch) | |
| tree | 26b06ca73f3a4bf754953475dca26cacefe10b35 /apps | |
| parent | 64e759a82349a85c4da55dbb47bb4b939dfeb322 (diff) | |
| download | karakeep-82cd3bb8fa2814b7e27b610682cd04d6f471ac2d.tar.zst | |
feature: Allow setting bookmark metadata during creation
Diffstat (limited to 'apps')
| -rw-r--r-- | apps/web/components/settings/ImportExport.tsx | 29 |
1 files changed, 9 insertions, 20 deletions
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, |
