Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CP Staging][Search v1] Fix random sorting on mobile #43380

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading