diff --git a/src/components/task/TaskEditComponent.vue b/src/components/task/TaskEditComponent.vue index 32cbdb1..a54a95b 100644 --- a/src/components/task/TaskEditComponent.vue +++ b/src/components/task/TaskEditComponent.vue @@ -122,7 +122,6 @@ hint="Add a boat, if applicable" v-model="modifiedTask.boat" use-input - emit-value input-debounce="250" :options="boatList" option-label="name" @@ -172,7 +171,6 @@ const defaultTask = { volunteers_required: 0, status: 'ready', depends_on: [], - boat: '', }; const { taskId } = props; @@ -210,7 +208,7 @@ function filterTasks(val: string, update: (cb: () => void) => void): void { } function filterTags( - optionVar: Ref, + optionVar: Ref<(SkillTag | TaskTag)[] | undefined>, optionSrc: SkillTag[] | TaskTag[], val: string, update: (cb: () => void) => void diff --git a/src/components/task/TaskTableComponent.vue b/src/components/task/TaskTableComponent.vue index b409127..e34a693 100644 --- a/src/components/task/TaskTableComponent.vue +++ b/src/components/task/TaskTableComponent.vue @@ -22,7 +22,7 @@ color="primary" :disable="loading" label="Delete task(s)" - @click="deleteTask" + @click="deleteTasks" /> { + console.log('Deleting Task: ' + task.$id); + taskStore.deleteTask(task); + return; + }); } const filter = ref(''); diff --git a/src/stores/task.ts b/src/stores/task.ts index 80ed990..ca84312 100644 --- a/src/stores/task.ts +++ b/src/stores/task.ts @@ -1,6 +1,7 @@ import { defineStore } from 'pinia'; import { AppwriteIds, databases, ID } from 'src/boot/appwrite'; import type { Models } from 'appwrite'; +import { Boat } from './boat'; export const TASKSTATUS = ['ready', 'complete', 'waiting', 'archived']; @@ -15,7 +16,7 @@ export interface Task extends Partial { volunteers_required: number; status: string; depends_on: Task[]; - boat: string; + boat?: Boat; } // TODO: convert some of these strings into objects. export interface TaskTag extends Models.Document { @@ -89,11 +90,30 @@ export const useTaskStore = defineStore('tasks', { console.error('Failed to fetch skill tags', error); } }, + async deleteTask(task: Task | string) { + const docId = typeof task === 'string' ? task : task.$id; + if (docId === undefined) { + console.error('No document ID provided to deleteTask!'); + return; + } + try { + const response = await databases.deleteDocument( + AppwriteIds.databaseId, + AppwriteIds.collectionIdTask, + docId + ); + this.tasks = this.tasks.filter((task) => docId !== task.$id); + } catch (error) { + // Need some better error handling, here. + console.error('Failed to delete task:', error); + } + }, async addTask(task: Task) { const newTask = { ...task }; newTask.required_skills = task.required_skills.map((s) => s['$id']); newTask.tags = task.tags.map((s) => s['$id']); newTask.depends_on = task.depends_on.map((d) => d['$id']); + newTask.boat = task.boat?.$id; try { const response = await databases.createDocument( AppwriteIds.databaseId,