aboutsummaryrefslogtreecommitdiffstats
path: root/components/export/ExportZipModal.vue
blob: b84690d4c74dc1691f482a12a6b4e7581d109fce (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<script setup lang="ts">
import { saveAs } from 'file-saver';

const session = useSessionStore();
const exportStore = useExportStore();

const showModal = ref(false);

const status = computed(() => exportStore.getZipStatus());

const startExport = async () => {
  const quests = session.getQuests();
  const categories = session.getCategories();
  const items = session.getItems();

  exportStore.setZipStatus('preparing');

  const { transformedQuests, transformedCategories, transformedItems } = await prepareZip(quests, categories, items);

  exportStore.setZipStatus('compressing');

  try {
    const blob = await createZip(transformedQuests, transformedCategories, transformedItems);

    exportStore.setZipContents(blob);
    exportStore.setZipStatus('ready');

    saveAs(blob, "quests.zip");
  } catch {
    exportStore.setZipStatus('failed');
  }
}

const open = () => {
  showModal.value = true;
}

defineExpose({
  open,
  startExport
})
</script>

<template>
  <Modal v-model="showModal">
    <template v-slot:header>
      <h2>Export as ZIP</h2>
    </template>

    <p v-if="status === 'preparing'">Preparing quests for export...</p>
    <p v-if="status === 'compressing'">Compressing zip...</p>
    <p v-if="status === 'ready'">Done.</p>
    <p v-if="status === 'failed'">Failed to create zip.</p>

    <div id="controls" class="control-group">
      <Button :icon="['fas', 'xmark']" :label="'Close'" @click="showModal = false"></Button>
    </div>
  </Modal>
</template>

<style scoped>
#controls {
  display: flex;
  justify-content: flex-end;
  margin-top: 1rem;
}
</style>