Skip to content

Commit

Permalink
fix PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
SzymczakJ committed Sep 27, 2024
1 parent fb0fc7f commit 26e9026
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 28 deletions.
14 changes: 4 additions & 10 deletions src/components/Search/SearchRouter/SearchRouter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import useKeyboardShortcut from '@hooks/useKeyboardShortcut';
import useLocalize from '@hooks/useLocalize';
import useResponsiveLayout from '@hooks/useResponsiveLayout';
import useThemeStyles from '@hooks/useThemeStyles';
import Log from '@libs/Log';
import * as OptionsListUtils from '@libs/OptionsListUtils';
import * as SearchUtils from '@libs/SearchUtils';
import Navigation from '@navigation/Navigation';
Expand Down Expand Up @@ -42,11 +43,7 @@ function SearchRouter() {
return state?.routes.at(-1)?.params?.reportID;
});
const sortedRecentSearches = useMemo(() => {
return Object.values(recentSearches ?? {}).sort((a, b) => {
const dateA = new Date(a.timestamp);
const dateB = new Date(b.timestamp);
return dateB.getTime() - dateA.getTime();
});
return Object.values(recentSearches ?? {}).sort((a, b) => b.timestamp.localeCompare(a.timestamp));
}, [recentSearches]);

const {options, areOptionsInitialized} = useOptionsList({
Expand Down Expand Up @@ -79,12 +76,9 @@ function SearchRouter() {
const queryJSON = SearchUtils.buildSearchQueryJSON(userQuery);

if (queryJSON) {
// eslint-disable-next-line
console.log('parsedQuery', queryJSON);

setUserSearchQuery(queryJSON);
} else {
// Handle query parsing error
Log.alert(`${CONST.ERROR.ENSURE_BUGBOT} user query failed to parse`, userQuery, false);
}
}, SEARCH_DEBOUNCE_DELAY),
[],
Expand Down Expand Up @@ -150,7 +144,7 @@ function SearchRouter() {
currentQuery={userSearchQuery}
reportForContextualSearch={contextualReportData}
recentSearches={sortedRecentSearches?.slice(0, 5)}
recentReports={searchOptions?.recentReports?.slice(0, 5)}
recentReports={searchOptions?.recentReports?.slice(0, 10)}
onSearchSubmit={onSearchSubmit}
updateUserSearchQuery={updateUserSearchQuery}
closeAndClearRouter={closeAndClearRouter}
Expand Down
40 changes: 23 additions & 17 deletions src/components/Search/SearchRouter/SearchRouterList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,17 @@ type SearchRouterListProps = {
closeAndClearRouter: () => void;
};

function isSearchQueryListItem(listItem: UserListItemProps<OptionData> | SearchQueryListItemProps): listItem is SearchQueryListItemProps {
if ('singleIcon' in listItem.item && listItem.item.singleIcon && 'query' in listItem.item && !!listItem.item.query) {
function isSearchQueryItem(item: OptionData | SearchQueryItem): item is SearchQueryItem {
if ('singleIcon' in item && item.singleIcon && 'query' in item && item.query) {
return true;
}
return false;
}

function isSearchQueryListItem(listItem: UserListItemProps<OptionData> | SearchQueryListItemProps): listItem is SearchQueryListItemProps {
return isSearchQueryItem(listItem.item);
}

function SearchRouterItem(props: UserListItemProps<OptionData> | SearchQueryListItemProps) {
const styles = useThemeStyles();

Expand Down Expand Up @@ -109,25 +113,27 @@ function SearchRouterList(

const onSelectRow = useCallback(
(item: OptionData | SearchQueryItem) => {
if (!('query' in item) || !item.query) {
// Handle selection of "Recent chat"
closeAndClearRouter();
if ('reportID' in item && item?.reportID) {
Navigation.closeAndNavigate(ROUTES.REPORT_WITH_ID.getRoute(item?.reportID));
} else if ('login' in item) {
Report.navigateToAndOpenReport(item?.login ? [item.login] : []);
if (isSearchQueryItem(item)) {
if (item.isContextualSearchItem) {
// Handle selection of "Contextual search suggestion"
updateUserSearchQuery(`${item?.query} ${currentQuery?.inputQuery ?? ''}`);
return;
}
return;
}

if (item.isContextualSearchItem) {
// Handle selection of "Contextual search suggestion"
updateUserSearchQuery(`${item?.query} ${currentQuery?.inputQuery ?? ''}`);
return;
// Handle selection of "Recent search"
if (!item?.query) {
return;
}
onSearchSubmit(SearchUtils.buildSearchQueryJSON(item?.query));
}

// Handle selection of "Recent search"
onSearchSubmit(SearchUtils.buildSearchQueryJSON(item?.query));
// Handle selection of "Recent chat"
closeAndClearRouter();
if ('reportID' in item && item?.reportID) {
Navigation.closeAndNavigate(ROUTES.REPORT_WITH_ID.getRoute(item?.reportID));
} else if ('login' in item) {
Report.navigateToAndOpenReport(item?.login ? [item.login] : []);
}
},
[closeAndClearRouter, onSearchSubmit, currentQuery, updateUserSearchQuery],
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ function SearchQueryListItem({item, isFocused, showTooltip, onSelectRow, onFocus
);
}

SearchQueryListItem.displayName = 'SingleIconListItem';
SearchQueryListItem.displayName = 'SearchQueryListItem';

export default SearchQueryListItem;
export type {SearchQueryItem, SearchQueryListItemProps};

0 comments on commit 26e9026

Please sign in to comment.