|
1 | 1 | <script setup lang="ts"> |
2 | 2 | import { useSortable } from '@vueuse/integrations/useSortable' |
3 | 3 |
|
4 | | -const { factoryPresets } = useFactoryPresets() |
| 4 | +const userPresets = ref<Schema[]>([]) |
5 | 5 |
|
6 | 6 | const el = useTemplateRef<HTMLElement>('el') |
7 | 7 |
|
8 | | -useSortable(el, factoryPresets as Ref<Schema[]>, { |
| 8 | +useSortable(el, userPresets as Ref<Schema[]>, { |
9 | 9 | animation: 400 |
10 | 10 | }) |
| 11 | +
|
| 12 | +const files = ref<File[]>([]) |
| 13 | +
|
| 14 | +watch(files, (latest, existing) => { |
| 15 | + // Only process newly added files and deal with files being removed |
| 16 | + const newFiles = latest.filter(file => !existing.includes(file)) |
| 17 | + if (newFiles.length > 0) { |
| 18 | + newFiles.forEach((file) => { |
| 19 | + const reader = new FileReader() |
| 20 | + reader.onload = () => { |
| 21 | + const fileContents = JSON.parse(reader.result as string) as Schema |
| 22 | + // if () |
| 23 | + // check if preset already exists in factoryPresets |
| 24 | + if (userPresets.value?.some(preset => preset.data.meta.name === fileContents.data.meta.name)) { |
| 25 | + console.log(fileContents.data.meta.name, ' - Preset with this name already exists') |
| 26 | + // TODO: ask user to overwrite, rename or cancel |
| 27 | + } |
| 28 | + userPresets.value?.push(fileContents) |
| 29 | + } |
| 30 | + reader.readAsText(file) |
| 31 | + }) |
| 32 | + } |
| 33 | +}) |
11 | 34 | </script> |
12 | 35 |
|
13 | 36 | <template> |
14 | | - <div ref="el" class="columns-1 sm:columns-2 md:columns-3 gap-2"> |
15 | | - <UBadge |
16 | | - v-for="(item, i) in factoryPresets" |
17 | | - :key="i" |
18 | | - class="m-1 cursor-grab" |
19 | | - variant="soft" |
20 | | - size="lg" |
21 | | - trailing-icon="i-lucide-grip-vertical" |
22 | | - > |
23 | | - <template #leading> |
24 | | - <span class="w-5">{{ i }}.</span> |
25 | | - </template> |
26 | | - <UInput v-model="item.data.meta.name" /> |
27 | | - </UBadge> |
| 37 | + <div> |
| 38 | + <div> |
| 39 | + <!-- <FileUpload /> --> |
| 40 | + <UFileUpload |
| 41 | + v-model="files" |
| 42 | + multiple |
| 43 | + layout="grid" |
| 44 | + class="w-96 min-h-48" |
| 45 | + accept="text/json,.thrl6p" |
| 46 | + label="Upload your presets" |
| 47 | + description=".thrl6p format" |
| 48 | + highlight |
| 49 | + /> |
| 50 | + <!-- <pre>{{ files }}</pre> --> |
| 51 | + </div> |
| 52 | + <div ref="el" class="columns-1 sm:columns-2 md:columns-3 gap-2"> |
| 53 | + <UBadge |
| 54 | + v-for="(item, i) in userPresets" |
| 55 | + :key="i" |
| 56 | + class="m-1 cursor-grab" |
| 57 | + variant="soft" |
| 58 | + size="lg" |
| 59 | + trailing-icon="i-lucide-grip-vertical" |
| 60 | + > |
| 61 | + <template #leading> |
| 62 | + <span class="w-5">{{ i }}.</span> |
| 63 | + </template> |
| 64 | + <UInput v-model="item.data.meta.name" /> |
| 65 | + </UBadge> |
| 66 | + </div> |
28 | 67 | </div> |
29 | 68 | </template> |
0 commit comments