diff --git a/components/AppContainer.tsx b/components/AppContainer.tsx index 8c98254..8749908 100644 --- a/components/AppContainer.tsx +++ b/components/AppContainer.tsx @@ -18,7 +18,7 @@ import RefreshListsButton from "./RefreshListsButton"; import CheckDoneButton from "./CheckDoneButton"; import { useNowAllFollowers } from "@/lib/accessTwitch"; import { debugLogger } from "@/lib/debugLogger"; -import { lastCheckedDateKey } from "@/lib/constants"; +import { lastCheckedDateKey, storedAllFollowersKey } from "@/lib/constants"; export default function AppContainer() { debugLogger("AppContainer"); @@ -105,7 +105,10 @@ export default function AppContainer() { useEffect(() => { debugLogger("onChecked();"); - if (!localStorage.getItem(lastCheckedDateKey)) { + if ( + !localStorage.getItem(lastCheckedDateKey) && + localStorage.getItem(storedAllFollowersKey) + ) { onChecked(); } }, [onChecked]); diff --git a/lib/accessTwitch.ts b/lib/accessTwitch.ts index 62b25c8..eddb59a 100644 --- a/lib/accessTwitch.ts +++ b/lib/accessTwitch.ts @@ -110,10 +110,16 @@ export const useNowAllFollowers = () => { const resJson = await res.json(); const followers = await fetchFollowers(resJson.data[0].id); + if (!localStorage.getItem(storedAllFollowersKey)) { + // addedUsers の差分が全てのユーザーにならないように、初期値はfollowers + localStorage.setItem(storedAllFollowersKey, JSON.stringify(followers)); + } + const result = await findDifference( followers, - JSON.parse(localStorage.getItem(storedAllFollowersKey) ?? "[]") + JSON.parse(localStorage.getItem(storedAllFollowersKey) as string) ); + debugLogger(result.removedUsers); debugLogger(result.addedUsers); setNowAllFollowers(followers); diff --git a/lib/debugLogger.ts b/lib/debugLogger.ts index ed1a184..2750f60 100644 --- a/lib/debugLogger.ts +++ b/lib/debugLogger.ts @@ -1,7 +1,10 @@ const isDebugMode = (): boolean => { if (typeof window !== "undefined") { // Make it server-side compatible. - return window.location.hash.includes("debug"); + return ( + window.location.hash.includes("debug") || + window.location.hostname === "localhost" + ); } return false; };