Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion e2e/landing.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ test("dashboard stays protected for unauthenticated users", async ({ page }) =>

await expect(page).toHaveURL(/\/$/);
await expect(page.getByRole("link", { name: "Sign in with GitHub" })).toBeVisible();
});
});
8 changes: 3 additions & 5 deletions src/hooks/useHeatmapTheme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,10 @@ export function getCalendarCellStyle(count: number, config: HeatmapThemeConfig):

export function useHeatmapTheme() {
const [theme, _setTheme] = useState<HeatmapTheme>("default");
const [mounted, setMounted] = useState(false);

// Initialize from localStorage on mount
useEffect(() => {
setMounted(true);
if (typeof window === "undefined") return;

const saved = window.localStorage.getItem(STORAGE_KEY) as HeatmapTheme | null;
Expand All @@ -133,20 +134,17 @@ export function useHeatmapTheme() {
_setTheme(saved ?? "default");
}, []);

// Broadcast and persist theme changes
const setTheme = (t: HeatmapTheme) => {
if (typeof window !== "undefined") {
try {
window.localStorage.setItem(STORAGE_KEY, t);
} catch {}
// notify other listeners in this window
window.dispatchEvent(new CustomEvent("heatmap-theme-changed", { detail: t }));
}

_setTheme(t);
};

// Listen for theme changes from other components/tabs
useEffect(() => {
if (typeof window === "undefined") return;

Expand Down Expand Up @@ -183,7 +181,7 @@ export function useHeatmapTheme() {
);

return {
theme,
theme: mounted ? theme : "default",
setTheme,
themeConfig,
getHeatmapStyle,
Expand Down
Loading