diff --git a/src/lib/components/BulkList/BulkList.svelte b/src/lib/components/BulkList/BulkList.svelte index 0ff093e..046c27e 100644 --- a/src/lib/components/BulkList/BulkList.svelte +++ b/src/lib/components/BulkList/BulkList.svelte @@ -4,7 +4,7 @@ import { type Readable } from 'svelte/store'; import BulkListItem from '../BulkListItem/BulkListItem.svelte'; export let itemList: Readable; -export let isLoading = false; +export let isLoading: boolean; const selectAllItems = ({ target }: Event) => { if (target instanceof HTMLInputElement) { @@ -39,7 +39,7 @@ const selectAllItems = ({ target }: Event) => { title={item.title} category={item.category} selected={item.selected} - isLoading={item.isLoading} + isLoading={isLoading} metadataFetched={!!item.contentHtml} metadata={item} /> {/each} diff --git a/src/lib/components/BulkListItem/BulkListItem.svelte b/src/lib/components/BulkListItem/BulkListItem.svelte index d370d15..42368a0 100644 --- a/src/lib/components/BulkListItem/BulkListItem.svelte +++ b/src/lib/components/BulkListItem/BulkListItem.svelte @@ -22,6 +22,7 @@ let urlObj = new URL(url); const onEditItem = () => { editBookmarkStore.set({ + imported: true, description: '', note: '', ...metadata, diff --git a/src/lib/components/EditBookmarkForm/EditBookmarkForm.svelte b/src/lib/components/EditBookmarkForm/EditBookmarkForm.svelte index e05981f..9612778 100644 --- a/src/lib/components/EditBookmarkForm/EditBookmarkForm.svelte +++ b/src/lib/components/EditBookmarkForm/EditBookmarkForm.svelte @@ -10,7 +10,7 @@ import { writable, type Writable } from 'svelte/store'; import { invalidate } from '$app/navigation'; import { editBookmarkStore } from '$lib/stores/edit-bookmark.store'; import { searchEngine } from '$lib/stores/search.store'; -import type { Bookmark } from '$lib/types/Bookmark.type'; +import type { Bookmark, BookmarkEdit } from '$lib/types/Bookmark.type'; import { updateBookmarkInSearchIndex } from '$lib/utils/search'; import { showToast } from '$lib/utils/show-toast'; @@ -19,7 +19,7 @@ export let closeModal: () => void; let error = ''; const loading = writable(false); -const bookmark = writable>({}); +const bookmark = writable | BookmarkEdit>(); $: $bookmark = { ...$editBookmarkStore }; @@ -92,6 +92,21 @@ function handleTagsChange() { ]; } +function handleImportedBookmarkEdit() { + const formData = new FormData(form); + let rawData = Object.fromEntries(formData as any); + console.log('rawData', rawData); + delete rawData.tags; + editBookmarkStore.set({ + ...$bookmark, + ...rawData, + category: JSON.parse(rawData.category)?.label, + bookmarkTags: $bookmarkTags + }); + console.log('$editBookmarkStore', $editBookmarkStore); + closeModal(); +} + const onGetMetadata = _.debounce( async (event: Event) => { const validateUrlRegex = @@ -376,6 +391,14 @@ const onGetMetadata = _.debounce( diff --git a/src/lib/stores/edit-bookmark.store.ts b/src/lib/stores/edit-bookmark.store.ts index b1c2b02..b029559 100644 --- a/src/lib/stores/edit-bookmark.store.ts +++ b/src/lib/stores/edit-bookmark.store.ts @@ -1,4 +1,4 @@ -import type { Bookmark } from '$lib/types/Bookmark.type'; +import type { Bookmark, BookmarkEdit } from '$lib/types/Bookmark.type'; import { writable } from 'svelte/store'; -export const editBookmarkStore = writable>({}); +export const editBookmarkStore = writable | BookmarkEdit>({}); diff --git a/src/lib/types/Bookmark.type.ts b/src/lib/types/Bookmark.type.ts index ed87c80..32aef00 100644 --- a/src/lib/types/Bookmark.type.ts +++ b/src/lib/types/Bookmark.type.ts @@ -1,4 +1,5 @@ import type { Category } from './Category.type'; +import type { Metadata } from './Metadata.type'; import type { Tag } from './Tag.type'; import type { User } from './User.type'; @@ -38,3 +39,18 @@ export type BookmarkForIndex = Omit; }; + +export type BookmarkEdit = Partial & { + id: number; + icon: string | null; + url: string; + title: string; + category: string; + selected: boolean; + imported?: boolean; + bookmarkTags?: { + value: string; + label: string; + created?: boolean; + }[]; +}; diff --git a/src/lib/types/common/BulkList.type.ts b/src/lib/types/common/BulkList.type.ts index c320aff..13b55dc 100644 --- a/src/lib/types/common/BulkList.type.ts +++ b/src/lib/types/common/BulkList.type.ts @@ -1,10 +1,3 @@ -import type { Metadata } from '../Metadata.type'; +import type { BookmarkEdit } from '../Bookmark.type'; -export type BulkListItem = Partial & { - id: number; - icon: string | null; - url: string; - title: string; - category: string; - selected: boolean; -}; +export type BulkListItem = BookmarkEdit; diff --git a/src/routes/import/+page.svelte b/src/routes/import/+page.svelte index eaefcf8..e751251 100644 --- a/src/routes/import/+page.svelte +++ b/src/routes/import/+page.svelte @@ -1,194 +1,12 @@ -
- {#if $step === 1} -

Import bookmarks from HTML file

- - {:else if $step === 2} -
- - - {#if $isAnySelected && !$isFetchingMetadata} - +{:else if $step === 2} +
+
+ + + {#if $isAnySelected && !$isFetchingMetadata} +