|
@@ -41,6 +41,8 @@ import chatStyle from "./chat.module.scss";
|
|
|
|
|
|
import { Input, Modal, showModal, showToast } from "./ui-lib";
|
|
import { Input, Modal, showModal, showToast } from "./ui-lib";
|
|
|
|
|
|
|
|
+import calcTextareaHeight from "../calcTextareaHeight";
|
|
|
|
+
|
|
const Markdown = dynamic(
|
|
const Markdown = dynamic(
|
|
async () => memo((await import("./markdown")).Markdown),
|
|
async () => memo((await import("./markdown")).Markdown),
|
|
{
|
|
{
|
|
@@ -331,6 +333,10 @@ function useScrollToBottom() {
|
|
export function Chat(props: {
|
|
export function Chat(props: {
|
|
showSideBar?: () => void;
|
|
showSideBar?: () => void;
|
|
sideBarShowing?: boolean;
|
|
sideBarShowing?: boolean;
|
|
|
|
+ autoSize: {
|
|
|
|
+ minRows: number;
|
|
|
|
+ maxRows?: number;
|
|
|
|
+ };
|
|
}) {
|
|
}) {
|
|
type RenderMessage = Message & { preview?: boolean };
|
|
type RenderMessage = Message & { preview?: boolean };
|
|
|
|
|
|
@@ -348,6 +354,7 @@ export function Chat(props: {
|
|
const { submitKey, shouldSubmit } = useSubmitHandler();
|
|
const { submitKey, shouldSubmit } = useSubmitHandler();
|
|
const { scrollRef, setAutoScroll } = useScrollToBottom();
|
|
const { scrollRef, setAutoScroll } = useScrollToBottom();
|
|
const [hitBottom, setHitBottom] = useState(false);
|
|
const [hitBottom, setHitBottom] = useState(false);
|
|
|
|
+ const [textareaStyle, setTextareaStyle] = useState({});
|
|
|
|
|
|
const onChatBodyScroll = (e: HTMLElement) => {
|
|
const onChatBodyScroll = (e: HTMLElement) => {
|
|
const isTouchBottom = e.scrollTop + e.clientHeight >= e.scrollHeight - 20;
|
|
const isTouchBottom = e.scrollTop + e.clientHeight >= e.scrollHeight - 20;
|
|
@@ -381,6 +388,14 @@ export function Chat(props: {
|
|
dom.scrollTop = dom.scrollHeight - dom.offsetHeight + paddingBottomNum;
|
|
dom.scrollTop = dom.scrollHeight - dom.offsetHeight + paddingBottomNum;
|
|
};
|
|
};
|
|
|
|
|
|
|
|
+ // textarea has an adaptive height
|
|
|
|
+ const resizeTextarea = () => {
|
|
|
|
+ const dom = inputRef.current;
|
|
|
|
+ if (!dom) return;
|
|
|
|
+ const { minRows, maxRows } = props.autoSize;
|
|
|
|
+ setTextareaStyle(calcTextareaHeight(dom, minRows, maxRows));
|
|
|
|
+ };
|
|
|
|
+
|
|
// only search prompts when user input is short
|
|
// only search prompts when user input is short
|
|
const SEARCH_TEXT_LIMIT = 30;
|
|
const SEARCH_TEXT_LIMIT = 30;
|
|
const onInput = (text: string) => {
|
|
const onInput = (text: string) => {
|
|
@@ -512,6 +527,12 @@ export function Chat(props: {
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
}, []);
|
|
}, []);
|
|
|
|
|
|
|
|
+ // Textarea Adaptive height
|
|
|
|
+ useEffect(() => {
|
|
|
|
+ resizeTextarea();
|
|
|
|
+ // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
|
|
+ }, [userInput]);
|
|
|
|
+
|
|
return (
|
|
return (
|
|
<div className={styles.chat} key={session.id}>
|
|
<div className={styles.chat} key={session.id}>
|
|
<div className={styles["window-header"]}>
|
|
<div className={styles["window-header"]}>
|
|
@@ -667,8 +688,8 @@ export function Chat(props: {
|
|
<textarea
|
|
<textarea
|
|
ref={inputRef}
|
|
ref={inputRef}
|
|
className={styles["chat-input"]}
|
|
className={styles["chat-input"]}
|
|
|
|
+ style={textareaStyle}
|
|
placeholder={Locale.Chat.Input(submitKey)}
|
|
placeholder={Locale.Chat.Input(submitKey)}
|
|
- rows={2}
|
|
|
|
onInput={(e) => onInput(e.currentTarget.value)}
|
|
onInput={(e) => onInput(e.currentTarget.value)}
|
|
value={userInput}
|
|
value={userInput}
|
|
onKeyDown={onInputKeyDown}
|
|
onKeyDown={onInputKeyDown}
|