aboutsummaryrefslogtreecommitdiff
path: root/src/frontend/app/hooks/useFavorites.ts
diff options
context:
space:
mode:
authorAriel Costas Guerrero <ariel@costas.dev>2026-04-02 12:38:10 +0200
committerAriel Costas Guerrero <ariel@costas.dev>2026-04-02 12:45:33 +0200
commit1b4f4a674ac533c0b51260ba35ab91dd2cf9486d (patch)
tree9fdaf418bef86c51737bcf203483089c9e2b908b /src/frontend/app/hooks/useFavorites.ts
parent749e04d6fc2304bb29920db297d1fa4d73b57648 (diff)
Basic push notification system for service alerts
Co-authored-by: Copilot <copilot@github.com>
Diffstat (limited to 'src/frontend/app/hooks/useFavorites.ts')
-rw-r--r--src/frontend/app/hooks/useFavorites.ts6
1 files changed, 6 insertions, 0 deletions
diff --git a/src/frontend/app/hooks/useFavorites.ts b/src/frontend/app/hooks/useFavorites.ts
index 962ac2d..0eceba9 100644
--- a/src/frontend/app/hooks/useFavorites.ts
+++ b/src/frontend/app/hooks/useFavorites.ts
@@ -1,7 +1,10 @@
import { useState } from "react";
+import { writeFavorites } from "~/utils/idb";
/**
* A simple hook for managing favorite items in localStorage.
+ * Also mirrors changes to IndexedDB so the service worker can filter push
+ * notifications by favourites without access to localStorage.
* @param key LocalStorage key to use
* @returns [favorites, toggleFavorite, isFavorite]
*/
@@ -18,6 +21,9 @@ export function useFavorites(key: string) {
? prev.filter((item) => item !== id)
: [...prev, id];
localStorage.setItem(key, JSON.stringify(next));
+ writeFavorites(key, next).catch(() => {
+ /* best-effort */
+ });
return next;
});
};