feat(frontend): API layer + stores Pinia
Ajoute le client Axios, les modules API (gardens, varieties, plantings, tasks) et les stores Pinia correspondants. Corrige tsconfig.json pour inclure vite/client et DOM.Iterable. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
34
frontend/src/stores/tasks.ts
Normal file
34
frontend/src/stores/tasks.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
import { defineStore } from 'pinia'
|
||||
import { ref } from 'vue'
|
||||
import { tasksApi, type Task } from '@/api/tasks'
|
||||
|
||||
export const useTasksStore = defineStore('tasks', () => {
|
||||
const tasks = ref<Task[]>([])
|
||||
const loading = ref(false)
|
||||
|
||||
async function fetchAll(params?: { statut?: string; garden_id?: number }) {
|
||||
loading.value = true
|
||||
tasks.value = await tasksApi.list(params)
|
||||
loading.value = false
|
||||
}
|
||||
|
||||
async function create(t: Partial<Task>) {
|
||||
const created = await tasksApi.create(t)
|
||||
tasks.value.push(created)
|
||||
return created
|
||||
}
|
||||
|
||||
async function updateStatut(id: number, statut: string) {
|
||||
const t = tasks.value.find(t => t.id === id)
|
||||
if (!t) return
|
||||
const updated = await tasksApi.update(id, { ...t, statut })
|
||||
Object.assign(t, updated)
|
||||
}
|
||||
|
||||
async function remove(id: number) {
|
||||
await tasksApi.delete(id)
|
||||
tasks.value = tasks.value.filter(t => t.id !== id)
|
||||
}
|
||||
|
||||
return { tasks, loading, fetchAll, create, updateStatut, remove }
|
||||
})
|
||||
Reference in New Issue
Block a user