From 0b3257997a97088e22c9b6881c20a4807422ec05 Mon Sep 17 00:00:00 2001 From: Akshay Nair Date: Sun, 29 Sep 2024 17:22:19 +0530 Subject: Open alarm when clock is pressed --- src/hooks/useFavorites.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'src/hooks') diff --git a/src/hooks/useFavorites.ts b/src/hooks/useFavorites.ts index fa96211..625ac08 100644 --- a/src/hooks/useFavorites.ts +++ b/src/hooks/useFavorites.ts @@ -10,7 +10,10 @@ const favoriteAppNamesAtom = atomWithStorage( jsonStorage, ); -const serialize = (packageNames: string[]) => packageNames.join(','); +const isSameArray = (a: string[], b: string[]): boolean => { + if (a.length !== b.length) return false; + return a.every((item, index) => item === b[index]); +}; export const useFavorites = () => { const [favoriteAppNames, setFavoriteAppNames] = useAtom(favoriteAppNamesAtom); @@ -20,7 +23,7 @@ export const useFavorites = () => { updater: (packageNames: string[]) => Promise | string[], ) => { const newNames = [...new Set(await updater(favoriteAppNames))]; - if (serialize(newNames) === serialize(favoriteAppNames)) return newNames; + if (isSameArray(newNames, favoriteAppNames)) return newNames; setFavoriteAppNames(newNames); return newNames; -- cgit v1.3.1