Skip to content

Commit 9078c99

Browse files
authored
feat: right-click menu search supports shortcuts (#441)
1 parent a044642 commit 9078c99

2 files changed

Lines changed: 32 additions & 16 deletions

File tree

src/components/Assistant/AssistantList.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,12 @@ import { useChatStore } from "@/stores/chatStore";
1818
import { useShortcutsStore } from "@/stores/shortcutsStore";
1919
import { Post } from "@/api/axiosRequest";
2020
import { Popover, PopoverButton, PopoverPanel } from "@headlessui/react";
21-
import { useDebounce, useKeyPress, useMount, usePagination } from "ahooks";
21+
import {
22+
useAsyncEffect,
23+
useDebounce,
24+
useKeyPress,
25+
usePagination,
26+
} from "ahooks";
2227
import clsx from "clsx";
2328
import NoDataImage from "../Common/NoDataImage";
2429
import PopoverInput from "../Common/PopoverInput";
@@ -144,11 +149,11 @@ export function AssistantList({ assistantIDs = [] }: AssistantListProps) {
144149
}
145150
};
146151

147-
useMount(async () => {
152+
useAsyncEffect(async () => {
148153
const data = await fetchAssistant({ current: 1, pageSize: 1000 });
149154

150155
setAssistantList(data.list);
151-
});
156+
}, [currentServiceId]);
152157

153158
const { pagination, runAsync } = usePagination(fetchAssistant, {
154159
defaultPageSize: 5,

src/components/Search/ContextMenu.tsx

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { isMac } from "@/utils/platform";
1212
import { CONTEXT_MENU_PANEL_ID } from "@/constants";
1313
import { useShortcutsStore } from "@/stores/shortcutsStore";
1414
import { Input } from "@headlessui/react";
15+
import VisibleKey from "../Common/VisibleKey";
1516

1617
interface State {
1718
activeMenuIndex: number;
@@ -38,6 +39,7 @@ const ContextMenu = ({ hideCoco }: ContextMenuProps) => {
3839
return state.selectedSearchContent;
3940
});
4041
const [searchMenus, setSearchMenus] = useState<typeof menus>([]);
42+
const searchInputRef = useRef<HTMLInputElement>(null);
4143

4244
const title = useCreation(() => {
4345
if (selectedSearchContent?.id === "Calculator") {
@@ -251,20 +253,29 @@ const ContextMenu = ({ hideCoco }: ContextMenuProps) => {
251253

252254
<div className="-mx-3 p-2 border-t border-[#E6E6E6] dark:border-[#262626]">
253255
{visibleContextMenu && (
254-
<Input
255-
autoFocus
256-
placeholder={t("search.contextMenu.search")}
257-
className="w-full bg-transparent"
258-
onChange={(event) => {
259-
const value = event.target.value;
260-
261-
const searchMenus = menus.filter((item) => {
262-
return lowerCase(item.name).includes(lowerCase(value));
263-
});
264-
265-
setSearchMenus(searchMenus);
256+
<VisibleKey
257+
shortcut="F"
258+
shortcutClassName="left-3"
259+
onKeyPress={() => {
260+
searchInputRef.current?.focus();
266261
}}
267-
/>
262+
>
263+
<Input
264+
ref={searchInputRef}
265+
autoFocus
266+
placeholder={t("search.contextMenu.search")}
267+
className="w-full bg-transparent"
268+
onChange={(event) => {
269+
const value = event.target.value;
270+
271+
const searchMenus = menus.filter((item) => {
272+
return lowerCase(item.name).includes(lowerCase(value));
273+
});
274+
275+
setSearchMenus(searchMenus);
276+
}}
277+
/>
278+
</VisibleKey>
268279
)}
269280
</div>
270281
</div>

0 commit comments

Comments
 (0)