fix: refresh server components after nav style change to fix broken layout

This commit is contained in:
ginnoir
2026-06-01 17:53:21 -05:00
parent 19308be768
commit b255aaeac1
+6 -2
View File
@@ -1,6 +1,7 @@
"use client"; "use client";
import { useCallback, useEffect, useState } from "react"; import { useCallback, useEffect, useState } from "react";
import { useRouter } from "next/navigation";
import type { import type {
Palette, Palette,
ThemeMode, ThemeMode,
@@ -67,6 +68,7 @@ export function useTheme(
const [dashLayout, setDashLayoutState] = useState<DashLayout>(initial.dashLayout ?? "classic"); const [dashLayout, setDashLayoutState] = useState<DashLayout>(initial.dashLayout ?? "classic");
const [calView, setCalViewState] = useState<CalView>(initial.calView ?? "month"); const [calView, setCalViewState] = useState<CalView>(initial.calView ?? "month");
const [navStyle, setNavStyleState] = useState<NavStyle>(initial.navStyle ?? "rail-desktop"); const [navStyle, setNavStyleState] = useState<NavStyle>(initial.navStyle ?? "rail-desktop");
const router = useRouter();
// Re-apply data-nav whenever the viewport crosses the mobile breakpoint. // Re-apply data-nav whenever the viewport crosses the mobile breakpoint.
useEffect(() => { useEffect(() => {
@@ -158,9 +160,11 @@ export function useTheme(
(next: NavStyle) => { (next: NavStyle) => {
setNavStyleState(next); setNavStyleState(next);
applyTheme({ palette, mode, fontPair, density, navStyle: next }); applyTheme({ palette, mode, fontPair, density, navStyle: next });
persist({ navStyle: next }); if (signedIn) {
void setUserTheme({ navStyle: next }).then(() => router.refresh());
}
}, },
[palette, mode, fontPair, density, persist], [palette, mode, fontPair, density, signedIn, router],
); );
return { return {