diff --git a/app/components/chat.tsx b/app/components/chat.tsx index 90c88d97b..5512a0f5e 100644 --- a/app/components/chat.tsx +++ b/app/components/chat.tsx @@ -20,6 +20,7 @@ import { ROLES, createMessage, } from "../store"; +import { useScreen } from "../store/screen"; import { copyToClipboard, @@ -348,6 +349,8 @@ export function Chat(props: { const { scrollRef, setAutoScroll } = useScrollToBottom(); const [hitBottom, setHitBottom] = useState(false); + const isMobile = useScreen(screen => screen.isMobile); + const onChatBodyScroll = (e: HTMLElement) => { const isTouchBottom = e.scrollTop + e.clientHeight >= e.scrollHeight - 20; setHitBottom(isTouchBottom); @@ -409,7 +412,7 @@ export function Chat(props: { chatStore.onUserInput(userInput).then(() => setIsLoading(false)); setUserInput(""); setPromptHints([]); - if (!isMobileScreen()) inputRef.current?.focus(); + if (!isMobile) inputRef.current?.focus(); setAutoScroll(true); }; @@ -499,7 +502,7 @@ export function Chat(props: { // Auto focus useEffect(() => { - if (props.sideBarShowing && isMobileScreen()) return; + if (props.sideBarShowing && isMobile) return; inputRef.current?.focus(); // eslint-disable-next-line react-hooks/exhaustive-deps }, []); @@ -635,7 +638,7 @@ export function Chat(props: { style={{ fontSize: `${fontSize}px` }} onContextMenu={(e) => onRightClick(e, message)} onDoubleClickCapture={() => { - if (!isMobileScreen()) return; + if (!isMobile) return; setUserInput(message.content); }} > diff --git a/app/components/home.tsx b/app/components/home.tsx index 9e57cb870..56a90b2b4 100644 --- a/app/components/home.tsx +++ b/app/components/home.tsx @@ -17,7 +17,8 @@ import LoadingIcon from "../icons/three-dots.svg"; import CloseIcon from "../icons/close.svg"; import { useChatStore } from "../store"; -import { isMobileScreen } from "../utils"; +import { useScreen } from "../store/screen"; + import Locale from "../locales"; import { Chat } from "./chat"; @@ -99,6 +100,7 @@ function _Home() { // setting const [openSettings, setOpenSettings] = useState(false); const config = useChatStore((state) => state.config); + const isMobile = useScreen(screen => screen.isMobile); useSwitchTheme(); @@ -109,7 +111,7 @@ function _Home() { return (