-
Notifications
You must be signed in to change notification settings - Fork 5
Ask AI default new chat #1322
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Ask AI default new chat #1322
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -143,26 +143,11 @@ export function AskAiProvider({ children }: { children: ReactNode }) { | |
|
|
||
| try { | ||
| const savedSessions = localStorage.getItem(STORAGE_KEYS.chatSessions); | ||
| const savedCurrentChatId = localStorage.getItem( | ||
| STORAGE_KEYS.currentChatId, | ||
| ); | ||
|
|
||
| if (savedSessions) { | ||
| const sessions = JSON.parse(savedSessions) as ChatSession[]; | ||
| const sanitizedSessions = sanitizeChatSessions(sessions); | ||
| setChatSessions(sanitizedSessions); | ||
|
|
||
| if (savedCurrentChatId) { | ||
| const session = sanitizedSessions.find( | ||
| (s) => s.id === savedCurrentChatId, | ||
| ); | ||
| if (session) { | ||
| setCurrentChatId(savedCurrentChatId); | ||
| setMessages(session.messages); | ||
| } else { | ||
| localStorage.removeItem(STORAGE_KEYS.currentChatId); | ||
| } | ||
| } | ||
| } | ||
| } catch { | ||
| // Invalid JSON in localStorage, ignore | ||
|
|
@@ -233,9 +218,19 @@ export function AskAiProvider({ children }: { children: ReactNode }) { | |
| return sessionId; | ||
| }, []); | ||
|
|
||
| const openSidebar = useCallback(() => setIsOpen(true), []); | ||
| const openSidebar = useCallback(() => { | ||
| createNewSession(); | ||
| setIsOpen(true); | ||
| }, [createNewSession]); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. openSidebar creates new session even when already openMedium Severity
|
||
| const closeSidebar = useCallback(() => setIsOpen(false), []); | ||
| const toggleSidebar = useCallback(() => setIsOpen((prev) => !prev), []); | ||
| const toggleSidebar = useCallback(() => { | ||
| setIsOpen((prev) => { | ||
| if (!prev) { | ||
| createNewSession(); | ||
| } | ||
| return !prev; | ||
| }); | ||
| }, [createNewSession]); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Side effects inside React state updater functionMedium Severity
|
||
| const openSidebarWithPrompt = useCallback( | ||
| (prompt: string) => { | ||
| // Create new session before setting prompt to ensure each query starts fresh | ||
|
|
||


There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dead code: localStorage write with no reader remaining
Low Severity
The diff removed the code that reads
STORAGE_KEYS.currentChatIdfrom localStorage on mount, but left behind the effect that writes it (lines 168–176) and thecurrentChatIdkey inSTORAGE_KEYS. This effect now runs on every session change, writing to localStorage with no consumer ever reading the value back, making it dead code.Additional Locations (1)
components/AskAiContext.tsx#L15-L16