From a072c91cc0dc26e417c51f666e8547e08ef40942 Mon Sep 17 00:00:00 2001
From: Leonardo Bishop <me@leonardobishop.com>
Date: Tue, 12 Mar 2024 23:18:23 +0000
Subject: Add import from file system

---
 components/loader/LoaderFileSystemButton.vue | 40 ++++++++++++++++++++++++++++
 1 file changed, 40 insertions(+)
 create mode 100644 components/loader/LoaderFileSystemButton.vue

(limited to 'components/loader/LoaderFileSystemButton.vue')

diff --git a/components/loader/LoaderFileSystemButton.vue b/components/loader/LoaderFileSystemButton.vue
new file mode 100644
index 0000000..0d02477
--- /dev/null
+++ b/components/loader/LoaderFileSystemButton.vue
@@ -0,0 +1,40 @@
+<script setup lang="ts">
+import type LoaderFileSystemModal from './LoaderFileSystemModal.vue';
+
+const loaderStore = useLoaderStore();
+
+const { canUseFsApi } = getBrowserCapabilities();
+
+const fileSystemModal = ref<InstanceType<typeof LoaderFileSystemModal> | null>(null);
+
+const openFileSystemPrompt = async () => {
+  fileSystemModal.value?.open();
+  loaderStore.setFileSystemLoaderStatus('pending');
+  const dirHandle = await openFileSystem();
+  if (!dirHandle) {
+    loaderStore.setFileSystemLoaderStatus('inactive');
+    return;
+  }
+  loaderStore.setPath(dirHandle.name);
+  loaderStore.setFileSystemLoaderStatus('loaded');
+  try {
+    const { categories, quests, items } = await enumerateQuestDirectory(dirHandle);
+    loaderStore.setCategories(categories);
+    loaderStore.setQuests(quests);
+    loaderStore.setItems(items);
+    loaderStore.setFileSystemLoaderStatus('valid');
+  } catch (e) {
+    console.error(e);
+    loaderStore.setFileSystemLoaderStatus('invalid');
+  }
+}
+</script>
+
+<template>
+  <ClientOnly>
+    <Button type="solid" :icon="['fas', 'folder-open']" label="Import from Filesystem" @click="openFileSystemPrompt"
+      :disabled="!canUseFsApi" />
+
+    <LoaderFileSystemModal ref="fileSystemModal" />
+  </ClientOnly>
+</template>
\ No newline at end of file
-- 
cgit v1.2.3-70-g09d2

