Skip to content

Commit

Permalink
fix: preserve focused thread when navigating in jan app
Browse files Browse the repository at this point in the history
Signed-off-by: James <[email protected]>
  • Loading branch information
James committed Jan 27, 2024
1 parent 36a8809 commit a568290
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions web/hooks/useThreads.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 5,14 @@ import {
ConversationalExtension,
} from '@janhq/core'

import { useAtom } from 'jotai'
import { useAtom, useAtomValue } from 'jotai'

import useSetActiveThread from './useSetActiveThread'

import { extensionManager } from '@/extension/ExtensionManager'
import {
ModelParams,
activeThreadAtom,
threadModelParamsAtom,
threadStatesAtom,
threadsAtom,
Expand All @@ -23,6 24,7 @@ const useThreads = () => {
const [threadModelRuntimeParams, setThreadModelRuntimeParams] = useAtom(
threadModelParamsAtom
)
const activeThread = useAtomValue(activeThreadAtom)
const { setActiveThread } = useSetActiveThread()

const getThreads = async () => {
Expand Down Expand Up @@ -84,7 86,7 @@ const useThreads = () => {
setThreadStates(localThreadStates)
setThreads(allThreads)
setThreadModelRuntimeParams(threadModelParams)
if (allThreads.length > 0) {
if (allThreads.length > 0 && !activeThread) {
setActiveThread(allThreads[0])
}
} catch (error) {
Expand Down

0 comments on commit a568290

Please sign in to comment.