From c67af258d37a672235fd849800324c2df3adb198 Mon Sep 17 00:00:00 2001 From: dakai Date: Fri, 14 Apr 2023 01:34:06 +0800 Subject: [PATCH] =?UTF-8?q?=E7=94=A8=E6=88=B7=E8=BE=93=E5=85=A5=E6=A1=86?= =?UTF-8?q?=E5=86=85=E5=AE=B9=E4=BC=9A=E9=9A=8F=E7=9D=80Session=E5=88=87?= =?UTF-8?q?=E6=8D=A2=E8=80=8C=E5=88=87=E6=8D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/components/chat-list.tsx | 23 ++++++++--------------- app/components/chat.tsx | 24 +++++++++++++++++++----- app/store/app.ts | 2 ++ 3 files changed, 29 insertions(+), 20 deletions(-) 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: "", }; }