mirror of
https://github.com/sqlchat/sqlchat.git
synced 2025-08-02 22:58:43 +08:00
feat: implement stores and basic chat logic
This commit is contained in:
36
store/user.ts
Normal file
36
store/user.ts
Normal file
@ -0,0 +1,36 @@
|
||||
import { create } from "zustand";
|
||||
import { Id, User, UserRole } from "../types";
|
||||
|
||||
const assistantList: User[] = [
|
||||
{
|
||||
id: "assistant-chatgpt",
|
||||
name: "Origin ChatGPT",
|
||||
description: "",
|
||||
avatar: "",
|
||||
role: UserRole.Assistant,
|
||||
},
|
||||
];
|
||||
|
||||
const localUser: User = {
|
||||
id: "local-user",
|
||||
name: "Local user",
|
||||
description: "",
|
||||
avatar: "",
|
||||
role: UserRole.User,
|
||||
};
|
||||
|
||||
interface UserState {
|
||||
// We can think assistants are special users.
|
||||
assistantList: User[];
|
||||
currentUser: User;
|
||||
getAssistantById: (id: string) => User | undefined;
|
||||
}
|
||||
|
||||
export const useUserStore = create<UserState>((set) => ({
|
||||
assistantList: assistantList,
|
||||
currentUser: localUser,
|
||||
getAssistantById: (id: Id) => {
|
||||
const user = assistantList.find((user) => user.id === id);
|
||||
return user || undefined;
|
||||
},
|
||||
}));
|
Reference in New Issue
Block a user