mirror of
https://github.com/antebudimir/feishin.git
synced 2026-01-01 02:13:33 +00:00
Add favorite handler to grid cards
This commit is contained in:
parent
7a3bdb531d
commit
d17f30f5e6
12 changed files with 114 additions and 7 deletions
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue