diff --git a/src/store/DataStore.tsx b/src/store/DataStore.tsx index 3e236b08..9af7e649 100644 --- a/src/store/DataStore.tsx +++ b/src/store/DataStore.tsx @@ -1,17 +1,21 @@ import { create } from 'zustand' import { apiRequest } from '@/utils/api.ts' +interface CollectionMap { + [key: string]: Collection +} + interface DataStoreType { - collections: Collection[] + collections: CollectionMap initCollection: (url: string) => Promise } export const dataStore = create((set, get) => ({ - collections: [], + collections: {}, initCollection: async (url: string) => { const collection = await apiRequest(url) - const collections: Collection[] = [ ...get().collections ] - collections.push(collection) + const collections: CollectionMap = { ...get().collections } + collections[collection.id] = collection set({ collections }) return collection }