+
-
- {chatTitle}
-
+
+
+ {assistant.name}
+
+ {assistant.description}
+
+
+
);
};
diff --git a/components/ChatView/MessageTextarea.tsx b/components/ChatView/MessageTextarea.tsx
index 5cd13ef..f40e230 100644
--- a/components/ChatView/MessageTextarea.tsx
+++ b/components/ChatView/MessageTextarea.tsx
@@ -38,22 +38,15 @@ const MessageTextarea = (props: Props) => {
return;
}
- const currentChat = chatStore.currentChat;
- if (currentChat.isRequesting) {
- toast.error("Please wait for the previous message to be sent.");
- return;
- }
-
messageStore.addMessage({
id: generateUUID(),
- chatId: currentChat.id,
+ chatId: chatStore.currentChat.id,
creatorId: userStore.currentUser.id,
createdAt: Date.now(),
content: value,
});
setValue("");
textareaRef.current!.value = "";
-
await sendMessage();
};
diff --git a/components/ChatView/index.tsx b/components/ChatView/index.tsx
index bf5a0e8..617bec8 100644
--- a/components/ChatView/index.tsx
+++ b/components/ChatView/index.tsx
@@ -14,6 +14,7 @@ const ChatView = () => {
const messageStore = useMessageStore();
const [messageList, setMessageList] = useState
([]);
const [currentChat, setCurrentChat] = useState(null);
+ const [isRequesting, setIsRequesting] = useState(false);
const chatViewRef = useRef(null);
useEffect(() => {
@@ -32,20 +33,17 @@ const ChatView = () => {
return;
}
chatViewRef.current.scrollTop = chatViewRef.current.scrollHeight;
- }, [currentChat, currentChat?.isRequesting]);
+ }, [currentChat, isRequesting]);
const sendMessageToCurrentChat = async () => {
if (!currentChat || !chatViewRef.current) {
return;
}
- if (currentChat.isRequesting) {
+ if (isRequesting) {
return;
}
- chatStore.setCurrentChat({
- ...currentChat,
- isRequesting: true,
- });
+ setIsRequesting(true);
const messageList = messageStore.getState().messageList.filter((message) => message.chatId === currentChat.id);
const { data } = await axios.post("/api/chat", {
messages: messageList.map((message) => ({
@@ -60,21 +58,18 @@ const ChatView = () => {
createdAt: Date.now(),
content: data,
});
- chatStore.setCurrentChat({
- ...currentChat,
- isRequesting: false,
- });
+ setIsRequesting(false);
};
return (
{messageList.length === 0 ? <>> : messageList.map((message) =>
)}
- {currentChat?.isRequesting && (
+ {isRequesting && (
Loading...
diff --git a/pages/chat.tsx b/pages/chat.tsx
index 4ee81d3..16e7f65 100644
--- a/pages/chat.tsx
+++ b/pages/chat.tsx
@@ -12,8 +12,8 @@ const ChatPage: NextPage = () => {
-
-
+
+
diff --git a/store/user.ts b/store/user.ts
index 811afe3..c5e734e 100644
--- a/store/user.ts
+++ b/store/user.ts
@@ -4,8 +4,8 @@ import { Id, User, UserRole } from "../types";
export const assistantList: User[] = [
{
id: "assistant-dba",
- name: "Chat DBA",
- description: "",
+ name: "ChatDBA",
+ description: "🤖️ I am a chatbot that can help you with database administration.",
avatar: "",
role: UserRole.Assistant,
},
diff --git a/types/chat.ts b/types/chat.ts
index 7b47795..05d8581 100644
--- a/types/chat.ts
+++ b/types/chat.ts
@@ -3,5 +3,4 @@ import { Id } from "./common";
export interface Chat {
id: string;
assistantId: Id;
- isRequesting: boolean;
}