aboutsummaryrefslogtreecommitdiffstats
path: root/components/editor/task/modal
diff options
context:
space:
mode:
authorLeonardo Bishop <me@leonardobishop.com>2024-03-10 01:31:42 +0000
committerLeonardo Bishop <me@leonardobishop.com>2024-03-10 01:31:42 +0000
commit71e4ad2c71efea471923ea47f01bfda841387f81 (patch)
treef08293fdc56b4eb2e3d0e520b79b4d8aad78924c /components/editor/task/modal
parent4495c02c41b95ce6df0c34dbf6ac62f7addae7a3 (diff)
Use nuxt auto import magic
Diffstat (limited to 'components/editor/task/modal')
-rw-r--r--components/editor/task/modal/Change.vue61
-rw-r--r--components/editor/task/modal/Create.vue75
2 files changed, 136 insertions, 0 deletions
diff --git a/components/editor/task/modal/Change.vue b/components/editor/task/modal/Change.vue
new file mode 100644
index 0000000..db7d96b
--- /dev/null
+++ b/components/editor/task/modal/Change.vue
@@ -0,0 +1,61 @@
+<script setup lang="ts">
+import { computed, ref } from 'vue';
+import { useSessionStore } from '@/stores/session';
+
+const model = defineModel();
+
+const emit = defineEmits(['update']);
+
+const session = useSessionStore();
+
+const props = defineProps({
+ taskId: String,
+ currentTaskType: String,
+});
+
+const knownTaskTypes = computed(() => session.getKnownTaskTypes());
+
+const newType = ref('');
+const unknownTaskType = computed(() => !knownTaskTypes.value.includes(newType.value));
+const noChange = computed(() => newType.value === props.currentTaskType);
+const newTypeDescription = computed(() => session.getTaskDefinitionByTaskType(newType.value)?.description);
+</script>
+
+<template>
+ <Modal v-model="model">
+ <template v-slot:header>
+ <h2>Change the task type of '{{ taskId }}'</h2>
+ </template>
+
+ <template v-slot:body>
+ <div id="body">
+ <div class="option-group">
+ <label for="new-type">New type</label>
+ <multiselect id="new-type" v-model="newType" :options="knownTaskTypes" :searchable="true"
+ placeholder="Select a new type"></multiselect>
+ </div>
+ <p v-if="unknownTaskType" class="error-text">Invalid task type.</p>
+ <p v-if="newTypeDescription">{{ newTypeDescription }}</p>
+ <p>Any configured options for this task will be overwritten.</p>
+ <div id="confirm" class="control-group">
+ <Button :icon="['fas', 'fa-times']" :label="'Cancel'" @click="model = false"></Button>
+ <Button type="solid" :icon="['fas', 'fa-check']" :label="'Change'" :disabled="unknownTaskType || noChange"
+ @click="emit('update', newType)"></Button>
+ </div>
+ </div>
+ </template>
+ </Modal>
+</template>
+
+<style scoped>
+#confirm {
+ display: flex;
+ justify-content: flex-end;
+}
+
+#body {
+ display: flex;
+ flex-direction: column;
+ gap: 0.5rem;
+}
+</style> \ No newline at end of file
diff --git a/components/editor/task/modal/Create.vue b/components/editor/task/modal/Create.vue
new file mode 100644
index 0000000..d286759
--- /dev/null
+++ b/components/editor/task/modal/Create.vue
@@ -0,0 +1,75 @@
+<script setup lang="ts">
+import { computed, ref } from 'vue';
+import { useSessionStore } from '@/stores/session';
+import { validateTaskId } from '@/lib/util';
+
+const model = defineModel();
+
+const emit = defineEmits(['add']);
+
+const session = useSessionStore();
+
+const props = defineProps({
+ questId: {
+ type: String,
+ required: true,
+ },
+});
+
+const knownTasks = computed(() => session.getQuestById(props.questId)!.tasks);
+const knownTaskTypes = computed(() => session.getKnownTaskTypes());
+
+const newId = ref('');
+const newType = ref('');
+const unknownTaskType = computed(() => !knownTaskTypes.value.includes(newType.value));
+const invalidTaskId = computed(() => !validateTaskId(newId.value));
+const duplicateTaskId = computed(() => knownTasks.value[newId.value] !== undefined);
+
+const newTypeDescription = computed(() => session.getTaskDefinitionByTaskType(newType.value)?.description);
+</script>
+
+<template>
+ <Modal v-model="model">
+ <template v-slot:header>
+ <h2>Add new task</h2>
+ </template>
+
+ <template v-slot:body>
+ <div id="body">
+ <div class="option-group">
+ <label for="new-type">Task ID</label>
+ <input id="new-id" name="new-id" type="text" v-model="newId" />
+ <p v-if="invalidTaskId" class="error-text">Invalid task ID.</p>
+ <p v-if="duplicateTaskId" class="error-text">Task ID already exists.</p>
+ </div>
+ <div class="option-group">
+ <label for="new-type">Task type</label>
+ <multiselect id="new-type" v-model="newType" :options="knownTaskTypes" :searchable="true"
+ placeholder="Select a new type"></multiselect>
+ <p v-if="unknownTaskType" class="error-text">Invalid task type.</p>
+ </div>
+ <p v-if="newTypeDescription">{{ newTypeDescription }}</p>
+ <p>A task ID must be unique, alphanumeric, and not contain any spaces.</p>
+ <div id="confirm" class="control-group">
+ <Button :icon="['fas', 'fa-times']" :label="'Cancel'" @click="model = false"></Button>
+ <Button type="solid" :icon="['fas', 'fa-check']" :label="'Confirm'"
+ :disabled="unknownTaskType || invalidTaskId || duplicateTaskId"
+ @click="emit('add', newId, newType)"></Button>
+ </div>
+ </div>
+ </template>
+ </Modal>
+</template>
+
+<style scoped>
+#confirm {
+ display: flex;
+ justify-content: flex-end;
+}
+
+#body {
+ display: flex;
+ flex-direction: column;
+ gap: 0.5rem;
+}
+</style> \ No newline at end of file