Skip to content
Merged
Show file tree
Hide file tree
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
4 changes: 3 additions & 1 deletion src/components/Search/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ type SearchProps = {
contentContainerStyle?: StyleProp<ViewStyle>;
searchResults?: SearchResults;
handleSearch: (value: SearchParams) => void;
onSortPressedCallback?: () => void;
isMobileSelectionModeEnabled: boolean;
};

Expand Down Expand Up @@ -215,7 +216,7 @@ const exportReportActionsSelector = (allReportActions: OnyxCollection<ReportActi
);
};

function Search({queryJSON, searchResults, onSearchListScroll, contentContainerStyle, handleSearch, isMobileSelectionModeEnabled}: SearchProps) {
function Search({queryJSON, searchResults, onSearchListScroll, contentContainerStyle, handleSearch, isMobileSelectionModeEnabled, onSortPressedCallback}: SearchProps) {
const {isOffline} = useNetwork();
const {shouldUseNarrowLayout} = useResponsiveLayout();
const styles = useThemeStyles();
Expand Down Expand Up @@ -860,6 +861,7 @@ function Search({queryJSON, searchResults, onSearchListScroll, contentContainerS

const onSortPress = (column: SearchColumnType, order: SortOrder) => {
const newQuery = buildSearchQueryString({...queryJSON, sortBy: column, sortOrder: order});
onSortPressedCallback?.();
navigation.setParams({q: newQuery});
};

Expand Down
24 changes: 23 additions & 1 deletion src/pages/Search/SearchPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import useLocalize from '@hooks/useLocalize';
import useMobileSelectionMode from '@hooks/useMobileSelectionMode';
import useNetwork from '@hooks/useNetwork';
import useOnyx from '@hooks/useOnyx';
import usePrevious from '@hooks/usePrevious';
import useResponsiveLayout from '@hooks/useResponsiveLayout';
import useTheme from '@hooks/useTheme';
import useThemeStyles from '@hooks/useThemeStyles';
Expand Down Expand Up @@ -642,7 +643,15 @@ function SearchPage({route}: SearchPageProps) {
const handleOnBackButtonPress = () => Navigation.goBack(ROUTES.SEARCH_ROOT.getRoute({query: buildCannedSearchQuery()}));
const {resetVideoPlayerData} = usePlaybackContext();

const searchResults = currentSearchResults?.data ? currentSearchResults : lastNonEmptySearchResults.current;
const [isSorting, setIsSorting] = useState(false);

let searchResults;
if (currentSearchResults?.data) {
searchResults = currentSearchResults;
} else if (isSorting) {
searchResults = lastNonEmptySearchResults.current;
}

const metadata = searchResults?.search;
const shouldShowOfflineIndicator = !!searchResults?.data;
const shouldShowFooter = !!metadata?.count;
Expand Down Expand Up @@ -674,6 +683,16 @@ function SearchPage({route}: SearchPageProps) {
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

const prevIsLoading = usePrevious(currentSearchResults?.isLoading);

useEffect(() => {
Comment thread
mkzie2 marked this conversation as resolved.
Resolved
if (!isSorting || !prevIsLoading || currentSearchResults?.isLoading) {
return;
}

setIsSorting(false);
}, [currentSearchResults?.isLoading, isSorting, prevIsLoading]);

const handleSearchAction = useCallback((value: SearchParams | string) => {
if (typeof value === 'string') {
searchInServer(value);
Expand Down Expand Up @@ -812,6 +831,9 @@ function SearchPage({route}: SearchPageProps) {

saveScrollOffset(route, e.nativeEvent.contentOffset.y);
}}
onSortPressedCallback={() => {
setIsSorting(true);
}}
/>
{shouldShowFooter && (
<SearchPageFooter
Expand Down