feat: 添加关闭设置快捷键

This commit is contained in:
shuaisguo
2023-03-31 11:55:38 +08:00
parent 9eb77207fb
commit 04238de655
3 changed files with 40 additions and 20 deletions

View File

@@ -2,6 +2,7 @@
import { useState, useRef, useEffect, useLayoutEffect } from "react";
import { useDebouncedCallback } from "use-debounce";
import { useHotkeys } from "react-hotkeys-hook";
import { IconButton } from "./button";
import styles from "./home.module.scss";
@@ -102,7 +103,7 @@ export function ChatList() {
state.currentSessionIndex,
state.selectSession,
state.removeSession,
]
],
);
return (
@@ -196,7 +197,7 @@ export function Chat(props: {
setPromptHints(promptStore.search(text));
},
100,
{ leading: true, trailing: true }
{ leading: true, trailing: true },
);
const onPromptSelect = (prompt: Prompt) => {
@@ -210,7 +211,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;
};
@@ -300,7 +301,7 @@ export function Chat(props: {
preview: true,
},
]
: []
: [],
)
.concat(
userInput.length > 0
@@ -312,7 +313,7 @@ export function Chat(props: {
preview: true,
},
]
: []
: [],
);
// auto scroll
@@ -340,7 +341,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!),
);
}
}}
@@ -586,7 +587,7 @@ export function Home() {
state.newSession,
state.currentSessionIndex,
state.removeSession,
]
],
);
const loading = !useHasHydrated();
const [showSideBar, setShowSideBar] = useState(true);
@@ -597,6 +598,19 @@ export function Home() {
useSwitchTheme();
useHotkeys(
"esc",
() => {
if (openSettings) {
setOpenSettings(false);
}
},
{
enableOnFormTags: ["input", "select", "textarea"],
},
[openSettings],
);
if (loading) {
return <Loading />;
}