This commit is contained in:
GH Action - Upstream Sync
2023-04-07 06:22:17 +00:00
6 changed files with 170 additions and 6 deletions

View File

@@ -344,6 +344,7 @@ export function Chat(props: {
const inputRef = useRef<HTMLTextAreaElement>(null);
const [userInput, setUserInput] = useState("");
const [beforeInput, setBeforeInput] = useState("");
const [isLoading, setIsLoading] = useState(false);
const { submitKey, shouldSubmit } = useSubmitHandler();
const { scrollRef, setAutoScroll } = useScrollToBottom();
@@ -408,6 +409,7 @@ export function Chat(props: {
if (userInput.length <= 0) return;
setIsLoading(true);
chatStore.onUserInput(userInput).then(() => setIsLoading(false));
setBeforeInput(userInput);
setUserInput("");
setPromptHints([]);
if (!isMobileScreen()) inputRef.current?.focus();
@@ -421,6 +423,12 @@ export function Chat(props: {
// check if should send message
const onInputKeyDown = (e: React.KeyboardEvent<HTMLTextAreaElement>) => {
// if ArrowUp and no userInput
if (e.key === "ArrowUp" && userInput.length <= 0) {
setUserInput(beforeInput);
e.preventDefault();
return;
}
if (shouldSubmit(e)) {
onUserSubmit();
e.preventDefault();

View File

@@ -184,6 +184,7 @@
right: -20px;
transition: all ease 0.3s;
opacity: 0;
cursor: pointer;
}
.chat-item:hover>.chat-item-delete {

View File

@@ -128,6 +128,19 @@ export function Settings(props: { closeSettings: () => void }) {
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
useEffect(() => {
const keydownEvent = (e: KeyboardEvent) => {
if (e.key === "Escape") {
props.closeSettings();
}
};
document.addEventListener("keydown", keydownEvent);
return () => {
document.removeEventListener("keydown", keydownEvent);
};
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
return (
<ErrorBoundary>
<div className={styles["window-header"]}>

View File

@@ -9,6 +9,7 @@ export function trimTopic(topic: string) {
export async function copyToClipboard(text: string) {
try {
await navigator.clipboard.writeText(text);
showToast(Locale.Copy.Success);
} catch (error) {
const textArea = document.createElement("textarea");
textArea.value = text;
@@ -17,11 +18,11 @@ export async function copyToClipboard(text: string) {
textArea.select();
try {
document.execCommand("copy");
showToast(Locale.Copy.Success);
} catch (error) {
showToast(Locale.Copy.Failed);
}
} finally {
showToast(Locale.Copy.Success);
document.body.removeChild(textArea);
}
}