avant codex
This commit is contained in:
26
frontend/src/stores/tools.js
Normal file
26
frontend/src/stores/tools.js
Normal file
@@ -0,0 +1,26 @@
|
||||
import { defineStore } from 'pinia';
|
||||
import { ref } from 'vue';
|
||||
import { toolsApi } from '@/api/tools';
|
||||
export const useToolsStore = defineStore('tools', () => {
|
||||
const tools = ref([]);
|
||||
const loading = ref(false);
|
||||
async function fetchAll() {
|
||||
loading.value = true;
|
||||
try {
|
||||
tools.value = await toolsApi.list();
|
||||
}
|
||||
finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
async function create(t) {
|
||||
const created = await toolsApi.create(t);
|
||||
tools.value.push(created);
|
||||
return created;
|
||||
}
|
||||
async function remove(id) {
|
||||
await toolsApi.delete(id);
|
||||
tools.value = tools.value.filter(t => t.id !== id);
|
||||
}
|
||||
return { tools, loading, fetchAll, create, remove };
|
||||
});
|
||||
Reference in New Issue
Block a user