Add favorite handler to grid cards

This commit is contained in:
jeffvli 2023-01-08 00:52:53 -08:00
parent 7a3bdb531d
commit d17f30f5e6
12 changed files with 114 additions and 7 deletions

View file

@ -9,6 +9,7 @@ export interface AlbumListDataState {
export interface AlbumListDataSlice extends AlbumListDataState {
actions: {
setItemData: (data: any[]) => void;
setItemDataById: (id: string, data: any) => void;
};
}
@ -21,6 +22,13 @@ export const useAlbumListDataStore = create<AlbumListDataSlice>()(
state.itemData = data;
});
},
setItemDataById: (id, data) => {
set((state) => {
const index = state.itemData.findIndex((item) => item?.id === id);
if (index === -1) return;
state.itemData[index] = { ...state.itemData[index], ...data };
});
},
},
itemData: [],
})),
@ -34,3 +42,6 @@ export const useAlbumListItemData = () =>
useAlbumListDataStore((state) => {
return { itemData: state.itemData, setItemData: state.actions.setItemData };
});
export const useSetAlbumListItemDataById = () =>
useAlbumListDataStore((state) => state.actions.setItemDataById);