Skip to content

Commit 07f0515

Browse files
committed
Fix search functionality and handle empty results
1 parent f43c5ad commit 07f0515

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

llmstack/client/src/components/store/Search.jsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,10 @@ const AppList = ({ queryTerm }) => {
108108
});
109109
}, [appsLoadable.contents, setAppsData, appsLoadable.state]);
110110

111+
useEffect(() => {
112+
setNextPage(null);
113+
}, [queryTerm]);
114+
111115
useEffect(() => {
112116
if (loaderRef.current && appsLoadable.state === "hasValue") {
113117
setAppsData(appsLoadable.contents);
@@ -181,7 +185,6 @@ export default function Search({ appSlug }) {
181185
sx={{ p: "2px 4px", display: "flex", alignItems: "center" }}
182186
onSubmit={(e) => {
183187
e.preventDefault();
184-
// searchApps(searchTerm);
185188
setQueryTerm(`search?query=${searchTerm}`);
186189
}}
187190
>

llmstack/client/src/data/atoms.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ export const storeAppState = atomFamily({
455455

456456
export const appsPageState = atomFamily({
457457
key: "appsPageState",
458-
default: { apps: [], nextPage: null },
458+
default: { apps: [], nextPage: null, empty: false },
459459
});
460460

461461
export const fetchAppsFromStore = selectorFamily({
@@ -464,7 +464,12 @@ export const fetchAppsFromStore = selectorFamily({
464464
({ queryTerm, nextPage }) =>
465465
async ({ get }) => {
466466
const currentPageData = get(appsPageState(queryTerm));
467-
if (nextPage === currentPageData.nextPage) {
467+
if (
468+
(nextPage && nextPage === currentPageData.nextPage) ||
469+
(!nextPage &&
470+
currentPageData.apps.length === 0 &&
471+
!currentPageData.empty)
472+
) {
468473
try {
469474
const response = await axios().get(
470475
nextPage?.replaceAll("http://localhost:8000", "") ||
@@ -474,6 +479,7 @@ export const fetchAppsFromStore = selectorFamily({
474479
return {
475480
apps: [...currentPageData.apps, ...data.results],
476481
nextPage: data.next,
482+
empty: data.results.length === 0,
477483
};
478484
} catch (error) {
479485
console.error(error);

0 commit comments

Comments
 (0)