Skip to content

Commit 1fb464d

Browse files
authored
fix: open extension store display (#724)
1 parent 65aa750 commit 1fb464d

3 files changed

Lines changed: 76 additions & 43 deletions

File tree

src/components/Search/AssistantManager.tsx

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useCallback, useRef, useMemo, useState, useEffect } from "react";
1+
import { useCallback, useRef, useMemo, useState } from "react";
22
import { cloneDeep, isEmpty } from "lodash-es";
33

44
import { useSearchStore } from "@/stores/searchStore";
@@ -147,24 +147,6 @@ export function useAssistantManager({
147147
]
148148
);
149149

150-
useEffect(() => {
151-
const unlisten = platformAdapter.listenEvent("open-extension-store", () => {
152-
platformAdapter.showWindow();
153-
154-
if (visibleExtensionStore || visibleExtensionDetail) return;
155-
156-
changeInput("");
157-
setSearchValue("");
158-
setVisibleExtensionStore(true);
159-
});
160-
161-
return () => {
162-
unlisten.then((fn) => {
163-
fn();
164-
});
165-
};
166-
}, [visibleExtensionStore, visibleExtensionDetail]);
167-
168150
return {
169151
askAI,
170152
askAIRef,

src/components/Search/Search.tsx

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,21 @@ import Footer from "@/components/Common/UI/Footer";
99
import AskAi from "./AskAi";
1010
import { useSearch } from "@/hooks/useSearch";
1111
import ExtensionStore from "./ExtensionStore";
12+
import platformAdapter from "@/utils/platformAdapter";
1213

1314
const SearchResultsPanel = memo<{
1415
input: string;
1516
isChatMode: boolean;
16-
}>(({ input, isChatMode }) => {
17-
const { sourceData, goAskAi } = useSearchStore();
17+
changeInput: (val: string) => void;
18+
changeMode?: (isChatMode: boolean) => void;
19+
}>(({ input, isChatMode, changeInput, changeMode }) => {
20+
const {
21+
sourceData,
22+
goAskAi,
23+
visibleExtensionDetail,
24+
setSearchValue,
25+
setVisibleExtensionStore,
26+
} = useSearchStore();
1827

1928
const searchState = useSearch();
2029
const {
@@ -48,6 +57,25 @@ const SearchResultsPanel = memo<{
4857
}
4958
}, [selectedSearchContent]);
5059

60+
useEffect(() => {
61+
const unlisten = platformAdapter.listenEvent("open-extension-store", () => {
62+
platformAdapter.showWindow();
63+
changeMode && changeMode(false);
64+
65+
if (visibleExtensionStore || visibleExtensionDetail) return;
66+
67+
changeInput("");
68+
setSearchValue("");
69+
setVisibleExtensionStore(true);
70+
});
71+
72+
return () => {
73+
unlisten.then((fn) => {
74+
fn();
75+
});
76+
};
77+
}, [visibleExtensionStore, visibleExtensionDetail]);
78+
5179
if (visibleExtensionStore) return <ExtensionStore />;
5280
if (goAskAi) return <AskAi />;
5381
if (suggests.length === 0) return <NoResults />;
@@ -71,14 +99,26 @@ interface SearchProps {
7199
isChatMode: boolean;
72100
input: string;
73101
setIsPinned?: (value: boolean) => void;
102+
changeMode?: (isChatMode: boolean) => void;
74103
}
75104

76-
function Search({ isChatMode, input, setIsPinned }: SearchProps) {
105+
function Search({
106+
changeInput,
107+
isChatMode,
108+
input,
109+
setIsPinned,
110+
changeMode,
111+
}: SearchProps) {
77112
const mainWindowRef = useRef<HTMLDivElement>(null);
78113

79114
return (
80115
<div ref={mainWindowRef} className={`h-full pb-8 w-full relative`}>
81-
<SearchResultsPanel input={input} isChatMode={isChatMode} />
116+
<SearchResultsPanel
117+
input={input}
118+
isChatMode={isChatMode}
119+
changeInput={changeInput}
120+
changeMode={changeMode}
121+
/>
82122

83123
<Footer setIsPinnedWeb={setIsPinned} />
84124

src/components/SearchChat/index.tsx

Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,15 @@ function SearchChat({
6262

6363
const source = currentAssistant?._source;
6464

65-
const customInitialState = useMemo(() => ({
66-
...initialAppState,
67-
isDeepThinkActive: source?.type === "deep_think",
68-
isSearchActive: source?.datasource?.enabled_by_default === true,
69-
isMCPActive: source?.mcp_servers?.enabled_by_default === true,
70-
}), [source]);
65+
const customInitialState = useMemo(
66+
() => ({
67+
...initialAppState,
68+
isDeepThinkActive: source?.type === "deep_think",
69+
isSearchActive: source?.datasource?.enabled_by_default === true,
70+
isMCPActive: source?.mcp_servers?.enabled_by_default === true,
71+
}),
72+
[source]
73+
);
7174

7275
const [state, dispatch] = useReducer(appReducer, customInitialState);
7376
const {
@@ -80,9 +83,18 @@ function SearchChat({
8083
isTyping,
8184
} = state;
8285
useEffect(() => {
83-
dispatch({ type: "SET_SEARCH_ACTIVE", payload: customInitialState.isSearchActive });
84-
dispatch({ type: "SET_DEEP_THINK_ACTIVE", payload: customInitialState.isDeepThinkActive });
85-
dispatch({ type: "SET_MCP_ACTIVE", payload: customInitialState.isMCPActive });
86+
dispatch({
87+
type: "SET_SEARCH_ACTIVE",
88+
payload: customInitialState.isSearchActive,
89+
});
90+
dispatch({
91+
type: "SET_DEEP_THINK_ACTIVE",
92+
payload: customInitialState.isDeepThinkActive,
93+
});
94+
dispatch({
95+
type: "SET_MCP_ACTIVE",
96+
payload: customInitialState.isMCPActive,
97+
});
8698
}, [customInitialState]);
8799

88100
const [isWin10, setIsWin10] = useState(false);
@@ -264,13 +276,11 @@ function SearchChat({
264276
)}
265277
style={{ opacity: blurred ? (opacity ?? 30) / 100 : 1 }}
266278
>
267-
268279
<div
269280
data-tauri-drag-region={isTauri}
270-
className={clsx(
271-
"flex-1 w-full overflow-auto",
272-
{ "hidden": !isTransitioned }
273-
)}
281+
className={clsx("flex-1 w-full overflow-auto", {
282+
hidden: !isTransitioned,
283+
})}
274284
>
275285
<Suspense fallback={<LoadingFallback />}>
276286
<ChatAI
@@ -290,8 +300,9 @@ function SearchChat({
290300

291301
<div
292302
data-tauri-drag-region={isTauri}
293-
className={`p-2 w-full flex justify-center transition-all duration-500 min-h-[82px] ${isTransitioned ? "border-t" : "border-b"
294-
} border-[#E6E6E6] dark:border-[#272626]`}
303+
className={`p-2 w-full flex justify-center transition-all duration-500 min-h-[82px] ${
304+
isTransitioned ? "border-t" : "border-b"
305+
} border-[#E6E6E6] dark:border-[#272626]`}
295306
>
296307
<InputBox
297308
isChatMode={isChatMode}
@@ -326,10 +337,9 @@ function SearchChat({
326337

327338
<div
328339
data-tauri-drag-region={isTauri}
329-
className={clsx(
330-
"flex-1 w-full overflow-auto",
331-
{ "hidden": isTransitioned }
332-
)}
340+
className={clsx("flex-1 w-full overflow-auto", {
341+
hidden: isTransitioned,
342+
})}
333343
>
334344
<Suspense fallback={<LoadingFallback />}>
335345
<Search
@@ -338,6 +348,7 @@ function SearchChat({
338348
isChatMode={isChatMode}
339349
changeInput={setInput}
340350
setIsPinned={setIsPinned}
351+
changeMode={changeMode}
341352
/>
342353
</Suspense>
343354
</div>

0 commit comments

Comments
 (0)