Skip to content

Commit c77275a

Browse files
authored
Merge pull request #4341 from janhq/fix/stop-button-state
fix: send message button state reset on stop
2 parents 3cd4db0 + a720aff commit c77275a

File tree

4 files changed

+35
-4
lines changed

4 files changed

+35
-4
lines changed

web/helpers/atoms/Thread.atom.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,21 @@ export const updateThreadWaitingForResponseAtom = atom(
173173
}
174174
)
175175

176+
/**
177+
* Reset the thread waiting for response state
178+
*/
179+
export const resetThreadWaitingForResponseAtom = atom(null, (get, set) => {
180+
const currentState = { ...get(threadStatesAtom) }
181+
Object.keys(currentState).forEach((threadId) => {
182+
currentState[threadId] = {
183+
...currentState[threadId],
184+
waitingForResponse: false,
185+
error: undefined,
186+
}
187+
})
188+
set(threadStatesAtom, currentState)
189+
})
190+
176191
/**
177192
* Update the thread last message
178193
*/

web/hooks/useActiveModel.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ import { LAST_USED_MODEL_ID } from './useRecommendedModel'
1010
import { vulkanEnabledAtom } from '@/helpers/atoms/AppConfig.atom'
1111
import { activeAssistantAtom } from '@/helpers/atoms/Assistant.atom'
1212
import { downloadedModelsAtom } from '@/helpers/atoms/Model.atom'
13+
import {
14+
isGeneratingResponseAtom,
15+
resetThreadWaitingForResponseAtom,
16+
} from '@/helpers/atoms/Thread.atom'
1317

1418
export const activeModelAtom = atom<Model | undefined>(undefined)
1519
export const loadModelErrorAtom = atom<string | undefined>(undefined)
@@ -34,6 +38,10 @@ export function useActiveModel() {
3438
const pendingModelLoad = useRef(false)
3539
const isVulkanEnabled = useAtomValue(vulkanEnabledAtom)
3640
const activeAssistant = useAtomValue(activeAssistantAtom)
41+
const setGeneratingResponse = useSetAtom(isGeneratingResponseAtom)
42+
const resetThreadWaitingForResponseState = useSetAtom(
43+
resetThreadWaitingForResponseAtom
44+
)
3745

3846
const downloadedModelsRef = useRef<Model[]>([])
3947

@@ -139,6 +147,8 @@ export function useActiveModel() {
139147
return
140148

141149
const engine = EngineManager.instance().get(stoppingModel.engine)
150+
setGeneratingResponse(false)
151+
resetThreadWaitingForResponseState()
142152
return engine
143153
?.unloadModel(stoppingModel)
144154
.catch((e) => console.error(e))
@@ -148,7 +158,14 @@ export function useActiveModel() {
148158
pendingModelLoad.current = false
149159
})
150160
},
151-
[activeModel, setStateModel, setActiveModel, stateModel]
161+
[
162+
activeModel,
163+
setStateModel,
164+
setActiveModel,
165+
stateModel,
166+
setGeneratingResponse,
167+
resetThreadWaitingForResponseState,
168+
]
152169
)
153170

154171
const stopInference = useCallback(async () => {

web/hooks/useDeleteThread.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ export default function useDeleteThread() {
4848
if (thread) {
4949
const updatedThread = {
5050
...thread,
51+
title: 'New Thread',
5152
metadata: {
5253
...thread.metadata,
5354
title: 'New Thread',

web/screens/Thread/ThreadCenterPanel/ChatInput/index.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -302,9 +302,7 @@ const ChatInput = () => {
302302
</div>
303303
)}
304304

305-
{messages[messages.length - 1]?.status !== MessageStatus.Pending &&
306-
!isGeneratingResponse &&
307-
!isStreamingResponse ? (
305+
{!isGeneratingResponse && !isStreamingResponse ? (
308306
<>
309307
{currentPrompt.length !== 0 && (
310308
<Button

0 commit comments

Comments
 (0)