mirror of
https://github.com/sqlchat/sqlchat.git
synced 2025-07-28 09:43:06 +08:00
* fix the change assistant didn't take effect immediately #45 * Update src/store/conversation.ts Co-authored-by: boojack <stevenlgtm@gmail.com> * change method name * change method name * fix the call method --------- Co-authored-by: boojack <stevenlgtm@gmail.com>
This commit is contained in:
@ -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 = () => {
|
||||
<div
|
||||
key={conversation.id}
|
||||
className={`w-full mt-2 first:mt-4 py-3 pl-4 pr-2 rounded-lg flex flex-row justify-start items-center cursor-pointer dark:text-gray-300 border border-transparent group hover:bg-white dark:hover:bg-zinc-800 ${
|
||||
conversation.id === conversationStore.currentConversation?.id && "bg-white dark:bg-zinc-800 border-gray-200 font-medium"
|
||||
conversation.id === conversationStore.currentConversationId && "bg-white dark:bg-zinc-800 border-gray-200 font-medium"
|
||||
}`}
|
||||
onClick={() => handleConversationSelect(conversation)}
|
||||
>
|
||||
{conversation.id === conversationStore.currentConversation?.id ? (
|
||||
{conversation.id === conversationStore.currentConversationId ? (
|
||||
<Icon.IoChatbubble className="w-5 h-auto mr-1.5 shrink-0" />
|
||||
) : (
|
||||
<Icon.IoChatbubbleOutline className="w-5 h-auto mr-1.5 opacity-80 shrink-0" />
|
||||
|
@ -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}`;
|
||||
|
@ -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) {
|
||||
|
@ -32,7 +32,7 @@ const ConversationView = () => {
|
||||
const [isStickyAtBottom, setIsStickyAtBottom] = useState<boolean>(true);
|
||||
const [showHeaderShadow, setShowHeaderShadow] = useState<boolean>(false);
|
||||
const conversationViewRef = useRef<HTMLDivElement>(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;
|
||||
}
|
||||
|
@ -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) {
|
||||
|
@ -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<Conversation>) => void;
|
||||
clearConversation: (filter: (conversation: Conversation) => boolean) => void;
|
||||
}
|
||||
@ -45,8 +45,8 @@ export const useConversationStore = create<ConversationState>()(
|
||||
}));
|
||||
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<Conversation>) => {
|
||||
@ -75,7 +75,7 @@ export const useConversationStore = create<ConversationState>()(
|
||||
conversation.assistantId = "sql-chat-bot";
|
||||
}
|
||||
}
|
||||
state.currentConversation = undefined;
|
||||
state.currentConversationId = undefined;
|
||||
}
|
||||
|
||||
return state;
|
||||
|
Reference in New Issue
Block a user