mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-05-23 19:05:16 +02:00
feat(sidebar): implement inbox sidebar with docked and floating modes, add sidebar context for state management
This commit is contained in:
parent
b3f08a7aa7
commit
f7122cd477
7 changed files with 362 additions and 146 deletions
37
surfsense_web/components/layout/hooks/SidebarContext.tsx
Normal file
37
surfsense_web/components/layout/hooks/SidebarContext.tsx
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
"use client";
|
||||
|
||||
import { createContext, useContext, type ReactNode } from "react";
|
||||
|
||||
interface SidebarContextValue {
|
||||
isCollapsed: boolean;
|
||||
setIsCollapsed: (collapsed: boolean) => void;
|
||||
toggleCollapsed: () => void;
|
||||
}
|
||||
|
||||
const SidebarContext = createContext<SidebarContextValue | null>(null);
|
||||
|
||||
interface SidebarProviderProps {
|
||||
children: ReactNode;
|
||||
value: SidebarContextValue;
|
||||
}
|
||||
|
||||
export function SidebarProvider({ children, value }: SidebarProviderProps) {
|
||||
return <SidebarContext.Provider value={value}>{children}</SidebarContext.Provider>;
|
||||
}
|
||||
|
||||
export function useSidebarContext(): SidebarContextValue {
|
||||
const context = useContext(SidebarContext);
|
||||
if (!context) {
|
||||
throw new Error("useSidebarContext must be used within a SidebarProvider");
|
||||
}
|
||||
return context;
|
||||
}
|
||||
|
||||
/**
|
||||
* Safe version that returns null if not within provider
|
||||
* Useful for components that may be rendered outside the sidebar context
|
||||
*/
|
||||
export function useSidebarContextSafe(): SidebarContextValue | null {
|
||||
return useContext(SidebarContext);
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue