chore: update bot avatar (#8)

This commit is contained in:
boojack
2023-03-29 15:06:32 +08:00
committed by GitHub
parent f3073a1f15
commit a2e4866d65
4 changed files with 31 additions and 9 deletions

View File

@ -3,10 +3,11 @@ import { ReactElement, useState } from "react";
import { toast } from "react-hot-toast"; import { toast } from "react-hot-toast";
import ReactMarkdown from "react-markdown"; import ReactMarkdown from "react-markdown";
import remarkGfm from "remark-gfm"; import remarkGfm from "remark-gfm";
import { useMessageStore, useUserStore } from "@/store"; import { useChatStore, useConnectionStore, useMessageStore, useUserStore } from "@/store";
import { Message } from "@/types"; import { Message } from "@/types";
import Icon from "../Icon"; import Icon from "../Icon";
import { CodeBlock } from "../CodeBlock"; import { CodeBlock } from "../CodeBlock";
import EngineIcon from "../EngineIcon";
interface Props { interface Props {
message: Message; message: Message;
@ -15,10 +16,13 @@ interface Props {
const MessageView = (props: Props) => { const MessageView = (props: Props) => {
const message = props.message; const message = props.message;
const userStore = useUserStore(); const userStore = useUserStore();
const chatStore = useChatStore();
const connectionStore = useConnectionStore();
const messageStore = useMessageStore(); const messageStore = useMessageStore();
const [menuAnchorEl, setMenuAnchorEl] = useState<HTMLButtonElement | null>(null); const [menuAnchorEl, setMenuAnchorEl] = useState<HTMLButtonElement | null>(null);
const isCurrentUser = message.creatorId === userStore.currentUser.id; const isCurrentUser = message.creatorId === userStore.currentUser.id;
const showMenu = Boolean(menuAnchorEl); const showMenu = Boolean(menuAnchorEl);
const connection = connectionStore.getConnectionById(chatStore.getChatById(message.chatId)?.connectionId || "");
const handleMoreMenuClick = (event: React.MouseEvent<HTMLButtonElement>) => { const handleMoreMenuClick = (event: React.MouseEvent<HTMLButtonElement>) => {
if (menuAnchorEl) { if (menuAnchorEl) {
@ -47,17 +51,19 @@ const MessageView = (props: Props) => {
> >
{isCurrentUser ? ( {isCurrentUser ? (
<> <>
<div className="w-auto max-w-full bg-indigo-600 text-white px-4 py-2 rounded-lg whitespace-pre-wrap"> <div className="w-auto max-w-full bg-indigo-600 text-white px-4 py-2 rounded-lg whitespace-pre-wrap">{message.content}</div>
{message.content}
</div>
<div className="w-10 h-10 p-1 border rounded-full flex justify-center items-center ml-2 shrink-0"> <div className="w-10 h-10 p-1 border rounded-full flex justify-center items-center ml-2 shrink-0">
<Icon.AiOutlineUser className="w-6 h-6" /> <Icon.AiOutlineUser className="w-6 h-6" />
</div> </div>
</> </>
) : ( ) : (
<> <>
<div className="w-10 h-10 p-1 flex justify-center items-center mr-2 shrink-0"> <div className="flex justify-center items-center mr-2 shrink-0">
<img src="/chat-logo-bot.webp" alt="" /> {connection ? (
<EngineIcon className="w-10 h-auto p-1 border rounded-full" engine={connection.engineType} />
) : (
<img className="w-10 h-auto p-1" src="/chat-logo-bot.webp" alt="" />
)}
</div> </div>
<ReactMarkdown <ReactMarkdown
className="w-auto max-w-[calc(100%-4rem)] bg-gray-100 px-4 py-2 rounded-lg prose prose-neutral" className="w-auto max-w-[calc(100%-4rem)] bg-gray-100 px-4 py-2 rounded-lg prose prose-neutral"

View File

@ -1,11 +1,19 @@
import { ThreeDots } from "react-loader-spinner"; import { ThreeDots } from "react-loader-spinner";
import Icon from "./Icon"; import { useConnectionStore } from "@/store";
import EngineIcon from "./EngineIcon";
const MessageLoader = () => { const MessageLoader = () => {
const connectionStore = useConnectionStore();
const connection = connectionStore.currentConnectionCtx?.connection;
return ( return (
<div className={`w-full max-w-full flex flex-row justify-start items-start my-4 pr-8 sm:pr-24`}> <div className={`w-full max-w-full flex flex-row justify-start items-start my-4 pr-8 sm:pr-24`}>
<div className="w-10 h-10 p-1 flex justify-center items-center mr-2 shrink-0"> <div className="flex justify-center items-center mr-2 shrink-0">
<img src="/chat-logo-bot.webp" alt="" /> {connection ? (
<EngineIcon className="w-10 h-auto p-1 border rounded-full" engine={connection.engineType} />
) : (
<img className="w-10 h-auto p-1" src="/chat-logo-bot.webp" alt="" />
)}
</div> </div>
<div className="mt-0.5 w-12 bg-gray-100 px-4 py-2 rounded-lg"> <div className="mt-0.5 w-12 bg-gray-100 px-4 py-2 rounded-lg">
<ThreeDots wrapperClass="opacity-80" width="24" height="24" color="" /> <ThreeDots wrapperClass="opacity-80" width="24" height="24" color="" />

View File

@ -19,6 +19,7 @@ interface ChatState {
getState: () => ChatState; getState: () => ChatState;
createChat: (connectionId?: Id, databaseName?: string) => Chat; createChat: (connectionId?: Id, databaseName?: string) => Chat;
setCurrentChat: (chat: Chat | undefined) => void; setCurrentChat: (chat: Chat | undefined) => void;
getChatById: (chatId: Id) => Chat | undefined;
updateChat: (chatId: Id, chat: Partial<Chat>) => void; updateChat: (chatId: Id, chat: Partial<Chat>) => void;
clearChat: (filter: (chat: Chat) => boolean) => void; clearChat: (filter: (chat: Chat) => boolean) => void;
} }
@ -41,6 +42,9 @@ export const useChatStore = create<ChatState>()(
return chat; return chat;
}, },
setCurrentChat: (chat: Chat | undefined) => set(() => ({ currentChat: chat })), setCurrentChat: (chat: Chat | undefined) => set(() => ({ currentChat: chat })),
getChatById: (chatId: Id) => {
return get().chatList.find((item) => item.id === chatId);
},
updateChat: (chatId: Id, chat: Partial<Chat>) => { updateChat: (chatId: Id, chat: Partial<Chat>) => {
set((state) => ({ set((state) => ({
...state, ...state,

View File

@ -29,6 +29,7 @@ interface ConnectionState {
setCurrentConnectionCtx: (connectionCtx: ConnectionContext | undefined) => void; setCurrentConnectionCtx: (connectionCtx: ConnectionContext | undefined) => void;
getOrFetchDatabaseList: (connection: Connection, skipCache?: boolean) => Promise<Database[]>; getOrFetchDatabaseList: (connection: Connection, skipCache?: boolean) => Promise<Database[]>;
getOrFetchDatabaseSchema: (database: Database) => Promise<Table[]>; getOrFetchDatabaseSchema: (database: Database) => Promise<Table[]>;
getConnectionById: (connectionId: string) => Connection | undefined;
updateConnection: (connectionId: string, connection: Partial<Connection>) => void; updateConnection: (connectionId: string, connection: Partial<Connection>) => void;
clearConnection: (filter: (connection: Connection) => boolean) => void; clearConnection: (filter: (connection: Connection) => boolean) => void;
} }
@ -97,6 +98,9 @@ export const useConnectionStore = create<ConnectionState>()(
}); });
return data; return data;
}, },
getConnectionById: (connectionId: string) => {
return get().connectionList.find((connection) => connection.id === connectionId);
},
updateConnection: (connectionId: string, connection: Partial<Connection>) => { updateConnection: (connectionId: string, connection: Partial<Connection>) => {
set((state) => ({ set((state) => ({
...state, ...state,