Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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