Skip to content

Commit

Permalink
Merge pull request #43380 from software-mansion-labs/fix-random-sorti…
Browse files Browse the repository at this point in the history
…ng-on-mobile

[Search v1] Fix random sorting on mobile

(cherry picked from commit 2261654)
  • Loading branch information
luacmartins authored and OSBotify committed Jun 10, 2024
1 parent ef2ac29 commit 3600046
Showing 1 changed file with 29 additions and 4 deletions.
33 changes: 29 additions & 4 deletions src/pages/Search/SearchPageBottomTab.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React from 'react';
import type {StackScreenProps} from '@react-navigation/stack';
import React, {useMemo} from 'react';
import FullPageNotFoundView from '@components/BlockingViews/FullPageNotFoundView';
import ScreenWrapper from '@components/ScreenWrapper';
import Search from '@components/Search';
Expand All @@ -7,20 +8,42 @@ import useLocalize from '@hooks/useLocalize';
import useThemeStyles from '@hooks/useThemeStyles';
import useWindowDimensions from '@hooks/useWindowDimensions';
import Navigation from '@libs/Navigation/Navigation';
import type {CentralPaneNavigatorParamList} from '@libs/Navigation/types';
import TopBar from '@navigation/AppNavigator/createCustomBottomTabNavigator/TopBar';
import CONST from '@src/CONST';
import ROUTES from '@src/ROUTES';
import SCREENS from '@src/SCREENS';
import type {SearchQuery} from '@src/types/onyx/SearchResults';
import SearchFilters from './SearchFilters';

type SearchPageProps = StackScreenProps<CentralPaneNavigatorParamList, typeof SCREENS.SEARCH.CENTRAL_PANE>;

const defaultSearchProps = {
query: '' as SearchQuery,
policyIDs: undefined,
sortBy: CONST.SEARCH_TABLE_COLUMNS.DATE,
sortOrder: CONST.SORT_ORDER.DESC,
};
function SearchPageBottomTab() {
const {translate} = useLocalize();
const {isSmallScreenWidth} = useWindowDimensions();
const activeRoute = useActiveRoute();
const styles = useThemeStyles();
const currentQuery = activeRoute?.params && 'query' in activeRoute.params ? activeRoute?.params?.query : '';
const policyIDs = activeRoute?.params && 'policyIDs' in activeRoute.params ? (activeRoute?.params?.policyIDs as string) : undefined;
const query = currentQuery as SearchQuery;

const {
query: rawQuery,
policyIDs,
sortBy,
sortOrder,
} = useMemo(() => {
if (activeRoute?.name !== SCREENS.SEARCH.CENTRAL_PANE || !activeRoute.params) {
return defaultSearchProps;
}
return {...defaultSearchProps, ...activeRoute.params} as SearchPageProps['route']['params'];
}, [activeRoute]);

const query = rawQuery as SearchQuery;

const isValidQuery = Object.values(CONST.TAB_SEARCH).includes(query);

const handleOnBackButtonPress = () => Navigation.goBack(ROUTES.SEARCH.getRoute(CONST.TAB_SEARCH.ALL));
Expand All @@ -45,6 +68,8 @@ function SearchPageBottomTab() {
<Search
policyIDs={policyIDs}
query={query}
sortBy={sortBy}
sortOrder={sortOrder}
/>
)}
</FullPageNotFoundView>
Expand Down

0 comments on commit 3600046

Please sign in to comment.