@@ -8,6 +8,7 @@ import { editBookmarkCategoriesStore, editBookmarkStore } from '$lib/stores/edit
8
8
import { importBookmarkStore } from ' $lib/stores/import-bookmarks.store' ;
9
9
import type { ImportExecutionResult } from ' $lib/types/BookmarkImport.type' ;
10
10
import type { BulkListItem } from ' $lib/types/common/BulkList.type' ;
11
+ import type { Metadata } from ' $lib/types/Metadata.type' ;
11
12
import { importBookmarks } from ' $lib/utils/import-bookmarks' ;
12
13
import { showToast } from ' $lib/utils/show-toast' ;
13
14
import { derived , writable } from ' svelte/store' ;
@@ -45,15 +46,15 @@ const processMetadataQueue = async (items: BulkListItem[]) => {
45
46
body: JSON .stringify ({ url: item .url }),
46
47
headers: { ' Content-Type' : ' application/json' }
47
48
});
48
- const { metadata } = await response .json ();
49
+ const { metadata }: { metadata : Metadata } = await response .json ();
49
50
processedItems .update ((count ) => count + 1 );
50
51
51
52
return {
52
- ... metadata ,
53
53
... item ,
54
+ ... metadata ,
55
+ title: item .title || metadata .title ,
54
56
imported: true ,
55
- icon: item .icon || metadata .iconUrl ,
56
- title: item .title || metadata .title
57
+ icon: item .icon || metadata .iconUrl
57
58
};
58
59
} catch (error ) {
59
60
console .error (` Failed to fetch metadata for ${item .url }: ` , error );
@@ -113,7 +114,16 @@ const onFileSelected = async (event: Event) => {
113
114
selected: false ,
114
115
importance: null ,
115
116
flagged: null ,
116
- note: null
117
+ note: null ,
118
+ domain: ' ' ,
119
+ author: null ,
120
+ contentHtml: null ,
121
+ contentText: null ,
122
+ contentPublishedDate: null ,
123
+ contentType: null ,
124
+ mainImageUrl: null ,
125
+ iconUrl: null ,
126
+ imported: true
117
127
}));
118
128
$editBookmarkCategoriesStore = [... new Set (updatedBookmarks .map ((item ) => item .category .name ))];
119
129
@@ -160,39 +170,55 @@ const onSetSelectedCategory = () => {
160
170
class =" file-input file-input-bordered file-input-primary file-input-md w-full max-w-xs"
161
171
on:change ={onFileSelected } />
162
172
{:else if $step === 2 }
163
- <form
164
- method =" POST"
165
- use:enhance ={({ formData }) => {
166
- formData .set (
167
- ' bookmarks' ,
168
- JSON .stringify (
169
- $importBookmarkStore .map ((bookmark ) => ({
170
- url: bookmark .url ,
171
- title: bookmark .title ,
172
- description: bookmark .description ,
173
- category: bookmark .category .name ,
174
- bookmarkTags: bookmark .bookmarkTags
175
- }))
176
- )
177
- );
173
+ <div class =" flex max-w-6xl flex-col" >
174
+ <form
175
+ method =" POST"
176
+ use:enhance ={({ formData }) => {
177
+ formData .set (
178
+ ' bookmarks' ,
179
+ JSON .stringify (
180
+ $importBookmarkStore .map ((bookmark ) => ({
181
+ url: bookmark .url ,
182
+ domain: bookmark .domain ,
183
+ title: bookmark .title ,
184
+ description: bookmark .description ,
185
+ category: bookmark .category ,
186
+ mainImageUrl: bookmark .mainImageUrl ,
187
+ iconUrl: bookmark .iconUrl ,
188
+ author: bookmark .author ,
189
+ contentText: bookmark .contentText ,
190
+ contentHtml: bookmark .contentHtml ,
191
+ contentType: bookmark .contentType ,
192
+ contentPublishedDate: bookmark .contentPublishedDate ,
193
+ importance: bookmark .importance ,
194
+ flagged: bookmark .flagged ,
195
+ note: bookmark .note ,
196
+ bookmarkTags: bookmark .bookmarkTags
197
+ }))
198
+ )
199
+ );
178
200
179
- return async ({ update , result }) => {
180
- if (result .type === ' success' ) {
181
- showToast .success (' Bookmarks imported successfully' );
182
- step .set (3 );
183
- } else {
184
- showToast .error (' Failed to import bookmarks' );
185
- }
186
- update ();
187
- };
188
- }}>
189
- <div class =" flex max-w-6xl flex-col" >
201
+ return async ({ update , result }) => {
202
+ if (result .type === ' success' && result ?.data ?.data ) {
203
+ showToast .success (' Bookmarks imported successfully' );
204
+ const { data } = result .data ;
205
+ if (data ) {
206
+ // @ts-ignore-next-line
207
+ importResult .set (data );
208
+ step .set (3 );
209
+ }
210
+ } else {
211
+ showToast .error (' Failed to import bookmarks' );
212
+ }
213
+ update ();
214
+ };
215
+ }}>
190
216
<div class =" mb-4 flex w-full gap-2 pl-12" >
191
217
<button
192
218
type =" submit"
193
219
class =" btn btn-primary btn-sm"
194
220
disabled ={$isFetchingMetadata || $importBookmarkStore .length === 0 }
195
- aria-label =" Import selected bookmarks" >
221
+ aria-label =" Import bookmarks" >
196
222
{#if $isFetchingMetadata }
197
223
<span class =" loading loading-spinner loading-xs" ></span >
198
224
{/if }
@@ -246,13 +272,13 @@ const onSetSelectedCategory = () => {
246
272
</div >
247
273
248
274
<BulkList itemList ={currentItems } isLoading ={$isFetchingMetadata } />
249
- < Pagination
250
- page ={ $page . data . page }
251
- limit ={$page .data .limit }
252
- items ={$itemsCount }
253
- position = " right " />
254
- </ div >
255
- </form >
275
+ </ form >
276
+ < Pagination
277
+ page ={$page .data .page }
278
+ limit ={$page . data . limit }
279
+ items ={ $itemsCount }
280
+ position = " right " / >
281
+ </div >
256
282
{:else if $step === 3 }
257
283
<div class =" flex flex-col items-center justify-center" >
258
284
<h1 class =" mb-8 text-2xl font-bold" >Import results</h1 >
0 commit comments