Skip to content

Commit 99a1d45

Browse files
YidadaaPeterZhang-2023
authored andcommitted
feat: close ChatGPTNextWeb#2752 auto re-fill unfinished input
1 parent 7bf4b0c commit 99a1d45

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

app/components/chat.tsx

+20-1
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ import {
8080
MAX_RENDER_MSG_COUNT,
8181
Path,
8282
REQUEST_TIMEOUT_MS,
83+
UNFINISHED_INPUT,
8384
} from "../constant";
8485
import { Avatar } from "./emoji";
8586
import { ContextPrompts, MaskAvatar, MaskConfig } from "./mask";
@@ -935,7 +936,8 @@ function _Chat() {
935936

936937
const isTouchTopEdge = e.scrollTop <= edgeThreshold;
937938
const isTouchBottomEdge = bottomHeight >= e.scrollHeight - edgeThreshold;
938-
const isHitBottom = bottomHeight >= e.scrollHeight - (isMobileScreen ? 0 : 10);
939+
const isHitBottom =
940+
bottomHeight >= e.scrollHeight - (isMobileScreen ? 0 : 10);
939941

940942
const prevPageMsgIndex = msgRenderIndex - CHAT_PAGE_SIZE;
941943
const nextPageMsgIndex = msgRenderIndex + CHAT_PAGE_SIZE;
@@ -1013,6 +1015,23 @@ function _Chat() {
10131015
// edit / insert message modal
10141016
const [isEditingMessage, setIsEditingMessage] = useState(false);
10151017

1018+
// remember unfinished input
1019+
useEffect(() => {
1020+
// try to load from local storage
1021+
const key = UNFINISHED_INPUT(session.id);
1022+
const mayBeUnfinishedInput = localStorage.getItem(key);
1023+
if (mayBeUnfinishedInput && userInput.length === 0) {
1024+
setUserInput(mayBeUnfinishedInput);
1025+
localStorage.removeItem(key);
1026+
}
1027+
1028+
const dom = inputRef.current;
1029+
return () => {
1030+
localStorage.setItem(key, dom?.value ?? "");
1031+
};
1032+
// eslint-disable-next-line react-hooks/exhaustive-deps
1033+
}, []);
1034+
10161035
return (
10171036
<div className={styles.chat} key={session.id}>
10181037
<div className="window-header" data-tauri-drag-region>

app/constant.ts

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ export const NARROW_SIDEBAR_WIDTH = 100;
4444
export const ACCESS_CODE_PREFIX = "nk-";
4545

4646
export const LAST_INPUT_KEY = "last-input";
47+
export const UNFINISHED_INPUT = (id: string) => "unfinished-input-" + id;
4748

4849
export const REQUEST_TIMEOUT_MS = 60000;
4950

0 commit comments

Comments
 (0)