This commit is contained in:
仙 境 ᰔᩚ 2023-03-29 17:20:38 +08:00
parent 8a05f84838
commit 9ad0e9a013
3 changed files with 19233 additions and 7683 deletions

View File

@ -7,7 +7,6 @@ import { IconButton } from "./button";
import styles from "./home.module.scss"; import styles from "./home.module.scss";
import SettingsIcon from "../icons/settings.svg"; import SettingsIcon from "../icons/settings.svg";
import GithubIcon from "../icons/github.svg";
import ChatGptIcon from "../icons/chatgpt.svg"; import ChatGptIcon from "../icons/chatgpt.svg";
import SendWhiteIcon from "../icons/send-white.svg"; import SendWhiteIcon from "../icons/send-white.svg";
import BrainIcon from "../icons/brain.svg"; import BrainIcon from "../icons/brain.svg";
@ -102,7 +101,7 @@ export function ChatList() {
state.currentSessionIndex, state.currentSessionIndex,
state.selectSession, state.selectSession,
state.removeSession, state.removeSession,
] ],
); );
return ( return (
@ -170,7 +169,10 @@ export function PromptHints(props: {
); );
} }
export function Chat(props: { showSideBar?: () => void, sideBarShowing?: boolean }) { export function Chat(props: {
showSideBar?: () => void;
sideBarShowing?: boolean;
}) {
type RenderMessage = Message & { preview?: boolean }; type RenderMessage = Message & { preview?: boolean };
const chatStore = useChatStore(); const chatStore = useChatStore();
@ -194,7 +196,7 @@ export function Chat(props: { showSideBar?: () => void, sideBarShowing?: boolean
setPromptHints(promptStore.search(text)); setPromptHints(promptStore.search(text));
}, },
100, 100,
{ leading: true, trailing: true } { leading: true, trailing: true },
); );
const onPromptSelect = (prompt: Prompt) => { const onPromptSelect = (prompt: Prompt) => {
@ -280,7 +282,7 @@ export function Chat(props: { showSideBar?: () => void, sideBarShowing?: boolean
preview: true, preview: true,
}, },
] ]
: [] : [],
) )
.concat( .concat(
userInput.length > 0 userInput.length > 0
@ -292,7 +294,7 @@ export function Chat(props: { showSideBar?: () => void, sideBarShowing?: boolean
preview: true, preview: true,
}, },
] ]
: [] : [],
); );
// auto scroll // auto scroll
@ -375,32 +377,33 @@ export function Chat(props: { showSideBar?: () => void, sideBarShowing?: boolean
</div> </div>
)} )}
<div className={styles["chat-message-item"]}> <div className={styles["chat-message-item"]}>
{(!isUser && !(message.preview || message.content.length === 0)) && ( {!isUser &&
<div className={styles["chat-message-top-actions"]}> !(message.preview || message.content.length === 0) && (
{message.streaming ? ( <div className={styles["chat-message-top-actions"]}>
<div {message.streaming ? (
className={styles["chat-message-top-action"]} <div
onClick={() => onUserStop(i)} className={styles["chat-message-top-action"]}
> onClick={() => onUserStop(i)}
{Locale.Chat.Actions.Stop} >
</div> {Locale.Chat.Actions.Stop}
) : ( </div>
<div ) : (
className={styles["chat-message-top-action"]} <div
onClick={() => onResend(i)} className={styles["chat-message-top-action"]}
> onClick={() => onResend(i)}
{Locale.Chat.Actions.Retry} >
</div> {Locale.Chat.Actions.Retry}
)} </div>
)}
<div <div
className={styles["chat-message-top-action"]} className={styles["chat-message-top-action"]}
onClick={() => copyToClipboard(message.content)} onClick={() => copyToClipboard(message.content)}
> >
{Locale.Chat.Actions.Copy} {Locale.Chat.Actions.Copy}
</div>
</div> </div>
</div> )}
)}
{(message.preview || message.content.length === 0) && {(message.preview || message.content.length === 0) &&
!isUser ? ( !isUser ? (
<LoadingIcon /> <LoadingIcon />
@ -555,7 +558,7 @@ export function Home() {
state.newSession, state.newSession,
state.currentSessionIndex, state.currentSessionIndex,
state.removeSession, state.removeSession,
] ],
); );
const loading = !useHasHydrated(); const loading = !useHasHydrated();
const [showSideBar, setShowSideBar] = useState(true); const [showSideBar, setShowSideBar] = useState(true);
@ -620,11 +623,6 @@ export function Home() {
}} }}
/> />
</div> </div>
<div className={styles["sidebar-action"]}>
<a href={REPO_URL} target="_blank">
<IconButton icon={<GithubIcon />} />
</a>
</div>
</div> </div>
<div> <div>
<IconButton <IconButton
@ -648,7 +646,11 @@ export function Home() {
}} }}
/> />
) : ( ) : (
<Chat key="chat" showSideBar={() => setShowSideBar(true)} sideBarShowing={showSideBar} /> <Chat
key="chat"
showSideBar={() => setShowSideBar(true)}
sideBarShowing={showSideBar}
/>
)} )}
</div> </div>
</div> </div>

14063
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

12777
yarn.lock

File diff suppressed because it is too large Load Diff