feat(layout): add cookie persistence for playground sidebar state management

This commit is contained in:
Anish Sarkar 2026-07-15 18:12:30 +05:30
parent d5b5c9cda2
commit 3740171a5c

View file

@ -44,6 +44,20 @@ const DocumentTabContent = dynamic(
const PLAYGROUND_SIDEBAR_COLLAPSED_COOKIE = "surfsense_playground_sidebar_collapsed"; const PLAYGROUND_SIDEBAR_COLLAPSED_COOKIE = "surfsense_playground_sidebar_collapsed";
const PLAYGROUND_SIDEBAR_COOKIE_MAX_AGE = 60 * 60 * 24 * 365; const PLAYGROUND_SIDEBAR_COOKIE_MAX_AGE = 60 * 60 * 24 * 365;
function persistPlaygroundSidebarCollapsedCookie(isCollapsed: boolean) {
void window.cookieStore
?.set({
name: PLAYGROUND_SIDEBAR_COLLAPSED_COOKIE,
value: String(isCollapsed),
path: "/",
expires: Date.now() + PLAYGROUND_SIDEBAR_COOKIE_MAX_AGE * 1000,
sameSite: "lax",
})
.catch(() => {
// Ignore preference persistence failures.
});
}
function MacDesktopTitleBar({ function MacDesktopTitleBar({
isSidebarCollapsed, isSidebarCollapsed,
onToggleSidebar, onToggleSidebar,
@ -242,8 +256,7 @@ export function LayoutShell({
const handlePlaygroundSidebarToggle = () => { const handlePlaygroundSidebarToggle = () => {
setIsPlaygroundSidebarCollapsed((collapsed) => { setIsPlaygroundSidebarCollapsed((collapsed) => {
const nextCollapsed = !collapsed; const nextCollapsed = !collapsed;
const secureAttribute = window.location.protocol === "https:" ? "; Secure" : ""; persistPlaygroundSidebarCollapsedCookie(nextCollapsed);
document.cookie = `${PLAYGROUND_SIDEBAR_COLLAPSED_COOKIE}=${nextCollapsed}; Path=/; Max-Age=${PLAYGROUND_SIDEBAR_COOKIE_MAX_AGE}; SameSite=Lax${secureAttribute}`;
return nextCollapsed; return nextCollapsed;
}); });
}; };