From a9523f036b02557dec79296d1b23ae0d43e570d7 Mon Sep 17 00:00:00 2001 From: cyhhao Date: Sun, 2 Apr 2023 02:26:42 +0800 Subject: [PATCH] optimize mobile experience --- app/components/home.module.scss | 14 ++++++++-- app/components/home.tsx | 46 ++++++++++++++------------------- 2 files changed, 31 insertions(+), 29 deletions(-) diff --git a/app/components/home.module.scss b/app/components/home.module.scss index 764805d80..73d453777 100644 --- a/app/components/home.module.scss +++ b/app/components/home.module.scss @@ -144,8 +144,10 @@ } } -.chat-item:hover { - background-color: var(--hover-color); +@media only screen and (min-width: 600px) { + .chat-item:hover { + background-color: var(--hover-color); + } } .chat-item-selected { @@ -170,6 +172,13 @@ opacity: 0; } +@media only screen and (max-width: 600px) { + .chat-item-delete { + right: 10px; + opacity: 0.5; + } +} + .chat-item:hover > .chat-item-delete { opacity: 0.5; right: 10px; @@ -422,6 +431,7 @@ @media only screen and (max-width: 600px) { .chat-input { font-size: 16px; + padding: 10px 5px; } } diff --git a/app/components/home.tsx b/app/components/home.tsx index de93510db..422e646b9 100644 --- a/app/components/home.tsx +++ b/app/components/home.tsx @@ -108,7 +108,7 @@ export function ChatList() { state.currentSessionIndex, state.selectSession, state.removeSession, - ] + ], ); return ( @@ -202,7 +202,7 @@ export function Chat(props: { setPromptHints(promptStore.search(text)); }, 100, - { leading: true, trailing: true } + { leading: true, trailing: true }, ); const onPromptSelect = (prompt: Prompt) => { @@ -216,7 +216,7 @@ export function Chat(props: { if (!dom) return; const paddingBottomNum: number = parseInt( window.getComputedStyle(dom).paddingBottom, - 10 + 10, ); dom.scrollTop = dom.scrollHeight - dom.offsetHeight + paddingBottomNum; }; @@ -246,7 +246,7 @@ export function Chat(props: { chatStore.onUserInput(userInput).then(() => setIsLoading(false)); setUserInput(""); setPromptHints([]); - inputRef.current?.focus(); + if (!isMobileScreen()) inputRef.current?.focus(); }; // stop response @@ -290,6 +290,7 @@ export function Chat(props: { // for auto-scroll const latestMessageRef = useRef(null); + const dialogBoxRef = useRef(null); const [autoScroll, setAutoScroll] = useState(true); // preview messages @@ -304,7 +305,7 @@ export function Chat(props: { preview: true, }, ] - : [] + : [], ) .concat( userInput.length > 0 @@ -316,7 +317,7 @@ export function Chat(props: { preview: true, }, ] - : [] + : [], ); // auto scroll @@ -324,6 +325,7 @@ export function Chat(props: { setTimeout(() => { const dom = latestMessageRef.current; const inputDom = inputRef.current; + const dialogBox = dialogBoxRef.current!; // only scroll when input overlaped message body let shouldScroll = true; @@ -334,8 +336,9 @@ export function Chat(props: { } if (dom && autoScroll && shouldScroll) { - dom.scrollIntoView({ - block: "end", + console.log(dialogBox.scrollHeight, dialogBox.clientHeight); + dialogBox.scrollTo({ + top: dialogBox.scrollHeight - dialogBox.clientHeight, }); } }, 500); @@ -354,7 +357,7 @@ export function Chat(props: { const newTopic = prompt(Locale.Chat.Rename, session.topic); if (newTopic && newTopic !== session.topic) { chatStore.updateCurrentSession( - (session) => (session.topic = newTopic!) + (session) => (session.topic = newTopic!), ); } }} @@ -397,7 +400,7 @@ export function Chat(props: { -
+
{messages.map((message, i) => { const isUser = message.role === "user"; @@ -445,8 +448,7 @@ export function Chat(props: {
)} - {(message.preview || message.content.length === 0) && - !isUser ? ( + {message.preview || message.content.length === 0 ? ( ) : (
onInput(e.currentTarget.value)} value={userInput} onKeyDown={(e) => onInputKeyDown(e as any)} onFocus={() => setAutoScroll(true)} onBlur={() => { - setAutoScroll(false); + if (!isMobileScreen()) setAutoScroll(false); setTimeout(() => setPromptHints([]), 500); }} autoFocus={!props?.sideBarShowing} /> } - text={Locale.Chat.Send} + text={isMobileScreen() ? "" : Locale.Chat.Send} className={styles["chat-input-send"] + " no-dark"} onClick={onUserSubmit} /> @@ -603,7 +605,7 @@ export function Home() { state.newSession, state.currentSessionIndex, state.removeSession, - ] + ], ); const loading = !useHasHydrated(); const [showSideBar, setShowSideBar] = useState(true); @@ -651,16 +653,6 @@ export function Home() {
-
- } - onClick={() => { - if (confirm(Locale.Home.DeleteChat)) { - removeSession(currentIndex); - } - }} - /> -
}