diff --git a/src/components/ConnectionSidebar.tsx b/src/components/ConnectionSidebar.tsx
index 9e20266..4c8eb0d 100644
--- a/src/components/ConnectionSidebar.tsx
+++ b/src/components/ConnectionSidebar.tsx
@@ -132,7 +132,7 @@ const ConnectionSidebar = () => {
};
const handleConversationSelect = (conversation: Conversation) => {
- conversationStore.setCurrentConversation(conversation);
+ conversationStore.setCurrentConversationId(conversation.id);
if (layoutStore.isMobileView) {
layoutStore.toggleSidebar(false);
}
@@ -148,8 +148,8 @@ const ConnectionSidebar = () => {
const handleDeleteConversation = (conversation: Conversation) => {
conversationStore.clearConversation((item) => item.id !== conversation.id);
- if (conversationStore.currentConversation?.id === conversation.id) {
- conversationStore.setCurrentConversation(undefined);
+ if (conversationStore.currentConversationId === conversation.id) {
+ conversationStore.setCurrentConversationId(undefined);
}
};
@@ -244,11 +244,11 @@ const ConnectionSidebar = () => {
handleConversationSelect(conversation)}
>
- {conversation.id === conversationStore.currentConversation?.id ? (
+ {conversation.id === conversationStore.currentConversationId ? (
) : (
diff --git a/src/components/ConversationView/Header.tsx b/src/components/ConversationView/Header.tsx
index d5b5f03..0793c86 100644
--- a/src/components/ConversationView/Header.tsx
+++ b/src/components/ConversationView/Header.tsx
@@ -13,8 +13,8 @@ const Header = (props: Props) => {
const layoutStore = useLayoutStore();
const conversationStore = useConversationStore();
const isDarkMode = useDarkMode();
- const currentConversation = conversationStore.currentConversation;
- const title = currentConversation?.title || "SQL Chat";
+ const currentConversationId = conversationStore.currentConversationId;
+ const title = conversationStore.getConversationById(currentConversationId)?.title || "SQL Chat";
useEffect(() => {
document.title = `${title}`;
diff --git a/src/components/ConversationView/MessageTextarea.tsx b/src/components/ConversationView/MessageTextarea.tsx
index 1aa2209..51571d8 100644
--- a/src/components/ConversationView/MessageTextarea.tsx
+++ b/src/components/ConversationView/MessageTextarea.tsx
@@ -34,7 +34,7 @@ const MessageTextarea = (props: Props) => {
};
const handleSend = async () => {
- let conversation = conversationStore.currentConversation;
+ let conversation = conversationStore.getConversationById(conversationStore.currentConversationId);
if (!conversation) {
const currentConnectionCtx = connectionStore.currentConnectionCtx;
if (!currentConnectionCtx) {
diff --git a/src/components/ConversationView/index.tsx b/src/components/ConversationView/index.tsx
index d3fa587..e8663b1 100644
--- a/src/components/ConversationView/index.tsx
+++ b/src/components/ConversationView/index.tsx
@@ -32,7 +32,7 @@ const ConversationView = () => {
const [isStickyAtBottom, setIsStickyAtBottom] = useState(true);
const [showHeaderShadow, setShowHeaderShadow] = useState(false);
const conversationViewRef = useRef(null);
- const currentConversation = conversationStore.currentConversation;
+ const currentConversation = conversationStore.getConversationById(conversationStore.currentConversationId);
const messageList = messageStore.messageList.filter((message) => message.conversationId === currentConversation?.id);
const lastMessage = last(messageList);
@@ -99,11 +99,10 @@ const ConversationView = () => {
conversation.connectionId === connectionStore.currentConnectionCtx?.connection.id &&
conversation.databaseName === connectionStore.currentConnectionCtx?.database?.name
);
- conversationStore.setCurrentConversation(head(conversationList));
+ conversationStore.setCurrentConversationId(head(conversationList)?.id);
}, [currentConversation, connectionStore.currentConnectionCtx]);
const sendMessageToCurrentConversation = async () => {
- const currentConversation = conversationStore.getState().currentConversation;
if (!currentConversation) {
return;
}
diff --git a/src/components/EmptyView.tsx b/src/components/EmptyView.tsx
index 9078698..2514101 100644
--- a/src/components/EmptyView.tsx
+++ b/src/components/EmptyView.tsx
@@ -21,7 +21,7 @@ const EmptyView = (props: Props) => {
const isDarkMode = useDarkMode();
const handleExampleClick = async (content: string) => {
- let conversation = conversationStore.currentConversation;
+ let conversation = conversationStore.getConversationById(conversationStore.currentConversationId);
if (!conversation) {
const currentConnectionCtx = connectionStore.currentConnectionCtx;
if (!currentConnectionCtx) {
diff --git a/src/store/conversation.ts b/src/store/conversation.ts
index feeb890..bddb71a 100644
--- a/src/store/conversation.ts
+++ b/src/store/conversation.ts
@@ -17,10 +17,10 @@ const getDefaultConversation = (): Conversation => {
interface ConversationState {
getState: () => ConversationState;
conversationList: Conversation[];
- currentConversation?: Conversation;
+ currentConversationId?: Id;
createConversation: (connectionId?: Id, databaseName?: string) => Conversation;
- setCurrentConversation: (Conversation: Conversation | undefined) => void;
- getConversationById: (conversationId: Id) => Conversation | undefined;
+ setCurrentConversationId: (conversationId: Id | undefined) => void;
+ getConversationById: (conversationId: Id | undefined) => Conversation | undefined;
updateConversation: (conversationId: Id, conversation: Partial) => void;
clearConversation: (filter: (conversation: Conversation) => boolean) => void;
}
@@ -45,8 +45,8 @@ export const useConversationStore = create()(
}));
return conversation;
},
- setCurrentConversation: (conversation: Conversation | undefined) => set(() => ({ currentConversation: conversation })),
- getConversationById: (conversationId: Id) => {
+ setCurrentConversationId: (conversation: Id | undefined) => set(() => ({ currentConversationId: conversation })),
+ getConversationById: (conversationId: Id | undefined) => {
return get().conversationList.find((item) => item.id === conversationId);
},
updateConversation: (conversationId: Id, conversation: Partial) => {
@@ -75,7 +75,7 @@ export const useConversationStore = create()(
conversation.assistantId = "sql-chat-bot";
}
}
- state.currentConversation = undefined;
+ state.currentConversationId = undefined;
}
return state;