Files
sqlchat/store/user.ts
2023-03-16 21:29:34 +08:00

44 lines
933 B
TypeScript

import { create } from "zustand";
import { Id, User, UserRole } from "../types";
const assistantList: User[] = [
{
id: "assistant-chatgpt",
name: "Origin ChatGPT",
description: "",
avatar: "",
role: UserRole.Assistant,
},
{
id: "assistant-dba",
name: "Great DBA Bot",
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;
},
}));