From 399a4e2c515f723b1c8fe5f20840fc0e36fa7c9b Mon Sep 17 00:00:00 2001 From: Pinapelz Date: Fri, 3 Oct 2025 17:03:25 -0700 Subject: fix: remove subscriptions after disabling notifications --- site/src/components/NotificationButton.tsx | 3 + site/src/pages/Homepage.tsx | 91 +++++++++++++++++++++++------- 2 files changed, 74 insertions(+), 20 deletions(-) diff --git a/site/src/components/NotificationButton.tsx b/site/src/components/NotificationButton.tsx index 1e9bc5e..fa31cde 100644 --- a/site/src/components/NotificationButton.tsx +++ b/site/src/components/NotificationButton.tsx @@ -178,6 +178,9 @@ export default function NotificationButton({ className = "", isMoe = false, game console.log("FCM token deleted"); localStorage.removeItem('fcm_token'); + // Clear all subscribed topics + localStorage.removeItem('subscribed_topics'); + if ('serviceWorker' in navigator) { const registration = await navigator.serviceWorker.getRegistration('/firebase-messaging-sw.js'); if (registration) { diff --git a/site/src/pages/Homepage.tsx b/site/src/pages/Homepage.tsx index 871df19..3ebbade 100644 --- a/site/src/pages/Homepage.tsx +++ b/site/src/pages/Homepage.tsx @@ -4,7 +4,7 @@ import { Link, useParams, useSearchParams } from "react-router-dom"; import { getGameTitle } from "../utils.ts"; import TitleBar from "../components/TitleBar"; import { GameNotes } from "../components/GameNotes"; -// import NotificationButton from "../components/NotificationButton"; +import NotificationButton from "../components/NotificationButton"; interface ArcadeNewsAPIData { fetch_time: number; @@ -30,7 +30,9 @@ export default function Home() { useEffect(() => { // Load subscribed games from localStorage const loadSubscribedGames = () => { - const topics = JSON.parse(localStorage.getItem('subscribed_topics') || '[]'); + const topics = JSON.parse( + localStorage.getItem("subscribed_topics") || "[]", + ); setSubscribedGames(topics); }; @@ -41,10 +43,10 @@ export default function Home() { loadSubscribedGames(); }; - window.addEventListener('storage', handleStorageChange); + window.addEventListener("storage", handleStorageChange); return () => { - window.removeEventListener('storage', handleStorageChange); + window.removeEventListener("storage", handleStorageChange); }; }, []); @@ -73,7 +75,9 @@ export default function Home() { // Update subscribed games when localStorage changes locally useEffect(() => { const checkSubscriptions = () => { - const topics = JSON.parse(localStorage.getItem('subscribed_topics') || '[]'); + const topics = JSON.parse( + localStorage.getItem("subscribed_topics") || "[]", + ); setSubscribedGames(topics); }; @@ -164,15 +168,46 @@ export default function Home() { {GameNotes(isMoe)[gameId] && (
{GameNotes(isMoe)[gameId]}
)} - {/*
+
-

- Currently in testing, not all games will receive updates via notifications yet. -

*/}
- - Subscribe via RSS + + + + + + {" "} + + {" "} + {" "} + {" "} + {" "} + {" "} + + + RSS Feed
@@ -214,32 +249,48 @@ export default function Home() {

- {/* */} + {/* Subscribed Games Display */} {subscribedGames.length > 0 && (
{showSubscribedDropdown && ( -
+
{subscribedGames.map((gameId) => (