|
9 | 9 | Card, |
10 | 10 | Helper, |
11 | 11 | Label, |
12 | | - Fileupload, |
13 | | - Textarea, |
14 | | - Table |
| 12 | + Fileupload |
15 | 13 | } from 'flowbite-svelte'; |
| 14 | + import { Table } from '@flowbite-svelte-plugins/datatable'; |
16 | 15 | import { ArrowUpRightFromSquareOutline, MoonOutline, SunOutline } from 'flowbite-svelte-icons'; |
17 | 16 | import { ZipReader, BlobReader } from '@zip.js/zip.js'; |
18 | 17 |
|
19 | 18 | let fileuploadRef = $state() as HTMLInputElement; |
20 | | - let textareaRef = $state() as HTMLTextAreaElement; |
21 | 19 | let files: FileList | null = $state(null); |
22 | 20 |
|
23 | 21 | let reader; |
24 | 22 | let allFiles; |
25 | | - let textureFiles; |
26 | | - let filteredBlocksText = $state(''); |
| 23 | +
|
| 24 | + let textureFiles = $state.raw([]); |
| 25 | + let tableItems = $derived.by(() => { |
| 26 | + // return textureFiles.map((file) => ({ filename: file.filename })); |
| 27 | + return [{ length: textureFiles.length }]; |
| 28 | + // return [{ name: 'example1' }, { name: 'example2' }].map((file) => ({ filename: file.name })); |
| 29 | + }); |
27 | 30 |
|
28 | 31 | function handleOnChange(event: Event) { |
29 | 32 | // console.log(files[0]); |
30 | 33 | loadFile(files[0]); |
31 | 34 | } |
32 | 35 |
|
33 | | - function formatFilesForTable(files) { |
34 | | - return files.map((file) => ({ filename: file.filename })); |
35 | | - } |
36 | | -
|
37 | | - let items = $state([]); |
| 36 | + $inspect(textureFiles, tableItems); |
38 | 37 |
|
39 | 38 | async function loadFile(file) { |
40 | | - reader = await new ZipReader(new BlobReader(file)); |
41 | | - // fileSizeString = `${Math.floor(reader.reader.size / 1e6)} MB`; |
| 39 | + reader = new ZipReader(new BlobReader(file)); |
42 | 40 | allFiles = await reader.getEntries(); |
43 | | -
|
44 | | - // console.log(allFiles); |
45 | | -
|
46 | | - textureFiles = allFiles.filter(filterTextures); |
47 | | - // let totalTextures = textureFiles.length; |
48 | | - textureFiles = textureFiles.filter(filterBlocks); |
49 | | - // let totalBlocks = textureFiles.length; |
50 | | -
|
51 | | - // console.log(textureFiles); |
52 | | -
|
53 | | - filteredBlocksText = textureFiles |
54 | | - .reduce((accumulator, currentValue) => { |
55 | | - return `${accumulator}${currentValue.filename}\n`; |
56 | | - }, '') |
57 | | - .trim(); |
58 | | -
|
59 | | - items = formatFilesForTable(textureFiles); |
60 | | -
|
61 | | - // fileInfoElement.innerText = `JAR size: ${fileSizeString}, All textures: ${totalTextures}, Block textures: ${totalBlocks}`; |
| 41 | + textureFiles = allFiles.filter(filterTextures).filter(filterBlocks); |
62 | 42 | } |
63 | 43 |
|
64 | 44 | function filterTextures(file) { |
|
120 | 100 | /> |
121 | 101 | </Card> |
122 | 102 |
|
123 | | - <Card class="flex max-w-xl gap-2 p-4"> |
124 | | - <Label for="blocklist_display">Textures:</Label> |
125 | | - <Textarea |
126 | | - id="blocklist_display" |
127 | | - bind:value={filteredBlocksText} |
128 | | - bind:elementRef={textareaRef} |
129 | | - rows={10} |
130 | | - class="w-full" |
131 | | - spellcheck="false" |
132 | | - /> |
133 | | - </Card> |
134 | | - |
135 | 103 | <Card class="max-w-xl gap-2 p-4"> |
136 | | - <Table {items}></Table> |
| 104 | + <Table items={tableItems}></Table> |
137 | 105 | </Card> |
138 | 106 | </div> |
139 | 107 | </div> |
0 commit comments