|
| 1 | +<template> |
| 2 | + <UPage> |
| 3 | + <UPageHeader |
| 4 | + :title="title" |
| 5 | + headline="Vertalen" |
| 6 | + :description="description" |
| 7 | + /> |
| 8 | + |
| 9 | + <UPageBody> |
| 10 | + <form method="post" action="/api/outlines" enctype="multipart/form-data"> |
| 11 | + <!-- <UFileUpload |
| 12 | + v-model="jwpubFile" |
| 13 | + name="file" |
| 14 | + :file-delete="false" |
| 15 | + accept=".jwpub,.JWPUB" |
| 16 | + class="w-full min-h-48" |
| 17 | + :disabled="!!jwpubFile" |
| 18 | + label="Importeer vanuit S-34 formulier." |
| 19 | + /> --> |
| 20 | + <input name="file" type="file" accept=".jwpub,.JWPUB" /> |
| 21 | + <UButton class="mr-2" type="reset" color="error" label="Reset" /> |
| 22 | + <UButton type="submit" label="Importeren" /> |
| 23 | + </form> |
| 24 | + <template v-if="loading"> |
| 25 | + <UPageGrid> |
| 26 | + <div v-for="i in 12" :key="i" class="grid gap-2"> |
| 27 | + <USkeleton class="h-4 w-3xs" /> |
| 28 | + <USkeleton class="h-4 w-20" /> |
| 29 | + <USkeleton class="h-4 w-full" /> |
| 30 | + </div> |
| 31 | + </UPageGrid> |
| 32 | + </template> |
| 33 | + <template v-else> |
| 34 | + <UPageGrid> |
| 35 | + <OutlineForm |
| 36 | + v-for="outline in jsonStore.originals.outlines" |
| 37 | + :id="`outline-${outline.number}`" |
| 38 | + :key="outline.number" |
| 39 | + :outline="outline" |
| 40 | + /> |
| 41 | + </UPageGrid> |
| 42 | + </template> |
| 43 | + </UPageBody> |
| 44 | + </UPage> |
| 45 | +</template> |
| 46 | +<script setup lang="ts"> |
| 47 | +const jsonStore = useJsonStore(); |
| 48 | +
|
| 49 | +const loading = ref(false); |
| 50 | +const jwpubFile = ref<File | null>(null); |
| 51 | +
|
| 52 | +const { showError } = useFlash(); |
| 53 | +
|
| 54 | +const _importOutlines = async () => { |
| 55 | + if (!jwpubFile.value) return; |
| 56 | +
|
| 57 | + loading.value = true; |
| 58 | + try { |
| 59 | + const body = new FormData(); |
| 60 | + body.append("file", jwpubFile.value); |
| 61 | + const parsedOutlines = await $fetch<Outline[]>("/api/outlines", { |
| 62 | + body, |
| 63 | + method: "POST", |
| 64 | + }); |
| 65 | +
|
| 66 | + const outlines = |
| 67 | + jsonStore.outlines.translations?.map((outline) => ({ |
| 68 | + ...outline, |
| 69 | + ...(parsedOutlines.find((o) => o.number === outline.number) ?? {}), |
| 70 | + })) ?? []; |
| 71 | +
|
| 72 | + jsonStore.setTranslations({ outlines }, "outlines"); |
| 73 | + } catch { |
| 74 | + showError({ |
| 75 | + description: |
| 76 | + "Er is een fout opgetreden bij het importeren van de lezingen.", |
| 77 | + id: "import-outlines-error", |
| 78 | + }); |
| 79 | + } |
| 80 | + loading.value = false; |
| 81 | + jwpubFile.value = null; |
| 82 | +}; |
| 83 | +
|
| 84 | +const title = "Lezingen"; |
| 85 | +const description = "Vertaal op deze pagina de lezingen."; |
| 86 | +
|
| 87 | +useSeoMeta({ |
| 88 | + description, |
| 89 | + ogDescription: description, |
| 90 | + ogTitle: title, |
| 91 | + title, |
| 92 | +}); |
| 93 | +</script> |
0 commit comments