fix(nav): restore sidebar collapse state from cookie; cmd+k search shows tools only while typing; mobile header search
Build & Push Docker Image / build (push) Successful in 3m22s
Build & Push Docker Image / build (push) Successful in 3m22s
This commit is contained in:
@@ -53,6 +53,15 @@ function useSidebar() {
|
||||
return context
|
||||
}
|
||||
|
||||
function getSidebarCookie(): boolean | null {
|
||||
if (typeof document === "undefined") return null;
|
||||
const match = document.cookie.match(
|
||||
new RegExp(`(?:^|; )${SIDEBAR_COOKIE_NAME}=([^;]*)`)
|
||||
);
|
||||
if (!match) return null;
|
||||
return match[1] === "true";
|
||||
}
|
||||
|
||||
function SidebarProvider({
|
||||
defaultOpen = true,
|
||||
open: openProp,
|
||||
@@ -71,7 +80,10 @@ function SidebarProvider({
|
||||
|
||||
// This is the internal state of the sidebar.
|
||||
// We use openProp and setOpenProp for control from outside the component.
|
||||
const [_open, _setOpen] = React.useState(defaultOpen)
|
||||
const [_open, _setOpen] = React.useState(() => {
|
||||
const stored = getSidebarCookie()
|
||||
return stored !== null ? stored : defaultOpen
|
||||
})
|
||||
const open = openProp ?? _open
|
||||
const setOpen = React.useCallback(
|
||||
(value: boolean | ((value: boolean) => boolean)) => {
|
||||
|
||||
Reference in New Issue
Block a user