|
9 | 9 |
|
10 | 10 | const entries = $derived(Object.values(db.file?.entries ?? {})) |
11 | 11 |
|
| 12 | + let error = $state(false) |
| 13 | + $effect(() => { |
| 14 | + if (!error) return |
| 15 | +
|
| 16 | + setTimeout(() => { |
| 17 | + error = false |
| 18 | + }, 7500) |
| 19 | + }) |
| 20 | +
|
12 | 21 | const relevantLanguages = $derived.by((): Option[] => { |
13 | 22 | const languages = Object.keys( |
14 | 23 | entries[0].strings, |
|
59 | 68 |
|
60 | 69 | const ondrop = async (event: DragEvent & { currentTarget: HTMLDivElement }) => { |
61 | 70 | event.preventDefault() |
62 | | - const file = event.dataTransfer!.items[0].getAsFile()! |
63 | | - const remsg = decodeMsg(Buffer.from(await file.arrayBuffer())) |
64 | | - const entries = Object.fromEntries(remsg.entries.map((entry) => [entry.name, entry])) |
65 | | -
|
66 | | - db.file = { |
67 | | - name: file.name, |
68 | | - meta: remsg.meta, |
69 | | - entries, |
| 71 | + error = false |
| 72 | +
|
| 73 | + try { |
| 74 | + const file = event.dataTransfer!.items[0].getAsFile()! |
| 75 | + const remsg = decodeMsg(Buffer.from(await file.arrayBuffer())) |
| 76 | + const entries = Object.fromEntries( |
| 77 | + remsg.entries.map((entry) => [entry.name, entry]), |
| 78 | + ) |
| 79 | +
|
| 80 | + db.file = { |
| 81 | + name: file.name, |
| 82 | + meta: remsg.meta, |
| 83 | + entries, |
| 84 | + } |
| 85 | + } catch { |
| 86 | + error = true |
70 | 87 | } |
71 | 88 |
|
72 | 89 | dragging = false |
|
105 | 122 | {#if dragging} |
106 | 123 | <div |
107 | 124 | transition:fade={{ duration: 100 }} |
108 | | - class="l-0 t-0 bg-amber-9 bg-op-25 z-100 fixed flex h-full w-full items-center justify-center" |
| 125 | + class="bg-amber-9 bg-op-25 z-100 fixed flex h-full w-full items-center justify-center" |
109 | 126 | > |
110 | 127 | <div |
111 | | - class="w-350px max-w-80% h-250px text-30px bg-#111 text-shadow-lg border-3px border-amber-4 rounded-30px flex items-center justify-center border-dashed font-bold shadow-lg" |
| 128 | + class="w-350px max-w-80% h-250px text-30px bg-#111 text-shadow-lg b-3px b-amber-4 rounded-30px b-dashed flex items-center justify-center font-bold shadow-lg" |
112 | 129 | > |
113 | 130 | Drop file |
114 | 131 | </div> |
115 | 132 | </div> |
116 | 133 | {/if} |
117 | 134 |
|
| 135 | + {#if error} |
| 136 | + <div |
| 137 | + transition:fade={{ duration: 250 }} |
| 138 | + class="b-3 b-1px b-solid b-red-5 fixed bottom-8 right-8 z-50 flex items-center justify-center rounded-lg bg-red-950 px-5 py-3" |
| 139 | + > |
| 140 | + Invalid file |
| 141 | + </div> |
| 142 | + {/if} |
| 143 | + |
118 | 144 | {#if db?.file == null} |
119 | 145 | <label |
120 | 146 | for="file" |
121 | | - class="h-75 w-75 border-1 border-amber flex cursor-pointer flex-col items-center justify-center rounded-2xl border-solid p-8" |
| 147 | + class="h-75 w-75 b-1 b-amber b-solid flex cursor-pointer flex-col items-center justify-center rounded-2xl p-8" |
122 | 148 | > |
123 | 149 | <span class="i-lucide:file-scan h-25 w-25"></span> |
124 | 150 | <span class="text-center font-bold"> |
|
0 commit comments