Skip to content

Commit

Permalink
fix(Thread): #1119 focus on the first thread to prevent blank chat sc…
Browse files Browse the repository at this point in the history
…reen

Signed-off-by: James <[email protected]>
  • Loading branch information
James committed Dec 20, 2023
1 parent 2fb7bfc commit ad5adae
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
10 changes: 7 additions & 3 deletions web/hooks/useSetActiveThread.ts
Original file line number Diff line number Diff line change
@@ -1,6 1,10 @@
import { EventName, ExtensionType, Thread, events } from '@janhq/core'

import { ConversationalExtension } from '@janhq/core'
import {
EventName,
ExtensionType,
Thread,
events,
ConversationalExtension,
} from '@janhq/core'

import { useAtomValue, useSetAtom } from 'jotai'

Expand Down
11 changes: 9 additions & 2 deletions web/hooks/useThreads.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 3,13 @@ import {
ModelRuntimeParams,
Thread,
ThreadState,
ConversationalExtension,
} from '@janhq/core'
import { ConversationalExtension } from '@janhq/core'

import { useAtom } from 'jotai'

import useSetActiveThread from './useSetActiveThread'

import { extensionManager } from '@/extension/ExtensionManager'
import {
threadModelRuntimeParamsAtom,
Expand All @@ -20,6 23,7 @@ const useThreads = () => {
const [threadModelRuntimeParams, setThreadModelRuntimeParams] = useAtom(
threadModelRuntimeParamsAtom
)
const { setActiveThread } = useSetActiveThread()

const getThreads = async () => {
try {
Expand Down Expand Up @@ -77,13 81,16 @@ const useThreads = () => {
setThreadStates(localThreadStates)
setThreads(allThreads)
setThreadModelRuntimeParams(threadModelParams)
if (allThreads.length > 0) {
setActiveThread(allThreads[0])
}
} catch (error) {
console.error(error)
}
}

return {
getAllThreads: getThreads,
getThreads,
}
}

Expand Down
4 changes: 2 additions & 2 deletions web/screens/Chat/ThreadList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 42,7 @@ import {
export default function ThreadList() {
const threads = useAtomValue(threadsAtom)
const threadStates = useAtomValue(threadStatesAtom)
const { getAllThreads } = useThreads()
const { getThreads } = useThreads()
const { assistants } = useGetAssistants()
const { requestCreateNewThread } = useCreateNewThread()
const activeThread = useAtomValue(activeThreadAtom)
Expand All @@ -53,7 53,7 @@ export default function ThreadList() {
useSetActiveThread()

useEffect(() => {
getAllThreads()
getThreads()
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [])

Expand Down

0 comments on commit ad5adae

Please sign in to comment.