From a35555a0d31708d95ff9694763e6bd0289480431 Mon Sep 17 00:00:00 2001 From: James Date: Sat, 27 Jan 2024 22:55:16 +0700 Subject: [PATCH 1/2] fix: preserve focused thread when navigating in jan app Signed-off-by: James --- web/hooks/useThreads.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/web/hooks/useThreads.ts b/web/hooks/useThreads.ts index b79cfea927..e0dbc846fb 100644 --- a/web/hooks/useThreads.ts +++ b/web/hooks/useThreads.ts @@ -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, @@ -23,6 +24,7 @@ const useThreads = () => { const [threadModelRuntimeParams, setThreadModelRuntimeParams] = useAtom( threadModelParamsAtom ) + const activeThread = useAtomValue(activeThreadAtom) const { setActiveThread } = useSetActiveThread() const getThreads = async () => { @@ -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) { From c10a1a7230204f6a5aec1f8095d9b93beb3dea67 Mon Sep 17 00:00:00 2001 From: NamH Date: Mon, 29 Jan 2024 13:56:36 +0700 Subject: [PATCH 2/2] Update web/hooks/useThreads.ts Co-authored-by: Louis --- web/hooks/useThreads.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/hooks/useThreads.ts b/web/hooks/useThreads.ts index e0dbc846fb..44be485fe6 100644 --- a/web/hooks/useThreads.ts +++ b/web/hooks/useThreads.ts @@ -86,7 +86,7 @@ const useThreads = () => { setThreadStates(localThreadStates) setThreads(allThreads) setThreadModelRuntimeParams(threadModelParams) - if (allThreads.length > 0 && !activeThread) { + if (allThreads.length && !activeThread) { setActiveThread(allThreads[0]) } } catch (error) {