From bd26b2800e2675613c6990673ad0b7b5175aa841 Mon Sep 17 00:00:00 2001
From: Leonardo Bishop <me@leonardobishop.com>
Date: Wed, 13 Mar 2024 19:33:33 +0000
Subject: Add zip export

---
 components/export/ExportZipModal.vue | 67 ++++++++++++++++++++++++++++++++++++
 1 file changed, 67 insertions(+)
 create mode 100644 components/export/ExportZipModal.vue

(limited to 'components/export/ExportZipModal.vue')

diff --git a/components/export/ExportZipModal.vue b/components/export/ExportZipModal.vue
new file mode 100644
index 0000000..b84690d
--- /dev/null
+++ b/components/export/ExportZipModal.vue
@@ -0,0 +1,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>
\ No newline at end of file
-- 
cgit v1.2.3-70-g09d2

