Skip to content

Commit

Permalink
Update search to work with pagination
Browse files Browse the repository at this point in the history
  • Loading branch information
Kicu committed May 17, 2024
1 parent b489783 commit 62dc109
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
14 changes: 6 additions & 8 deletions src/components/Search.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {useNavigation} from '@react-navigation/native';
import React, {useEffect} from 'react';
import {useOnyx} from 'react-native-onyx';
import useNetwork from '@hooks/useNetwork';
Expand Down Expand Up @@ -75,19 +76,19 @@ type SearchProps = {
function Search({query, policyIDs, sortOrder, sortBy}: SearchProps) {
const {isOffline} = useNetwork();
const styles = useThemeStyles();
const navigation = useNavigation();

useCustomBackHandler();

const hash = SearchUtils.getQueryHash(query, policyIDs);
const [searchResults, searchResultsMeta] = useOnyx(`${ONYXKEYS.COLLECTION.SNAPSHOT}${hash}`);

const offset = 0;

useEffect(() => {
if (isOffline) {
return;
}

SearchActions.search({hash, query, policyIDs, offset, sortBy, sortOrder});
SearchActions.search({hash, query, policyIDs, offset: 0, sortBy, sortOrder});
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [hash, isOffline, sortBy, sortOrder]);

Expand Down Expand Up @@ -116,7 +117,7 @@ function Search({query, policyIDs, sortOrder, sortBy}: SearchProps) {
return;
}
const currentOffset = searchResults?.search?.offset ?? 0;
SearchActions.search({hash, query, offset: currentOffset + CONST.SEARCH_RESULTS_PAGE_SIZE});
SearchActions.search({hash, query, offset: currentOffset + CONST.SEARCH_RESULTS_PAGE_SIZE, sortBy, sortOrder});
};

const type = SearchUtils.getSearchType(searchResults?.search);
Expand All @@ -130,13 +131,10 @@ function Search({query, policyIDs, sortOrder, sortBy}: SearchProps) {
const data = SearchUtils.getSections(searchResults?.data ?? {}, type);

const onSortPress = (column: SearchColumnType, order: SortOrder) => {
const newRoute = ROUTES.SEARCH.getRoute(query, {
query,
navigation.setParams({
sortBy: column,

Check failure on line 135 in src/components/Search.tsx

View workflow job for this annotation

GitHub Actions / typecheck

Object literal may only specify known properties, and 'sortBy' does not exist in type 'Partial<{ reportID: string; source: string; }> | Partial<{ accountID: string; }> | Partial<{ policyID: string; }> | Partial<{ reportID: string; }> | ... 74 more ... | Partial<...>'.
sortOrder: order,
});

Navigation.navigate(newRoute);
};

const sortedData = getSortedData(data, sortBy, sortOrder);
Expand Down
2 changes: 1 addition & 1 deletion src/libs/actions/Search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function search({hash, query, policyIDs, offset, sortBy, sortOrder}: SearchParam
},
];

API.read(READ_COMMANDS.SEARCH, {hash, query, offset, policyIDs}, {optimisticData, finallyData});
API.read(READ_COMMANDS.SEARCH, {hash, query, offset, policyIDs, sortBy, sortOrder}, {optimisticData, finallyData});
}
export {
// eslint-disable-next-line import/prefer-default-export
Expand Down

0 comments on commit 62dc109

Please sign in to comment.