initial commit
This commit is contained in:
62
app/stores/lists.ts
Normal file
62
app/stores/lists.ts
Normal file
@@ -0,0 +1,62 @@
|
||||
import { defineStore } from 'pinia'
|
||||
import type { List } from '~/types/lists'
|
||||
|
||||
|
||||
export const useListStore = defineStore('lists', {
|
||||
state: () => ({
|
||||
lists: [] as List[],
|
||||
loading: false as boolean,
|
||||
}),
|
||||
|
||||
actions: {
|
||||
saveLists(lists:Array<List>){
|
||||
this.lists = lists
|
||||
},
|
||||
resetLists(){
|
||||
this.lists = []
|
||||
},
|
||||
|
||||
async fetchLists() {
|
||||
// On récupère notre plugin API injecté
|
||||
const { $api } = useNuxtApp();
|
||||
this.loading = true;
|
||||
|
||||
try {
|
||||
// L'appel est maintenant ultra simple et typé
|
||||
const data = await $api.lists.getAll();
|
||||
this.lists = data;
|
||||
} catch (error) {
|
||||
// La gestion d'erreur est centralisée,
|
||||
// mais tu peux ajouter une logique spécifique ici (ex: notification)
|
||||
console.error("Erreur lors du chargement des listes:", error);
|
||||
throw error;
|
||||
} finally {
|
||||
this.loading = false;
|
||||
}
|
||||
}
|
||||
|
||||
// async updateList(id, title, content) {
|
||||
// const config = useRuntimeConfig();
|
||||
|
||||
// try {
|
||||
// const data = await $fetch<[]|null>(`${config.public.apiBase}/lists`, {
|
||||
// method: 'GET',
|
||||
// headers: {
|
||||
// // On injecte le token ici
|
||||
// 'Authorization': `Bearer ${this.token}`
|
||||
// },
|
||||
// // Si tu as besoin d'envoyer un corps de message vide ou spécifique
|
||||
// // body: {}
|
||||
// });
|
||||
|
||||
// this.lists = data;
|
||||
// console.log(data);
|
||||
// console.log(this.token);
|
||||
// return data;
|
||||
// } catch (error) {
|
||||
// console.error("Erreur lors de la récupération des listes:", error);
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
})
|
||||
Reference in New Issue
Block a user