fix: refresh server components after nav style change to fix broken layout
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
"use client";
|
||||
|
||||
import { useCallback, useEffect, useState } from "react";
|
||||
import { useRouter } from "next/navigation";
|
||||
import type {
|
||||
Palette,
|
||||
ThemeMode,
|
||||
@@ -67,6 +68,7 @@ export function useTheme(
|
||||
const [dashLayout, setDashLayoutState] = useState<DashLayout>(initial.dashLayout ?? "classic");
|
||||
const [calView, setCalViewState] = useState<CalView>(initial.calView ?? "month");
|
||||
const [navStyle, setNavStyleState] = useState<NavStyle>(initial.navStyle ?? "rail-desktop");
|
||||
const router = useRouter();
|
||||
|
||||
// Re-apply data-nav whenever the viewport crosses the mobile breakpoint.
|
||||
useEffect(() => {
|
||||
@@ -158,9 +160,11 @@ export function useTheme(
|
||||
(next: NavStyle) => {
|
||||
setNavStyleState(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 {
|
||||
|
||||
Reference in New Issue
Block a user