mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-07-26 23:51:14 +02:00
feat(layout): add cookie persistence for playground sidebar state management
This commit is contained in:
parent
d5b5c9cda2
commit
3740171a5c
1 changed files with 15 additions and 2 deletions
|
|
@ -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;
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue