mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-12-05 15:44:28 +00:00
fix(webui): persist chatbot sidebar input text across route navigation
This commit is contained in:
@@ -39,9 +39,26 @@ describe('useChatbotStore', () => {
|
||||
historySessions: [],
|
||||
isStreaming: false,
|
||||
selectedAgentId: 'agent-1',
|
||||
inputText: '',
|
||||
})
|
||||
})
|
||||
|
||||
it('should persist and reset inputText', () => {
|
||||
expect(useChatbotStore.getState().inputText).toBe('')
|
||||
useChatbotStore.getState().setInputText('Draft text in progress')
|
||||
expect(useChatbotStore.getState().inputText).toBe('Draft text in progress')
|
||||
|
||||
useChatbotStore.setState({
|
||||
currentSessionId: 'sess-abc',
|
||||
messages: [{ id: 'msg-1', role: 'user', content: 'test' } as unknown as ChatMessage],
|
||||
})
|
||||
// Navigating or changing other state does not wipe inputText
|
||||
expect(useChatbotStore.getState().inputText).toBe('Draft text in progress')
|
||||
|
||||
useChatbotStore.getState().startNewSession()
|
||||
expect(useChatbotStore.getState().inputText).toBe('')
|
||||
})
|
||||
|
||||
it('should add, remove and clear assets in context', () => {
|
||||
const store = useChatbotStore.getState()
|
||||
expect(store.chatAssets).toHaveLength(0)
|
||||
|
||||
@@ -28,6 +28,8 @@ interface ChatbotState {
|
||||
setIsStreaming: (streaming: boolean) => void
|
||||
selectedAgentId: string | null
|
||||
setSelectedAgentId: (id: string | null) => void
|
||||
inputText: string
|
||||
setInputText: (text: string) => void
|
||||
|
||||
scrollTop: number
|
||||
isAtBottom: boolean
|
||||
@@ -74,6 +76,8 @@ export const useChatbotStore = create<ChatbotState>((set) => ({
|
||||
setIsStreaming: (streaming) => set({ isStreaming: streaming }),
|
||||
selectedAgentId: null,
|
||||
setSelectedAgentId: (id) => set({ selectedAgentId: id }),
|
||||
inputText: '',
|
||||
setInputText: (text) => set({ inputText: text }),
|
||||
scrollTop: 0,
|
||||
isAtBottom: true,
|
||||
setScrollState: (scrollTop, isAtBottom) => set({ scrollTop, isAtBottom }),
|
||||
@@ -147,6 +151,7 @@ export const useChatbotStore = create<ChatbotState>((set) => ({
|
||||
currentSessionId: null,
|
||||
messages: [],
|
||||
chatAssets: [],
|
||||
inputText: '',
|
||||
scrollTop: 0,
|
||||
isAtBottom: true,
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user