6ede33ccdb
Build and Push Docker Images / create_manifest (web, surfsense-web, , cpu) (push) Has been cancelled
Build and Push Docker Images / finalize_release (push) Has been cancelled
Obsidian Plugin Lint / lint (push) Has been cancelled
Build and Push Docker Images / build (./surfsense_web, cpu, ./surfsense_web/Dockerfile, web, surfsense-web, ubuntu-24.04-arm, linux/arm64, arm64, , runner, false, cpu) (push) Has been cancelled
Build and Push Docker Images / build (./surfsense_web, cpu, ./surfsense_web/Dockerfile, web, surfsense-web, ubuntu-latest, linux/amd64, amd64, , runner, false, cpu) (push) Has been cancelled
Build and Push Docker Images / compute_version (push) Has been cancelled
Build and Push Docker Images / build (./surfsense_backend, cpu, ./surfsense_backend/Dockerfile, backend, surfsense-backend, ubuntu-24.04-arm, linux/arm64, arm64, , production, false, cpu) (push) Has been cancelled
Build and Push Docker Images / build (./surfsense_backend, cpu, ./surfsense_backend/Dockerfile, backend, surfsense-backend, ubuntu-latest, linux/amd64, amd64, , production, false, cpu) (push) Has been cancelled
Build and Push Docker Images / build (./surfsense_backend, cu126, ./surfsense_backend/Dockerfile, backend, surfsense-backend, ubuntu-24.04-arm, linux/arm64, arm64, -cuda126, production, true, cuda126) (push) Has been cancelled
Build and Push Docker Images / build (./surfsense_backend, cu126, ./surfsense_backend/Dockerfile, backend, surfsense-backend, ubuntu-latest, linux/amd64, amd64, -cuda126, production, true, cuda126) (push) Has been cancelled
Build and Push Docker Images / build (./surfsense_backend, cu128, ./surfsense_backend/Dockerfile, backend, surfsense-backend, ubuntu-24.04-arm, linux/arm64, arm64, -cuda, production, true, cuda) (push) Has been cancelled
Build and Push Docker Images / build (./surfsense_backend, cu128, ./surfsense_backend/Dockerfile, backend, surfsense-backend, ubuntu-latest, linux/amd64, amd64, -cuda, production, true, cuda) (push) Has been cancelled
Build and Push Docker Images / verify_digests (push) Has been cancelled
Build and Push Docker Images / create_manifest (backend, surfsense-backend, , cpu) (push) Has been cancelled
Build and Push Docker Images / create_manifest (backend, surfsense-backend, -cuda, cuda) (push) Has been cancelled
Build and Push Docker Images / create_manifest (backend, surfsense-backend, -cuda126, cuda126) (push) Has been cancelled
68 lines
1.7 KiB
TypeScript
68 lines
1.7 KiB
TypeScript
"use client";
|
|
|
|
import { useCallback, useEffect, useState } from "react";
|
|
|
|
const SIDEBAR_COOKIE_NAME = "sidebar_collapsed";
|
|
const SIDEBAR_COOKIE_MAX_AGE = 60 * 60 * 24 * 365; // 1 year
|
|
|
|
interface UseSidebarStateReturn {
|
|
isCollapsed: boolean;
|
|
setIsCollapsed: (collapsed: boolean) => void;
|
|
toggleCollapsed: () => void;
|
|
}
|
|
|
|
export function useSidebarState(defaultCollapsed = false): UseSidebarStateReturn {
|
|
const [isCollapsed, setIsCollapsedState] = useState(defaultCollapsed);
|
|
|
|
// Initialize from cookie on mount
|
|
useEffect(() => {
|
|
try {
|
|
const match = document.cookie.match(/(?:^|; )sidebar_collapsed=([^;]+)/);
|
|
if (match) {
|
|
setIsCollapsedState(match[1] === "true");
|
|
}
|
|
} catch {
|
|
// Ignore cookie read errors
|
|
}
|
|
}, []);
|
|
|
|
// Persist to cookie when state changes
|
|
const setIsCollapsed = useCallback((collapsed: boolean) => {
|
|
setIsCollapsedState(collapsed);
|
|
try {
|
|
document.cookie = `${SIDEBAR_COOKIE_NAME}=${collapsed}; path=/; max-age=${SIDEBAR_COOKIE_MAX_AGE}`;
|
|
} catch {
|
|
// Ignore cookie write errors
|
|
}
|
|
}, []);
|
|
|
|
const toggleCollapsed = useCallback(() => {
|
|
setIsCollapsedState((prev) => {
|
|
const next = !prev;
|
|
try {
|
|
document.cookie = `${SIDEBAR_COOKIE_NAME}=${next}; path=/; max-age=${SIDEBAR_COOKIE_MAX_AGE}`;
|
|
} catch {}
|
|
return next;
|
|
});
|
|
}, []);
|
|
|
|
// Keyboard shortcut: Cmd/Ctrl + \
|
|
useEffect(() => {
|
|
const handleKeyDown = (event: KeyboardEvent) => {
|
|
if (event.key === "\\" && (event.metaKey || event.ctrlKey)) {
|
|
event.preventDefault();
|
|
toggleCollapsed();
|
|
}
|
|
};
|
|
|
|
window.addEventListener("keydown", handleKeyDown);
|
|
return () => window.removeEventListener("keydown", handleKeyDown);
|
|
}, [toggleCollapsed]);
|
|
|
|
return {
|
|
isCollapsed,
|
|
setIsCollapsed,
|
|
toggleCollapsed,
|
|
};
|
|
}
|