Skip to content

Commit ad5adae

Browse files
author
James
committed
fix(Thread): #1119 focus on the first thread to prevent blank chat screen
Signed-off-by: James <[email protected]>
1 parent 2fb7bfc commit ad5adae

File tree

3 files changed

+18
-7
lines changed

3 files changed

+18
-7
lines changed

web/hooks/useSetActiveThread.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1-
import { EventName, ExtensionType, Thread, events } from '@janhq/core'
2-
3-
import { ConversationalExtension } from '@janhq/core'
1+
import {
2+
EventName,
3+
ExtensionType,
4+
Thread,
5+
events,
6+
ConversationalExtension,
7+
} from '@janhq/core'
48

59
import { useAtomValue, useSetAtom } from 'jotai'
610

web/hooks/useThreads.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@ import {
33
ModelRuntimeParams,
44
Thread,
55
ThreadState,
6+
ConversationalExtension,
67
} from '@janhq/core'
7-
import { ConversationalExtension } from '@janhq/core'
8+
89
import { useAtom } from 'jotai'
910

11+
import useSetActiveThread from './useSetActiveThread'
12+
1013
import { extensionManager } from '@/extension/ExtensionManager'
1114
import {
1215
threadModelRuntimeParamsAtom,
@@ -20,6 +23,7 @@ const useThreads = () => {
2023
const [threadModelRuntimeParams, setThreadModelRuntimeParams] = useAtom(
2124
threadModelRuntimeParamsAtom
2225
)
26+
const { setActiveThread } = useSetActiveThread()
2327

2428
const getThreads = async () => {
2529
try {
@@ -77,13 +81,16 @@ const useThreads = () => {
7781
setThreadStates(localThreadStates)
7882
setThreads(allThreads)
7983
setThreadModelRuntimeParams(threadModelParams)
84+
if (allThreads.length > 0) {
85+
setActiveThread(allThreads[0])
86+
}
8087
} catch (error) {
8188
console.error(error)
8289
}
8390
}
8491

8592
return {
86-
getAllThreads: getThreads,
93+
getThreads,
8794
}
8895
}
8996

web/screens/Chat/ThreadList/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ import {
4242
export default function ThreadList() {
4343
const threads = useAtomValue(threadsAtom)
4444
const threadStates = useAtomValue(threadStatesAtom)
45-
const { getAllThreads } = useThreads()
45+
const { getThreads } = useThreads()
4646
const { assistants } = useGetAssistants()
4747
const { requestCreateNewThread } = useCreateNewThread()
4848
const activeThread = useAtomValue(activeThreadAtom)
@@ -53,7 +53,7 @@ export default function ThreadList() {
5353
useSetActiveThread()
5454

5555
useEffect(() => {
56-
getAllThreads()
56+
getThreads()
5757
// eslint-disable-next-line react-hooks/exhaustive-deps
5858
}, [])
5959

0 commit comments

Comments
 (0)