From ff2b29899280edb97ef30948738e3bcda445511b Mon Sep 17 00:00:00 2001 From: Walker Date: Sun, 17 Nov 2024 01:17:39 +0800 Subject: [PATCH] fix(chat): resolve void type error and improve dropdown behavior #127 - Fix TypeScript void error by separating setIsOpen and clearTimeout operations - Refactor dropdown mouse event handlers in both ToolDropdown and ModelDropdown - Add clearTimeout to prevent race conditions in dropdown closing - Standardize dropdown components using MenuItems and MenuItem --- .gitignore | 1 + .vscode/settings.json | 6 ----- eslint.config.js | 1 + src/components/ask-tooldropdown.tsx | 30 ++++++++++++++++--------- src/components/ask/ModelDropDown.tsx | 33 +++++++++++++++++++--------- 5 files changed, 45 insertions(+), 26 deletions(-) delete mode 100644 .vscode/settings.json diff --git a/.gitignore b/.gitignore index 8c9ab5c..2da1096 100644 --- a/.gitignore +++ b/.gitignore @@ -21,3 +21,4 @@ public/manifest.json .aider* *.code-workspace .shire +.vscode \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index 24c9997..0000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "Codegeex.RepoIndex": true, - "Codegeex.CompletionDelay": 1, - "Codegeex.GenerationPreference": "line by line", - "Codegeex.SidebarUI.LanguagePreference": "中文" -} \ No newline at end of file diff --git a/eslint.config.js b/eslint.config.js index bae922d..8c4adaa 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -36,6 +36,7 @@ export default [ SVGSVGElement: 'readonly', DOMRect: 'readonly', requestAnimationFrame: 'readonly', + clearTimeout: 'readonly', global: 'readonly', // for unit test __dirname: 'readonly', }, diff --git a/src/components/ask-tooldropdown.tsx b/src/components/ask-tooldropdown.tsx index c3bfca8..407643b 100644 --- a/src/components/ask-tooldropdown.tsx +++ b/src/components/ask-tooldropdown.tsx @@ -1,5 +1,5 @@ import React, { useEffect, useRef, useState } from 'react'; -import { Menu, Transition } from '@headlessui/react'; +import { Menu, MenuButton, MenuItem, MenuItems, Transition } from '@headlessui/react'; import { ChevronDownIcon } from '@heroicons/react/20/solid'; import classNames from 'classnames'; import defaultTools from '@assets/conf/tools.toml'; @@ -132,6 +132,7 @@ export default function ToolDropdown({ } }; let isCommandPressed = false; + let closeDropdownTimer: any; return (
- { - setIsOpen(!isOpened); + onMouseEnter={_e => { + setIsOpen(true); // e.stopPropagation(); + }} + onMouseLeave={_e => { + // Add a small delay before closing to allow moving to menu items + closeDropdownTimer = setTimeout(() => setIsOpen(false), 100); }}> {({ active }) => { setIsOpen(active); @@ -157,7 +162,7 @@ export default function ToolDropdown({ ); }} - + - + className="absolute left-0 mt-0 min-w-[10rem] origin-top-right divide-y divide-gray-100 rounded bg-white shadow-lg ring-1 ring-black/5 focus:outline-none z-10" + onMouseEnter={() => { + clearTimeout(closeDropdownTimer); + setIsOpen(true); + }} + onMouseLeave={() => setIsOpen(false)}>
{allTools.map((tool, index) => ( - + {({ active }) => ( )} - + ))} {showPreview && }
-
+
diff --git a/src/components/ask/ModelDropDown.tsx b/src/components/ask/ModelDropDown.tsx index 0bbba0a..d3b0dde 100644 --- a/src/components/ask/ModelDropDown.tsx +++ b/src/components/ask/ModelDropDown.tsx @@ -1,5 +1,5 @@ import React, { Fragment, useRef, useEffect, useState } from 'react'; -import { Menu, Transition } from '@headlessui/react'; +import { Menu, MenuButton, MenuItem, MenuItems, Transition } from '@headlessui/react'; import { ChevronDownIcon } from '@heroicons/react/20/solid'; import classNames from 'classnames'; import configStorage from '@src/shared/storages/configStorage'; @@ -73,7 +73,7 @@ export default function ModelDropdown({ fetchModels(); }, []); - + let closeDropdownTimer: any; return ( )} - + ))} - +