From 40758dd093f8ed64c5a09a9dc1cd097220193699 Mon Sep 17 00:00:00 2001 From: BiggerRain <15911122312@163.COM> Date: Wed, 20 Nov 2024 10:08:08 +0800 Subject: [PATCH] feat: add query search functionality and UI enhancements (#10) * feat: add query serach & UI adjustments * chore: Cleaning up the code * fix: fix search bug * chore: add /ui to the routing link --- src-tauri/capabilities/default.json | 30 +- src-tauri/tauri.conf.json | 51 ++- src/components/ChatAI/AutoResizeTextarea.tsx | 43 ++ src/components/ChatAI/Chat.tsx | 394 +++++++++++++++++++ src/components/ChatAI/ChatInput.tsx | 100 ++--- src/components/ChatAI/ChatMessage.tsx | 2 - src/components/ChatAI/Markdown.tsx | 1 - src/components/ChatAI/index.tsx | 54 +-- src/components/MySearch/ChatInterface.tsx | 5 +- src/components/MySearch/CommandPalette.tsx | 2 +- src/components/MySearch/SearchResults.tsx | 3 - src/components/MySearch/index.tsx | 2 +- src/components/SearchChat/ChatSwitch.tsx | 18 +- src/components/SearchChat/DropdownList.tsx | 121 ++++++ src/components/SearchChat/Footer.tsx | 198 +++++----- src/components/SearchChat/Search.tsx | 179 +++++++-- src/components/SearchChat/SearchResults.tsx | 2 +- src/components/SearchChat/Switch.tsx | 37 ++ src/components/SearchChat/index.tsx | 31 +- src/components/SearchChat/types.ts | 12 + src/components/ThemeProvider.tsx | 6 +- src/hooks/useWebSocket.ts | 15 +- src/hooks/useWindows.ts | 115 ++++++ src/main.tsx | 2 +- src/routes/Header.tsx | 9 +- src/routes/Layout.tsx | 6 +- src/routes/index.tsx | 10 +- src/stores/themeStore.ts | 6 +- vite.config.ts | 1 + 29 files changed, 1169 insertions(+), 286 deletions(-) create mode 100644 src/components/ChatAI/AutoResizeTextarea.tsx create mode 100644 src/components/ChatAI/Chat.tsx create mode 100644 src/components/SearchChat/DropdownList.tsx create mode 100644 src/components/SearchChat/Switch.tsx create mode 100644 src/components/SearchChat/types.ts create mode 100644 src/hooks/useWindows.ts diff --git a/src-tauri/capabilities/default.json b/src-tauri/capabilities/default.json index daa7ace7..023e5ad4 100644 --- a/src-tauri/capabilities/default.json +++ b/src-tauri/capabilities/default.json @@ -2,26 +2,39 @@ "$schema": "../gen/schemas/desktop-schema.json", "identifier": "default", "description": "Capability for the main window", - "windows": ["main"], + "windows": ["main", "chat"], "permissions": [ + "core:default", + "core:event:allow-emit", "core:event:allow-listen", - "core:window:default", - "core:window:allow-start-dragging", "core:webview:allow-create-webview", - "core:window:allow-show", "core:webview:allow-create-webview-window", + "core:webview:allow-get-all-webviews", "core:webview:allow-webview-close", + "core:webview:allow-webview-hide", + "core:webview:allow-webview-show", + "core:webview:allow-webview-size", + "core:webview:allow-set-webview-size", + "core:webview:allow-set-webview-zoom", + "core:window:default", + "core:window:allow-center", "core:window:allow-close", "core:window:allow-hide", - "core:webview:allow-set-webview-size", + "core:window:allow-show", + "core:window:allow-create", + "core:window:allow-destroy", + "core:window:allow-start-dragging", "core:window:allow-set-size", - "core:default", + "core:window:allow-get-all-windows", "shell:allow-open", "http:default", "http:allow-fetch", "http:allow-fetch-cancel", "http:allow-fetch-read-body", "http:allow-fetch-send", + "websocket:default", + "websocket:allow-connect", + "websocket:allow-send", { "identifier": "http:default", "allow": [ @@ -30,9 +43,6 @@ } ], "deny": [] - }, - "websocket:default", - "websocket:allow-connect", - "websocket:allow-send" + } ] } diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index 5eb020c6..2fe5bc58 100644 --- a/src-tauri/tauri.conf.json +++ b/src-tauri/tauri.conf.json @@ -13,14 +13,46 @@ "macOSPrivateApi": true, "windows": [ { - "title": "Coco AI", - "width": 900, - "height": 800, - "maxHeight": 800, - "transparent": true, - "resizable": true, + "acceptFirstMouse": true, + "alwaysOnBottom": false, + "alwaysOnTop": false, + "center": false, + "closable": true, + "contentProtected": false, + "create": true, + "decorations": false, + "dragDropEnabled": true, + "focus": false, "fullscreen": false, - "decorations": false + "height": 90, + "maxHeight": 700, + "minHeight": 90, + "width": 680, + "maxWidth": 680, + "minWidth": 680, + "hiddenTitle": false, + "incognito": false, + "label": "main", + "maximizable": false, + "minimizable": true, + "maximized": false, + "proxyUrl": "http://localhost:2900", + "resizable": false, + "shadow": true, + "skipTaskbar": false, + "theme": "Light", + "title": "Coco AI", + "transparent": true, + "url": "/ui", + "visible": true, + "visibleOnAllWorkspaces": true, + "windowEffects": { + "effects": [], + "radius": 20 + }, + "x": null, + "y": null, + "zoomHotkeysEnabled": false } ], "security": { @@ -45,6 +77,7 @@ }, "plugins": { "window": {}, - "websocket": {} + "websocket": {}, + "shell": {} } -} \ No newline at end of file +} diff --git a/src/components/ChatAI/AutoResizeTextarea.tsx b/src/components/ChatAI/AutoResizeTextarea.tsx new file mode 100644 index 00000000..ce5e81f8 --- /dev/null +++ b/src/components/ChatAI/AutoResizeTextarea.tsx @@ -0,0 +1,43 @@ +import React, { useEffect, useRef } from "react"; + +interface AutoResizeTextareaProps { + input: string; + setInput: (value: string) => void; + handleKeyDown?: (e: React.KeyboardEvent) => void; +} + +const AutoResizeTextarea: React.FC = ({ + input, + setInput, + handleKeyDown, +}) => { + const textareaRef = useRef(null); + + useEffect(() => { + const textarea = textareaRef.current; + if (textarea) { + textarea.style.height = "auto"; // Reset height to recalculate + textarea.style.height = `${textarea.scrollHeight}px`; // Adjust based on content + } + }, [input]); + + return ( +