From da917e60124c79a87e41558bc6455a0e4a04033c Mon Sep 17 00:00:00 2001 From: BiggerRain <15911122312@163.COM> Date: Tue, 10 Jun 2025 14:28:00 +0800 Subject: [PATCH] fix: web page unmount event (#645) * fix: web page unmont event * docs: update notes --- docs/content.en/docs/release-notes/_index.md | 1 + src/components/Search/ContextMenu.tsx | 4 +- src/components/Search/DropdownList.tsx | 14 +- src/components/Search/InputBox.tsx | 1 - src/components/Search/Search.tsx | 5 +- src/components/SearchChat/index.tsx | 4 - src/hooks/useKeyboardNavigation.ts | 6 +- src/pages/main/index.tsx | 10 +- src/pages/web/README.md | 231 ++++++++++--------- src/pages/web/index.tsx | 4 +- 10 files changed, 144 insertions(+), 136 deletions(-) diff --git a/docs/content.en/docs/release-notes/_index.md b/docs/content.en/docs/release-notes/_index.md index 6c5344d1..97f353ac 100644 --- a/docs/content.en/docs/release-notes/_index.md +++ b/docs/content.en/docs/release-notes/_index.md @@ -34,6 +34,7 @@ Information about release notes of Coco Server is provided here. - fix: tab key hides window in chat mode #641 - fix: arrow keys still navigated search when menu opened with Cmd+K #642 - fix: input lost when reopening dialog after search #644 +- fix: web page unmount event #645 ### ✈️ Improvements diff --git a/src/components/Search/ContextMenu.tsx b/src/components/Search/ContextMenu.tsx index 42cebe8d..da6888db 100644 --- a/src/components/Search/ContextMenu.tsx +++ b/src/components/Search/ContextMenu.tsx @@ -19,9 +19,7 @@ interface State { activeMenuIndex: number; } -interface ContextMenuProps { - hideCoco?: () => void; -} +interface ContextMenuProps {} const ContextMenu: FC = () => { const containerRef = useRef(null); diff --git a/src/components/Search/DropdownList.tsx b/src/components/Search/DropdownList.tsx index a931fae1..1a9d8039 100644 --- a/src/components/Search/DropdownList.tsx +++ b/src/components/Search/DropdownList.tsx @@ -6,7 +6,7 @@ import { MouseEvent, useMemo, } from "react"; -import { useDebounceFn, useUnmount } from "ahooks"; +import { useDebounceFn } from "ahooks"; import { useTranslation } from "react-i18next"; import { useSearchStore } from "@/stores/searchStore"; @@ -98,11 +98,6 @@ function DropdownList({ }; }, []); - useUnmount(() => { - setSelectedIndex(null); - setSelectedSearchContent(undefined); - }); - useEffect(() => { if (selectedIndex === null) { setSelectedSearchContent(undefined); @@ -150,6 +145,13 @@ function DropdownList({ initializeSelection(); }, [searchData]); + useEffect(() => { + return () => { + setSelectedIndex(null); + setSelectedSearchContent(undefined); + }; + }, []); + // Keyboard navigation useKeyboardNavigation({ suggests, diff --git a/src/components/Search/InputBox.tsx b/src/components/Search/InputBox.tsx index 723c5009..e4853424 100644 --- a/src/components/Search/InputBox.tsx +++ b/src/components/Search/InputBox.tsx @@ -46,7 +46,6 @@ interface ChatInputProps { }) => Promise; getFileMetadata: (path: string) => Promise; getFileIcon: (path: string, size: number) => Promise; - hideCoco?: () => void; hasModules?: string[]; searchPlaceholder?: string; chatPlaceholder?: string; diff --git a/src/components/Search/Search.tsx b/src/components/Search/Search.tsx index 841509d5..06035ca3 100644 --- a/src/components/Search/Search.tsx +++ b/src/components/Search/Search.tsx @@ -54,11 +54,10 @@ interface SearchProps { changeInput: (val: string) => void; isChatMode: boolean; input: string; - hideCoco?: () => void; setIsPinned?: (value: boolean) => void; } -function Search({ isChatMode, input, hideCoco, setIsPinned }: SearchProps) { +function Search({ isChatMode, input, setIsPinned }: SearchProps) { const mainWindowRef = useRef(null); return ( @@ -67,7 +66,7 @@ function Search({ isChatMode, input, hideCoco, setIsPinned }: SearchProps) {