diff --git a/app/components/chat-list.tsx b/app/components/chat-list.tsx index d2cfa73a9..f8f38a259 100644 --- a/app/components/chat-list.tsx +++ b/app/components/chat-list.tsx @@ -87,21 +87,14 @@ export function ChatItem(props: { } export function ChatList() { - const [ - sidebarCollapse, - sessions, - selectedIndex, - selectSession, - removeSession, - moveSession, - ] = useChatStore((state) => [ - state.sidebarCollapse, - state.sessions, - state.currentSessionIndex, - state.selectSession, - state.removeSession, - state.moveSession, - ]); + const [sidebarCollapse, sessions, selectedIndex, selectSession, moveSession] = + useChatStore((state) => [ + state.sidebarCollapse, + state.sessions, + state.currentSessionIndex, + state.selectSession, + state.moveSession, + ]); const chatStore = useChatStore(); const onDragEnd: OnDragEndResponder = (result: any) => { const { destination, source } = result; diff --git a/app/components/chat.tsx b/app/components/chat.tsx index 7edc47c4d..a03201846 100644 --- a/app/components/chat.tsx +++ b/app/components/chat.tsx @@ -1,4 +1,4 @@ -import { useDebounce, useDebouncedCallback } from "use-debounce"; +import { useDebouncedCallback } from "use-debounce"; import { memo, useState, useRef, useEffect, useLayoutEffect } from "react"; import SendWhiteIcon from "../icons/send-white.svg"; @@ -37,7 +37,6 @@ import { isMobileScreen, selectOrCopy, autoGrowTextArea, - getCSSVar, } from "../utils"; import dynamic from "next/dynamic"; @@ -414,7 +413,7 @@ export function Chat() { const fontSize = useChatStore((state) => state.config.fontSize); const inputRef = useRef(null); - const [userInput, setUserInput] = useState(""); + const [userInput, setUserInput] = useState(session.userInput); const [beforeInput, setBeforeInput] = useState(""); const [isLoading, setIsLoading] = useState(false); const { submitKey, shouldSubmit } = useSubmitHandler(); @@ -471,8 +470,23 @@ export function Chat() { }, ); + const updateUserInput = (text: string) => { + session.userInput = text; + }; + + useEffect(() => { + setUserInput(session.userInput); + }, [session]); + + // useEffect(() => { + // updateUserInput(userInput); + // }, [userInput]); + // eslint-disable-next-line react-hooks/exhaustive-deps - useEffect(measure, [userInput]); + useEffect(() => { + measure; + updateUserInput(userInput); + }, [userInput]); // only search prompts when user input is short const SEARCH_TEXT_LIMIT = 30; @@ -586,7 +600,7 @@ export function Chat() { : [], ) .concat( - userInput.length > 0 && config.sendPreviewBubble + userInput && userInput.length > 0 && config.sendPreviewBubble ? [ { ...createMessage({ diff --git a/app/store/app.ts b/app/store/app.ts index 14ecbf979..b1408b5e8 100644 --- a/app/store/app.ts +++ b/app/store/app.ts @@ -174,6 +174,7 @@ export interface ChatSession { stat: ChatStat; lastUpdate: string; lastSummarizeIndex: number; + userInput: string; } const DEFAULT_TOPIC = Locale.Store.DefaultTopic; @@ -199,6 +200,7 @@ function createEmptySession(): ChatSession { }, lastUpdate: createDate, lastSummarizeIndex: 0, + userInput: "", }; }