Skip to content

Commit e3c3351

Browse files
committed
Fix empty type filter returning all objects in search despite layout-specific view
1 parent 4ae30e3 commit e3c3351

2 files changed

Lines changed: 12 additions & 3 deletions

File tree

src/hooks/useGlobalSearch.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,17 @@ import { globalSearch } from "../api";
55
import { SortDirection } from "../models";
66
import { apiLimit } from "../utils";
77

8-
export function useGlobalSearch(query: string, types: string[]) {
8+
export function useGlobalSearch(query: string, types: string[], config?: { execute?: boolean }) {
9+
const shouldExecute = config?.execute !== false;
910
const { data, error, isLoading, mutate, pagination } = useCachedPromise(
10-
(query: string, types: string[]) => async (options: { page: number }) => {
11+
(query: string, types: string[], shouldExecute: boolean) => async (options: { page: number }) => {
12+
if (!shouldExecute) {
13+
return {
14+
data: [],
15+
hasMore: false,
16+
};
17+
}
18+
1119
const offset = options.page * apiLimit;
1220
const sortPreference = getPreferenceValues().sort;
1321
const sortDirection = sortPreference === "name" ? SortDirection.Ascending : SortDirection.Descending;
@@ -22,7 +30,7 @@ export function useGlobalSearch(query: string, types: string[]) {
2230
hasMore: response.pagination.has_more,
2331
};
2432
},
25-
[query, types],
33+
[query, types, shouldExecute],
2634
{
2735
keepPreviousData: true,
2836
},

src/search-anytype.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ function Search() {
3838
const { objects, objectsError, isLoadingObjects, mutateObjects, objectsPagination } = useGlobalSearch(
3939
searchText,
4040
types,
41+
{ execute: currentView === ViewType.objects || types.length > 0 }, // only execute search when viewing all objects or when specific types selected
4142
);
4243
const { spaces, spacesError, isLoadingSpaces } = useSpaces();
4344
const { pinnedObjects, pinnedObjectsError, isLoadingPinnedObjects, mutatePinnedObjects } = usePinnedObjects(

0 commit comments

Comments
 (0)