|
7 | 7 | NavHamburger, |
8 | 8 | DarkMode, |
9 | 9 | Card, |
10 | | - Fileupload, |
11 | 10 | Helper, |
12 | 11 | Label, |
13 | 12 | Button, |
14 | 13 | Popover, |
15 | | - Kbd |
| 14 | + Kbd, |
| 15 | + Dropzone, |
| 16 | + Alert |
16 | 17 | } from 'flowbite-svelte'; |
17 | 18 | import { ArrowUpRightFromSquareOutline } from 'flowbite-svelte-icons'; |
| 19 | +
|
| 20 | + let filesInDropzone: FileList | null = $state(null); |
| 21 | +
|
| 22 | + function handleOnChange(event: Event) { |
| 23 | + console.log('handleOnChange fired.'); |
| 24 | + const target = event.target as HTMLInputElement; |
| 25 | + filesInDropzone = target.files; |
| 26 | + } |
| 27 | +
|
| 28 | + function handleOnDrop(event: DragEvent) { |
| 29 | + console.log('handleOnDrop fired.'); |
| 30 | + event.preventDefault(); |
| 31 | + filesInDropzone = event.dataTransfer?.files ?? null; |
| 32 | + } |
| 33 | +
|
| 34 | + function showFiles(files: FileList | null): string { |
| 35 | + console.log('showFiles fired.'); |
| 36 | + if (!files || files.length === 0) return 'No files selected.'; |
| 37 | + return Array.from(files) |
| 38 | + .map((file) => file.name) |
| 39 | + .join(', '); |
| 40 | + } |
18 | 41 | </script> |
19 | 42 |
|
20 | 43 | <Navbar class="bg-gray-100"> |
|
32 | 55 | </Navbar> |
33 | 56 |
|
34 | 57 | <div class="flex flex-col items-center p-4"> |
35 | | - <Card class="flex gap-3 p-4"> |
36 | | - <Label for="jarfile">Select a Minecraft JAR to extract textures</Label> |
37 | | - <Fileupload id="jarfile" accept=".jar"></Fileupload> |
38 | | - <Helper> |
39 | | - <a href="https://minecraft.wiki/w/.minecraft#Locating" |
40 | | - ><Kbd class="cursor-pointer">.minecraft/versions/<version>/<version>.jar</Kbd></a |
41 | | - > |
42 | | - </Helper> |
43 | | - <Popover |
44 | | - ><div class="flex flex-row items-center gap-1"> |
45 | | - <span>How to find the <code>.minecraft</code> folder</span> |
46 | | - <ArrowUpRightFromSquareOutline /> |
47 | | - </div> |
48 | | - </Popover> |
| 58 | + <Card class="flex gap-4 p-4"> |
| 59 | + <div> |
| 60 | + <Label for="jarfile">Select a Minecraft JAR to extract textures</Label> |
| 61 | + <Helper> |
| 62 | + <a |
| 63 | + class="flex flex-row items-center gap-1 underline" |
| 64 | + href="https://minecraft.wiki/w/.minecraft#Locating" |
| 65 | + > |
| 66 | + <span>How to find the <code>.minecraft</code> folder</span> |
| 67 | + <ArrowUpRightFromSquareOutline strokeWidth="1.5" /> |
| 68 | + </a> |
| 69 | + </Helper> |
| 70 | + </div> |
| 71 | + <Dropzone |
| 72 | + class="p-3" |
| 73 | + id="jarfile" |
| 74 | + accept=".jar" |
| 75 | + bind:files={filesInDropzone} |
| 76 | + onChange={handleOnChange} |
| 77 | + onDrop={handleOnDrop} |
| 78 | + > |
| 79 | + {#if !filesInDropzone || filesInDropzone.length === 0} |
| 80 | + <p class="mb-2 text-sm text-gray-500 dark:text-gray-400"> |
| 81 | + <span class="font-semibold">Click to upload</span> |
| 82 | + or drag and drop |
| 83 | + </p> |
| 84 | + <p class="text-xs text-gray-500 dark:text-gray-400"> |
| 85 | + <code>.minecraft/versions/<version>/<version>.jar</code> |
| 86 | + </p> |
| 87 | + {:else} |
| 88 | + <p class="text-sm text-green-600">{showFiles(filesInDropzone)}</p> |
| 89 | + <button |
| 90 | + class="mt-2 text-sm text-red-500 hover:underline" |
| 91 | + onclick={() => (filesInDropzone = null)}>Clear Files</button |
| 92 | + > |
| 93 | + {/if} |
| 94 | + </Dropzone> |
49 | 95 | </Card> |
50 | 96 | </div> |
0 commit comments