diff --git a/client/package.json b/client/package.json index 5fdc771e92..4d073f4300 100644 --- a/client/package.json +++ b/client/package.json @@ -39,10 +39,6 @@ "@radix-ui/react-tabs": "^1.0.3", "@tailwindcss/forms": "^0.5.3", "@tanstack/react-query": "^4.28.0", - "@types/jest": "^29.5.0", - "@types/node": "^20.2.3", - "@types/react": "^18.0.30", - "@types/react-dom": "^18.0.11", "@zattoo/use-double-click": "1.2.0", "axios": "^1.3.4", "class-variance-authority": "^0.6.0", @@ -94,10 +90,10 @@ "@testing-library/jest-dom": "^5.16.5", "@testing-library/react": "^14.0.0", "@testing-library/user-event": "^14.4.3", - "@types/jest": "^29.5.1", - "@types/node": "^18.16.13", - "@types/react": "^18.2.6", - "@types/react-dom": "^18.0.11", + "@types/jest": "^29.5.2", + "@types/node": "^20.3.0", + "@types/react": "^18.2.11", + "@types/react-dom": "^18.2.4", "@vitejs/plugin-react": "^4.0.0", "autoprefixer": "^10.4.13", "babel-jest": "^29.5.0", diff --git a/client/src/components/Nav/Settings.jsx b/client/src/components/Nav/Settings.jsx index 4e98f85733..2fbdf0dc8e 100644 --- a/client/src/components/Nav/Settings.jsx +++ b/client/src/components/Nav/Settings.jsx @@ -1,34 +1,18 @@ -import { Dialog } from '../ui/Dialog.tsx'; import * as Tabs from '@radix-ui/react-tabs'; -import { DialogContent, DialogHeader, DialogTitle } from '../ui/Dialog.tsx'; -import { useEffect, useState, useContext } from 'react'; +import { Dialog, DialogContent, DialogHeader, DialogTitle } from '../ui/Dialog.tsx'; +import { General } from './SettingsTabs/'; +import { CogIcon } from '~/components/svg'; +import { useEffect, useState } from 'react'; import { cn } from '~/utils/'; import { useClearConversationsMutation } from '~/data-provider'; -import { ThemeContext } from '~/hooks/ThemeContext'; import store from '~/store'; -import { CheckIcon } from 'lucide-react'; export default function Settings({ open, onOpenChange }) { - const { theme, setTheme } = useContext(ThemeContext); const { newConversation } = store.useConversation(); const { refreshConversations } = store.useConversations(); const clearConvosMutation = useClearConversationsMutation(); - const [isMobile, setIsMobile] = useState(false); const [confirmClear, setConfirmClear] = useState(false); - - const clearConvos = () => { - if (confirmClear) { - console.log('Clearing conversations...'); - clearConvosMutation.mutate(); - setConfirmClear(false); - } else { - setConfirmClear(true); - } - }; - - const changeTheme = (e) => { - setTheme(e.target.value); - }; + const [isMobile, setIsMobile] = useState(false); // check if mobile dynamically and update useEffect(() => { @@ -46,10 +30,10 @@ export default function Settings({ open, onOpenChange }) { useEffect(() => { if (clearConvosMutation.isSuccess) { - newConversation(); refreshConversations(); + newConversation(); } - }, [clearConvosMutation.isSuccess]); + }, [clearConvosMutation.isSuccess, newConversation, refreshConversations]); useEffect(() => { // If the user clicks in the dialog when confirmClear is true, set it to false @@ -71,7 +55,9 @@ export default function Settings({ open, onOpenChange }) { - Settings + + Settings +
- - - + General - - -
-
-
-
Theme
- -
-
-
-
-
Clear all chats
- -
-
-
-
+
diff --git a/client/src/components/Nav/SettingsTabs/General.tsx b/client/src/components/Nav/SettingsTabs/General.tsx new file mode 100644 index 0000000000..456ea1e02e --- /dev/null +++ b/client/src/components/Nav/SettingsTabs/General.tsx @@ -0,0 +1,77 @@ +import * as Tabs from '@radix-ui/react-tabs'; +import { CheckIcon } from 'lucide-react'; +import { ThemeContext } from '~/hooks/ThemeContext'; +import React, { useState, useContext, useCallback } from 'react'; +import { useClearConversationsMutation } from '~/data-provider'; + +const ThemeSelector = ({ theme, onChange }: { theme: string, onChange: (value: string) => void }) => ( +
+
Theme
+ +
+); + +const ClearChatsButton = ({ confirmClear, onClick }: { confirmClear: boolean, onClick: () => void }) => ( +
+
Clear all chats
+ +
+); + +function General() { + const { theme, setTheme } = useContext(ThemeContext); + const clearConvosMutation = useClearConversationsMutation(); + const [confirmClear, setConfirmClear] = useState(false); + + const clearConvos = useCallback(() => { + if (confirmClear) { + console.log('Clearing conversations...'); + clearConvosMutation.mutate({}); + setConfirmClear(false); + } else { + setConfirmClear(true); + } + }, [confirmClear, clearConvosMutation]); + + const changeTheme = useCallback((value: string) => { + setTheme(value); + }, [setTheme]); + + return ( + +
+
+ +
+
+ +
+
+
+ ); +} + +export default React.memo(General); diff --git a/client/src/components/Nav/SettingsTabs/index.ts b/client/src/components/Nav/SettingsTabs/index.ts new file mode 100644 index 0000000000..6ec619089a --- /dev/null +++ b/client/src/components/Nav/SettingsTabs/index.ts @@ -0,0 +1 @@ +export { default as General } from './General'; \ No newline at end of file diff --git a/client/src/components/svg/CogIcon.tsx b/client/src/components/svg/CogIcon.tsx new file mode 100644 index 0000000000..03acedc0d3 --- /dev/null +++ b/client/src/components/svg/CogIcon.tsx @@ -0,0 +1,22 @@ +import * as React from 'react' + +export default function CogIcon() { + return ( + + + + ); +} diff --git a/client/src/components/svg/index.ts b/client/src/components/svg/index.ts index ffff40dd89..c879df372b 100644 --- a/client/src/components/svg/index.ts +++ b/client/src/components/svg/index.ts @@ -1,4 +1,5 @@ export { default as Plugin } from './Plugin'; export { default as GPTIcon } from './GPTIcon'; export { default as BingIcon } from './BingIcon'; +export { default as CogIcon } from './CogIcon'; export { default as MessagesSquared } from './MessagesSquared'; \ No newline at end of file diff --git a/client/src/store/conversation.js b/client/src/store/conversation.js index 1b7e90061b..92ac7d226b 100644 --- a/client/src/store/conversation.js +++ b/client/src/store/conversation.js @@ -1,4 +1,5 @@ import endpoints from './endpoints'; +import { useCallback } from 'react'; import { atom, selector, @@ -112,7 +113,7 @@ const useConversation = () => { ); - const newConversation = (template = {}, preset) => { + const newConversation = useCallback((template = {}, preset) => { switchToConversation( { conversationId: 'new', @@ -122,7 +123,7 @@ const useConversation = () => { [], preset ); - }; + }, [switchToConversation]); const searchPlaceholderConversation = () => { switchToConversation( diff --git a/client/src/store/conversations.js b/client/src/store/conversations.js index b3399226d9..8455f09871 100644 --- a/client/src/store/conversations.js +++ b/client/src/store/conversations.js @@ -1,4 +1,5 @@ import { atom, useSetRecoilState } from 'recoil'; +import { useCallback } from 'react'; const refreshConversationsHint = atom({ key: 'refreshConversationsHint', @@ -8,7 +9,9 @@ const refreshConversationsHint = atom({ const useConversations = () => { const setRefreshConversationsHint = useSetRecoilState(refreshConversationsHint); - const refreshConversations = () => setRefreshConversationsHint((prevState) => prevState + 1); + const refreshConversations = useCallback(() => { + setRefreshConversationsHint((prevState) => prevState + 1); + }, [setRefreshConversationsHint]); return { refreshConversations }; }; diff --git a/client/tsconfig.json b/client/tsconfig.json index 3d318f6036..7d41d348e1 100644 --- a/client/tsconfig.json +++ b/client/tsconfig.json @@ -17,7 +17,7 @@ "noEmit": false, "declaration": true, "declarationDir": "./types", - "jsx": "react-jsx", + "jsx": "preserve", "baseUrl": ".", "paths": { "~/*": ["./src/*"] diff --git a/package-lock.json b/package-lock.json index 4d06f64ed6..e04b062fd7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -342,10 +342,6 @@ "@radix-ui/react-tabs": "^1.0.3", "@tailwindcss/forms": "^0.5.3", "@tanstack/react-query": "^4.28.0", - "@types/jest": "^29.5.0", - "@types/node": "^20.2.3", - "@types/react": "^18.0.30", - "@types/react-dom": "^18.0.11", "@zattoo/use-double-click": "1.2.0", "axios": "^1.3.4", "class-variance-authority": "^0.6.0", @@ -397,10 +393,10 @@ "@testing-library/jest-dom": "^5.16.5", "@testing-library/react": "^14.0.0", "@testing-library/user-event": "^14.4.3", - "@types/jest": "^29.5.1", - "@types/node": "^18.16.13", - "@types/react": "^18.2.6", - "@types/react-dom": "^18.0.11", + "@types/jest": "^29.5.2", + "@types/node": "^20.3.0", + "@types/react": "^18.2.11", + "@types/react-dom": "^18.2.4", "@vitejs/plugin-react": "^4.0.0", "autoprefixer": "^10.4.13", "babel-jest": "^29.5.0", @@ -433,12 +429,6 @@ "vite-plugin-html": "^3.2.0" } }, - "client/node_modules/@types/node": { - "version": "18.16.17", - "resolved": "https://registry.npmjs.org/@types/node/-/node-18.16.17.tgz", - "integrity": "sha512-QAkjjRA1N7gPJeAP4WLXZtYv6+eMXFNviqktCDt4GLcmCugMr5BcRHfkOjCQzvCsnMp+L79a54zBkbw356xv9Q==", - "dev": true - }, "node_modules/@adobe/css-tools": { "version": "4.2.0", "resolved": "https://registry.npmjs.org/@adobe/css-tools/-/css-tools-4.2.0.tgz", @@ -32056,7 +32046,7 @@ "jsonwebtoken": "^9.0.0", "keyv": "^4.5.2", "keyv-file": "^0.2.0", - "langchain": "0.0.92", + "langchain": "^0.0.92", "lodash": "^4.17.21", "meilisearch": "^0.33.0", "mongoose": "^7.1.1", @@ -32145,10 +32135,10 @@ "@testing-library/jest-dom": "^5.16.5", "@testing-library/react": "^14.0.0", "@testing-library/user-event": "^14.4.3", - "@types/jest": "^29.5.1", - "@types/node": "^18.16.13", - "@types/react": "^18.2.6", - "@types/react-dom": "^18.0.11", + "@types/jest": "^29.5.2", + "@types/node": "^20.3.0", + "@types/react": "^18.2.11", + "@types/react-dom": "^18.2.4", "@vitejs/plugin-react": "^4.0.0", "@zattoo/use-double-click": "1.2.0", "autoprefixer": "^10.4.13", @@ -32215,14 +32205,6 @@ "url": "^0.11.0", "vite": "^4.3.9", "vite-plugin-html": "^3.2.0" - }, - "dependencies": { - "@types/node": { - "version": "18.16.17", - "resolved": "https://registry.npmjs.org/@types/node/-/node-18.16.17.tgz", - "integrity": "sha512-QAkjjRA1N7gPJeAP4WLXZtYv6+eMXFNviqktCDt4GLcmCugMr5BcRHfkOjCQzvCsnMp+L79a54zBkbw356xv9Q==", - "dev": true - } } }, "cheerio": {