Skip to content

Commit 9bcf05f

Browse files
committed
Close #1
1 parent e373df7 commit 9bcf05f

File tree

1 file changed

+62
-16
lines changed

1 file changed

+62
-16
lines changed

src/routes/+page.svelte

Lines changed: 62 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,37 @@
77
NavHamburger,
88
DarkMode,
99
Card,
10-
Fileupload,
1110
Helper,
1211
Label,
1312
Button,
1413
Popover,
15-
Kbd
14+
Kbd,
15+
Dropzone,
16+
Alert
1617
} from 'flowbite-svelte';
1718
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+
}
1841
</script>
1942

2043
<Navbar class="bg-gray-100">
@@ -32,19 +55,42 @@
3255
</Navbar>
3356

3457
<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/&lt;version&gt;/&ltversion&gt;.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/&lt;version&gt;/&ltversion&gt;.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>
4995
</Card>
5096
</div>

0 commit comments

Comments
 (0)