mirror of
https://github.com/Yidadaa/ChatGPT-Next-Web.git
synced 2025-09-16 08:27:10 +08:00
feat: generate chat suggestions for user
This commit is contained in:
@@ -475,3 +475,21 @@
|
||||
bottom: 30px;
|
||||
}
|
||||
}
|
||||
|
||||
.chat-suggestions {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
|
||||
.chat-suggestion {
|
||||
display: inline;
|
||||
white-space: nowrap;
|
||||
border-radius: 20px;
|
||||
font-size: 12px;
|
||||
background-color: var(--white);
|
||||
color: var(--black);
|
||||
border: var(--border-in-light);
|
||||
padding: 4px 10px;
|
||||
animation: slide-in ease 0.3s;
|
||||
margin-bottom: 5px;
|
||||
}
|
||||
}
|
||||
|
@@ -606,6 +606,8 @@ export function Chat() {
|
||||
}
|
||||
};
|
||||
|
||||
const [suggestions, setSuggestions] = useState<string[]>([]);
|
||||
|
||||
const doSubmit = (userInput: string) => {
|
||||
if (userInput.trim() === "") return;
|
||||
const matchCommand = chatCommands.match(userInput);
|
||||
@@ -616,7 +618,13 @@ export function Chat() {
|
||||
return;
|
||||
}
|
||||
setIsLoading(true);
|
||||
chatStore.onUserInput(userInput).then(() => setIsLoading(false));
|
||||
setSuggestions([]);
|
||||
chatStore.onUserInput(userInput).then(() => {
|
||||
setIsLoading(false);
|
||||
chatStore
|
||||
.getSuggestions()
|
||||
.then((suggestions) => setSuggestions(suggestions));
|
||||
});
|
||||
localStorage.setItem(LAST_INPUT_KEY, userInput);
|
||||
setUserInput("");
|
||||
setPromptHints([]);
|
||||
@@ -1061,6 +1069,25 @@ export function Chat() {
|
||||
onSearch("");
|
||||
}}
|
||||
/>
|
||||
|
||||
{suggestions.length > 0 && (
|
||||
<div className={styles["chat-suggestions"]}>
|
||||
{suggestions.map((s, i) => {
|
||||
return (
|
||||
<div
|
||||
key={i}
|
||||
className={styles["chat-suggestion"] + " clickable"}
|
||||
onClick={() => {
|
||||
doSubmit(s);
|
||||
}}
|
||||
>
|
||||
{s}
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className={styles["chat-input-panel-inner"]}>
|
||||
<textarea
|
||||
ref={inputRef}
|
||||
|
@@ -28,6 +28,7 @@ import { useAppConfig } from "../store/config";
|
||||
import { AuthPage } from "./auth";
|
||||
import { getClientConfig } from "../config/client";
|
||||
import { api } from "../client/api";
|
||||
import { useChatStore } from "../store";
|
||||
|
||||
export function Loading(props: { noLogo?: boolean }) {
|
||||
return (
|
||||
@@ -114,6 +115,7 @@ function Screen() {
|
||||
const isHome = location.pathname === Path.Home;
|
||||
const isAuth = location.pathname === Path.Auth;
|
||||
const isMobileScreen = useMobileScreen();
|
||||
const chat = useChatStore();
|
||||
|
||||
useEffect(() => {
|
||||
loadAsyncGoogleFont();
|
||||
|
Reference in New Issue
Block a user