first commit
This commit is contained in:
26
store/Card.ts
Normal file
26
store/Card.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import { defineStore } from "pinia";
|
||||
import type { Card } from "~/types/Card";
|
||||
|
||||
export const useCardStore = defineStore("cardStore", {
|
||||
state: () => ({
|
||||
collections: [] as string[],
|
||||
cards: [] as Card[],
|
||||
}),
|
||||
actions: {
|
||||
async fetchCollections() {
|
||||
const { data: collections } =
|
||||
await useFetch<string[]>("/api/collections");
|
||||
this.collections = collections.value ?? [];
|
||||
},
|
||||
async fetchCardsByCollection(collectionName: string) {
|
||||
const response = useFetch<Card[]>(`/api/cards/${collectionName}`);
|
||||
this.cards = response.data.value ?? [];
|
||||
},
|
||||
removeCard(id: number) {
|
||||
const index = this.cards.findIndex((card) => card.id === id);
|
||||
if (index !== -1) {
|
||||
this.cards.splice(index, 1);
|
||||
}
|
||||
},
|
||||
},
|
||||
});
|
||||
Reference in New Issue
Block a user