@@ -12,10 +12,12 @@ import type { Metadata } from '$lib/types/Metadata.type';
12
12
import { importBookmarks } from ' $lib/utils/import-bookmarks' ;
13
13
import { showToast } from ' $lib/utils/show-toast' ;
14
14
import { derived , writable } from ' svelte/store' ;
15
+ import { IconFileTypeHtml } from ' @tabler/icons-svelte' ;
15
16
16
17
const defaultCategory = ' [No parent]' ;
17
18
18
- const step = writable <number >(1 );
19
+ const user = $page .data .user ;
20
+ const step = writable <number >(3 );
19
21
const isFetchingMetadata = writable <boolean >(true );
20
22
const selectedCategory = writable <string >();
21
23
const processedItems = writable <number >(0 );
@@ -108,7 +110,9 @@ const onFileSelected = async (event: Event) => {
108
110
id: i + 1 ,
109
111
icon: bookmark .icon || null ,
110
112
category: {
111
- name: bookmark .categorySlug || defaultCategory
113
+ name:
114
+ importedData .categories .find ((category ) => category .slug === bookmark .categorySlug )
115
+ ?.name || defaultCategory
112
116
},
113
117
description: bookmark .description || ' ' ,
114
118
selected: false ,
@@ -158,19 +162,32 @@ const onSetSelectedCategory = () => {
158
162
};
159
163
</script >
160
164
161
- {#if $step === 1 }
162
- <h1 class =" mb-8 text-2xl font-bold" >Import bookmarks from HTML file</h1 >
163
- <input
164
- type =" file"
165
- title =" Select backup file"
166
- id =" backup"
167
- name =" backup"
168
- accept =" .html,.htm"
169
- multiple ={false }
170
- class =" file-input file-input-bordered file-input-primary file-input-md w-full max-w-xs"
171
- on:change ={onFileSelected } />
165
+ {#if ! user }
166
+ <p >Not logged in.</p >
167
+ {:else if $step === 1 }
168
+ <div class =" hero bg-base-200" >
169
+ <div class =" hero-content flex-col lg:flex-row" >
170
+ <IconFileTypeHtml size ={300 } stroke ={1.2 } class =" rounded-md p-10 text-info" />
171
+ <div >
172
+ <h1 class =" text-4xl font-bold" >Import bookmarks from HTML file</h1 >
173
+ <p class =" py-6" >
174
+ Use this tool to import your bookmarks exported as HTML file (from browser or any
175
+ compatible tool)
176
+ </p >
177
+ <input
178
+ type =" file"
179
+ title =" Select backup file"
180
+ id =" backup"
181
+ name =" backup"
182
+ accept =" .html,.htm"
183
+ multiple ={false }
184
+ class =" file-input file-input-bordered file-input-primary file-input-md w-full max-w-xs"
185
+ on:change ={onFileSelected } />
186
+ </div >
187
+ </div >
188
+ </div >
172
189
{:else if $step === 2 }
173
- <div class =" flex max-w-6xl flex-col" >
190
+ <div class =" flex w-full max-w-4xl flex-col" >
174
191
<form
175
192
method =" POST"
176
193
use:enhance ={({ formData }) => {
@@ -279,34 +296,83 @@ const onSetSelectedCategory = () => {
279
296
items ={$itemsCount }
280
297
position =" right" />
281
298
</div >
282
- {:else if $step === 3 }
283
- <div class =" flex flex-col items-center justify-center" >
299
+ {:else if $step === 3 && $importResult ?. total }
300
+ <div class =" flex w-full flex-col items-center justify-center" >
284
301
<h1 class =" mb-8 text-2xl font-bold" >Import results</h1 >
285
- <div class =" flex flex-col items-center justify-center" >
302
+ <div class =" flex w-full flex-col items-center justify-center" >
286
303
{#if $importResult .successful }
287
- <div class =" alert alert-success" >
288
- <div >
289
- <span class =" text-lg font-bold" >Success!</span >
290
- <span class =" text-sm" >
291
- {$importResult .successful } bookmarks imported successfully.
292
- </span >
293
- </div >
304
+ <div >
305
+ <span class =" text-xl font-bold text-success" >
306
+ {$importResult .successful }
307
+ </span >
308
+ <span class =" text-xl" >bookmarks imported successfully.</span >
294
309
</div >
295
310
{/if }
296
311
{#if $importResult .failed }
297
- <div class =" alert alert-error" >
298
- <div >
299
- <span class =" text-lg font-bold" >Error!</span >
300
- <span class =" text-sm" >
301
- {$importResult .failed } bookmarks failed to import.
302
- </span >
303
- </div >
312
+ <div >
313
+ <span class =" text-xl font-bold text-error" >
314
+ {$importResult .failed }
315
+ </span >
316
+ <span class =" text-xl" >bookmarks failed to import.</span >
304
317
</div >
305
318
{/if }
319
+ <div class =" mt-4" >
320
+ <span class ="text-xl font-bold" >{$importResult .total }</span >
321
+ <span class =" text-xl" >bookmarks in total.</span >
322
+ </div >
323
+
324
+ <div class =" mt-8 flex w-full flex-col gap-4" >
325
+ {#if $importResult .failed }
326
+ <div class =" collapse bg-base-200" >
327
+ <input type =" checkbox" />
328
+ <div class =" collapse-title text-xl font-semibold" >Click here to see failed items</div >
329
+ <div class =" collapse-content" >
330
+ <div class =" flex flex-col gap-4" >
331
+ <div class =" overflow-x-auto" >
332
+ <table class =" table" >
333
+ <thead >
334
+ <tr >
335
+ <th >#</th >
336
+ <th >Title</th >
337
+ <th >Category</th >
338
+ <th >URL</th >
339
+ </tr >
340
+ </thead >
341
+ <tbody >
342
+ {#each $importResult .results .filter ((item ) => ! item .success ) as { bookmark }, i (bookmark .id )}
343
+ <tr class =" bg-base-200" >
344
+ <th >{i + 1 }</th >
345
+ <td class ="break-all font-bold" >{bookmark .title }</td >
346
+ <td >{bookmark .category }</td >
347
+ <td
348
+ ><a class ="link link-primary" href ={bookmark .url } target =" _blank"
349
+ >{bookmark .url .slice (0 , 10 )}{bookmark .url .length > 10 ? ' ...' : ' ' }</a
350
+ ></td >
351
+ </tr >
352
+ {/each }
353
+ </tbody >
354
+ </table >
355
+ </div >
356
+ </div >
357
+ </div >
358
+ </div >
359
+ {/if }
360
+ <div class =" mt-4 flex flex-col items-center justify-center" >
361
+ <a class =" btn btn-primary btn-sm ml-4" href =" /import" >back to import page</a >
362
+ </div >
363
+ </div >
364
+ </div >
365
+ </div >
366
+ {:else }
367
+ <div class =" flex w-full flex-col items-center justify-center" >
368
+ <h1 class =" mb-8 text-2xl font-bold" >Import failed to complete</h1 >
369
+ <p class =" mb-4 text-xl" >Unexpected error occurred while importing bookmarks 🔥</p >
370
+ <p >(check your console for more details)</p >
371
+ <div class =" flex w-full flex-col items-center justify-center" >
306
372
<div class =" flex flex-col items-center justify-center" >
307
- <span >
308
- Total bookmarks: { $importResult . total }
309
- </span >
373
+ <div class = " mt-4 flex flex-col items-center justify-center " >
374
+ < a class = " btn btn-primary btn-sm ml-4 " href = " /import " >try again</ a >
375
+ </div >
310
376
</div >
311
377
</div >
312
378
</div >
0 commit comments