current init

This commit is contained in:
Marek
2026-03-30 15:42:44 +02:00
parent c5229e48ed
commit 2f96caaa23
366 changed files with 6093 additions and 11029 deletions

View File

@@ -0,0 +1,34 @@
import { defineStore } from 'pinia'
import { ref } from 'vue'
import * as api from '../services/api'
export const useCategoriesStore = defineStore('categories', () => {
const items = ref([])
const loaded = ref(false)
async function fetchCategories(force = false) {
if (loaded.value && !force) return
items.value = await api.getCategories()
loaded.value = true
}
async function addCategory(data) {
const category = await api.createCategory(data)
items.value.push(category)
return category
}
async function editCategory(id, data) {
const updated = await api.updateCategory(id, data)
const index = items.value.findIndex((c) => c.id === id)
if (index !== -1) items.value[index] = updated
return updated
}
async function removeCategory(id) {
await api.deleteCategory(id)
items.value = items.value.filter((c) => c.id !== id)
}
return { items, loaded, fetchCategories, addCategory, editCategory, removeCategory }
})