feat: reactive isMobileScreen

This commit is contained in:
Yidadaa
2023-04-20 23:20:25 +08:00
parent 2390da1165
commit 55281ed548
4 changed files with 34 additions and 18 deletions

View File

@@ -38,9 +38,9 @@ import {
copyToClipboard,
downloadAs,
getEmojiUrl,
isMobileScreen,
selectOrCopy,
autoGrowTextArea,
useMobileScreen,
} from "../utils";
import dynamic from "next/dynamic";
@@ -438,6 +438,7 @@ export function Chat(props: {
const { submitKey, shouldSubmit } = useSubmitHandler();
const { scrollRef, setAutoScroll, scrollToBottom } = useScrollToBottom();
const [hitBottom, setHitBottom] = useState(false);
const isMobileScreen = useMobileScreen();
const onChatBodyScroll = (e: HTMLElement) => {
const isTouchBottom = e.scrollTop + e.clientHeight >= e.scrollHeight - 20;
@@ -468,7 +469,7 @@ export function Chat(props: {
const rows = inputRef.current ? autoGrowTextArea(inputRef.current) : 1;
const inputRows = Math.min(
5,
Math.max(2 + Number(!isMobileScreen()), rows),
Math.max(2 + Number(!isMobileScreen), rows),
);
setInputRows(inputRows);
},
@@ -508,7 +509,7 @@ export function Chat(props: {
setBeforeInput(userInput);
setUserInput("");
setPromptHints([]);
if (!isMobileScreen()) inputRef.current?.focus();
if (!isMobileScreen) inputRef.current?.focus();
setAutoScroll(true);
};
@@ -640,7 +641,7 @@ export function Chat(props: {
// Auto focus
useEffect(() => {
if (props.sideBarShowing && isMobileScreen()) return;
if (props.sideBarShowing && isMobileScreen) return;
inputRef.current?.focus();
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
@@ -688,7 +689,7 @@ export function Chat(props: {
}}
/>
</div>
{!isMobileScreen() && (
{!isMobileScreen && (
<div className={styles["window-action-button"]}>
<IconButton
icon={chatStore.config.tightBorder ? <MinIcon /> : <MaxIcon />}
@@ -788,7 +789,7 @@ export function Chat(props: {
}
onContextMenu={(e) => onRightClick(e, message)}
onDoubleClickCapture={() => {
if (!isMobileScreen()) return;
if (!isMobileScreen) return;
setUserInput(message.content);
}}
fontSize={fontSize}