diff --git a/components/ChatView/index.tsx b/components/ChatView/index.tsx index 43f86d3..a4d3fbc 100644 --- a/components/ChatView/index.tsx +++ b/components/ChatView/index.tsx @@ -1,3 +1,4 @@ +import { head } from "lodash-es"; import { useEffect, useRef, useState } from "react"; import { toast } from "react-hot-toast"; import { getAssistantById, getPromptGeneratorOfAssistant, useChatStore, useMessageStore, useConnectionStore } from "@/store"; @@ -27,6 +28,17 @@ const ChatView = () => { }); }, [currentChat, isRequesting]); + useEffect(() => { + if (!connectionStore.currentConnectionCtx) { + return; + } + if (currentChat?.connectionId === connectionStore.currentConnectionCtx.connection.id) { + return; + } + const chatList = chatStore.chatList.filter((chat) => chat.connectionId === connectionStore.currentConnectionCtx?.connection.id); + chatStore.setCurrentChat(head(chatList)); + }, [connectionStore.currentConnectionCtx]); + const sendMessageToCurrentChat = async () => { if (!currentChat || !chatViewRef.current) { return; @@ -101,7 +113,11 @@ const ChatView = () => {
- {messageList.length === 0 ? : messageList.map((message) => )} + {messageList.length === 0 ? ( + + ) : ( + messageList.map((message) => ) + )} {isRequesting && (
Requesting... diff --git a/components/ClearDataConfirmModal.tsx b/components/ClearDataConfirmModal.tsx new file mode 100644 index 0000000..4b163bb --- /dev/null +++ b/components/ClearDataConfirmModal.tsx @@ -0,0 +1,42 @@ +import { toast } from "react-hot-toast"; +import Icon from "./Icon"; + +interface Props { + close: () => void; +} + +const ClearDataConfirmModal = (props: Props) => { + const { close } = props; + + const handleClearData = () => { + window.localStorage.clear(); + toast.success("Message cleared. The page will be reloaded."); + setTimeout(() => { + window.location.reload(); + }, 1500); + }; + + return ( +
+
+

Clear all data

+ +
+

SQLChat saves all of your data in localstorage. Please be sure to clear data.

+
+
+ + +
+
+
+ ); +}; + +export default ClearDataConfirmModal; diff --git a/components/ConnectionSidebar.tsx b/components/ConnectionSidebar.tsx index 1f2bb6e..f0bdfb5 100644 --- a/components/ConnectionSidebar.tsx +++ b/components/ConnectionSidebar.tsx @@ -6,9 +6,11 @@ import { Connection } from "@/types"; import Icon from "./Icon"; import EngineIcon from "./EngineIcon"; import CreateConnectionModal from "./CreateConnectionModal"; +import SettingModal from "./SettingModal"; interface State { showCreateConnectionModal: boolean; + showSettingModal: boolean; } const ConnectionSidebar = () => { @@ -16,6 +18,7 @@ const ConnectionSidebar = () => { const chatStore = useChatStore(); const [state, setState] = useState({ showCreateConnectionModal: false, + showSettingModal: false, }); const connectionList = connectionStore.connectionList; const currentConnectionCtx = connectionStore.currentConnectionCtx; @@ -24,12 +27,6 @@ const ConnectionSidebar = () => { (chat) => chat.connectionId === currentConnectionCtx?.connection.id && chat.databaseName === currentConnectionCtx?.database?.name ); - useEffect(() => { - if (connectionList.length > 0) { - handleConnectionSelect(connectionList[0]); - } - }, []); - const toggleCreateConnectionModal = (show = true) => { setState({ ...state, @@ -37,6 +34,13 @@ const ConnectionSidebar = () => { }); }; + const toggleSettingModal = (show = true) => { + setState({ + ...state, + showSettingModal: show, + }); + }; + const handleConnectionSelect = async (connection: Connection) => { const databaseList = await connectionStore.getOrFetchDatabaseList(connection); connectionStore.setCurrentConnectionCtx({ @@ -86,6 +90,13 @@ const ConnectionSidebar = () => {
+ {
{databaseList.length > 0 && ( -
+

Select your database: