Attempt to add basic tasklist
All checks were successful
Build BAB Application Deployment Artifact / build (push) Successful in 2m8s

This commit is contained in:
2024-03-12 22:44:24 -04:00
parent 6ff1a69e2b
commit 0986d04ea6
5 changed files with 95 additions and 94 deletions

View File

@@ -1,90 +1,63 @@
import { defineStore } from 'pinia';
import { Databases } from 'appwrite';
import { AppwriteIds, databases, ID } from 'src/boot/appwrite';
import type { Models } from 'appwrite';
export const useCounterStore = defineStore('counter', {
state: () => ({
counter: 0,
}),
getters: {
doubleCount(state) {
return state.counter * 2;
},
},
actions: {
increment() {
this.counter++;
},
},
});
export interface Task {
id: string;
export interface Task extends Models.Document {
title: string;
description: string;
taskLabels: string[];
dueDate: Date;
created: Date;
parentId: string;
completed: boolean;
}
const getSampleData = () => [
{
id: 1,
name: 'ProjectX',
displayName: 'PX',
class: 'J/27',
year: 1981,
imgsrc: '/tmpimg/j27.png',
iconsrc: '/tmpimg/projectx_avatar256.png',
defects: [
{
type: 'engine',
severity: 'moderate',
description: 'Fuel line leaks at engine fitting.',
detail: `The gasket in the end of the fuel hose is damaged, and does not properly seal.
This will cause fuel to leak, and will allow air into the fuel chamber, causing a lean mixture,
and rough engine performance.`,
},
{
type: 'rigging',
severity: 'moderate',
description: 'Tiller extension is broken.',
detail:
'The tiller extension swivel is broken, and will not attach to the tiller.',
},
],
},
{
id: 2,
name: 'Take5',
displayName: 'T5',
class: 'J/27',
year: 1985,
imgsrc: '/tmpimg/j27.png',
iconsrc: '/tmpimg/take5_avatar32.png',
},
{
id: 3,
name: 'WeeBeestie',
displayName: 'WB',
class: 'Capri 25',
year: 1989,
imgsrc: '/tmpimg/capri25.png',
},
];
export const useBoatStore = defineStore('boat', {
export const useTaskStore = defineStore('tasks', {
state: () => ({
boats: getSampleData(),
tasks: [] as Task[],
}),
getters: {},
actions: {
// update () {
// }
async fetchTasks() {
try {
const response = await databases.listDocuments(
AppwriteIds.databaseId,
AppwriteIds.collectionIdTask
);
this.tasks = response.documents as Task[];
} catch (error) {
console.error('Failed to fetch tasks', error);
}
},
async addTask(task: Task) {
try {
const response = await databases.createDocument(
AppwriteIds.databaseId,
AppwriteIds.collectionIdTask,
ID.unique(),
task
);
this.tasks.push(response as Task);
} catch (error) {
console.error('Failed to add task:', error);
}
},
},
// Add more actions as needed (e.g., updateTask, deleteTask)
getters: {
// A getter to reconstruct the hierarchical structure from flat task data
taskHierarchy: (state) => {
function buildHierarchy(
tasks: Task[],
parentId: string | null = null
): Task[] {
return tasks
.filter((task) => task.parentId === parentId)
.map((task) => ({
...task,
subtasks: buildHierarchy(tasks, task.$id), // Assuming $id is the task ID field
}));
}
return buildHierarchy(state.tasks);
},
},
});