mirror of
https://github.com/remvze/moodist.git
synced 2025-10-17 20:10:32 -04:00
feat: reorder sounds in favorites
This commit is contained in:
parent
cb34b59d86
commit
dc9da85e68
@ -18,10 +18,17 @@ export function Categories() {
|
|||||||
const favorites = useFavoriteStore(useShallow(state => state.favorites));
|
const favorites = useFavoriteStore(useShallow(state => state.favorites));
|
||||||
|
|
||||||
const favoriteSounds = useMemo(() => {
|
const favoriteSounds = useMemo(() => {
|
||||||
return categories
|
const favoriteSounds = categories
|
||||||
.map(category => category.sounds)
|
.map(category => category.sounds)
|
||||||
.flat()
|
.flat()
|
||||||
.filter(sound => favorites.includes(sound.id));
|
.filter(sound => favorites.includes(sound.id));
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reorder based on the order of favorites
|
||||||
|
*/
|
||||||
|
return favorites.map(favorite =>
|
||||||
|
favoriteSounds.find(sound => sound.id === favorite),
|
||||||
|
);
|
||||||
}, [favorites, categories]);
|
}, [favorites, categories]);
|
||||||
|
|
||||||
useEffect(() => console.log({ favoriteSounds }), [favoriteSounds]);
|
useEffect(() => console.log({ favoriteSounds }), [favoriteSounds]);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user