rework issue system
This commit is contained in:
@@ -2,13 +2,17 @@ import React, { createContext, useContext, useState, useCallback, ReactNode } fr
|
||||
|
||||
export const DRAWER_WIDTH = 240;
|
||||
export const DRAWER_WIDTH_COLLAPSED = 64;
|
||||
export const CHAT_PANEL_MIN_WIDTH = 360;
|
||||
export const CHAT_PANEL_MAX_WIDTH = 720;
|
||||
|
||||
interface LayoutContextType {
|
||||
sidebarCollapsed: boolean;
|
||||
chatPanelOpen: boolean;
|
||||
chatPanelWidth: number;
|
||||
toggleSidebar: () => void;
|
||||
toggleChatPanel: () => void;
|
||||
setChatPanelOpen: (open: boolean) => void;
|
||||
setChatPanelWidth: (width: number) => void;
|
||||
}
|
||||
|
||||
const LayoutContext = createContext<LayoutContextType | undefined>(undefined);
|
||||
@@ -22,6 +26,21 @@ function getInitialCollapsed(): boolean {
|
||||
}
|
||||
}
|
||||
|
||||
function getInitialChatPanelWidth(): number {
|
||||
try {
|
||||
const stored = localStorage.getItem('chat-panel-width');
|
||||
if (stored) {
|
||||
const parsed = parseInt(stored, 10);
|
||||
if (!isNaN(parsed)) {
|
||||
return Math.min(Math.max(parsed, CHAT_PANEL_MIN_WIDTH), CHAT_PANEL_MAX_WIDTH);
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
// ignore storage errors
|
||||
}
|
||||
return CHAT_PANEL_MIN_WIDTH;
|
||||
}
|
||||
|
||||
interface LayoutProviderProps {
|
||||
children: ReactNode;
|
||||
}
|
||||
@@ -29,6 +48,7 @@ interface LayoutProviderProps {
|
||||
export const LayoutProvider: React.FC<LayoutProviderProps> = ({ children }) => {
|
||||
const [sidebarCollapsed, setSidebarCollapsed] = useState(getInitialCollapsed);
|
||||
const [chatPanelOpen, setChatPanelOpenState] = useState(false);
|
||||
const [chatPanelWidth, setChatPanelWidthState] = useState(getInitialChatPanelWidth);
|
||||
|
||||
const toggleSidebar = useCallback(() => {
|
||||
setSidebarCollapsed((prev) => {
|
||||
@@ -50,12 +70,24 @@ export const LayoutProvider: React.FC<LayoutProviderProps> = ({ children }) => {
|
||||
setChatPanelOpenState(open);
|
||||
}, []);
|
||||
|
||||
const setChatPanelWidth = useCallback((width: number) => {
|
||||
const clamped = Math.min(Math.max(width, CHAT_PANEL_MIN_WIDTH), CHAT_PANEL_MAX_WIDTH);
|
||||
setChatPanelWidthState(clamped);
|
||||
try {
|
||||
localStorage.setItem('chat-panel-width', String(clamped));
|
||||
} catch {
|
||||
// ignore storage errors
|
||||
}
|
||||
}, []);
|
||||
|
||||
const value: LayoutContextType = {
|
||||
sidebarCollapsed,
|
||||
chatPanelOpen,
|
||||
chatPanelWidth,
|
||||
toggleSidebar,
|
||||
toggleChatPanel,
|
||||
setChatPanelOpen,
|
||||
setChatPanelWidth,
|
||||
};
|
||||
|
||||
return <LayoutContext.Provider value={value}>{children}</LayoutContext.Provider>;
|
||||
@@ -68,3 +100,4 @@ export const useLayout = (): LayoutContextType => {
|
||||
}
|
||||
return context;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user