mirror of
https://github.com/sqlchat/sqlchat.git
synced 2025-08-01 09:43:12 +08:00
feat: implement stores and basic chat logic
This commit is contained in:
32
components/ChatView/Sidebar.tsx
Normal file
32
components/ChatView/Sidebar.tsx
Normal file
@ -0,0 +1,32 @@
|
||||
import { useChatStore, useUserStore } from "../../store";
|
||||
import { User } from "../../types";
|
||||
|
||||
const Sidebar = () => {
|
||||
const userStore = useUserStore();
|
||||
const chatStore = useChatStore();
|
||||
|
||||
const handleAssistantClick = (user: User) => {
|
||||
for (const chat of chatStore.chatList) {
|
||||
if (chat.userId === user.id) {
|
||||
chatStore.setCurrentChat(chat);
|
||||
return;
|
||||
}
|
||||
}
|
||||
chatStore.createChat(user);
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="w-full border-r p-2">
|
||||
<h2>Assistant list</h2>
|
||||
<div>
|
||||
{userStore.assistantList.map((assistant) => (
|
||||
<p onClick={() => handleAssistantClick(assistant)} key={assistant.id}>
|
||||
{assistant.name}
|
||||
</p>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default Sidebar;
|
Reference in New Issue
Block a user