-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Use SearchRouter everywhere and drop Chat finder #49984
Changes from 14 commits
830ac47
4052f9a
cb51d04
635e0da
078420e
e21ed95
4b81669
2fddc70
47ba23f
c4f7088
5fc6c1f
7e44690
7587f23
90e18c5
3cd9405
1d0811f
935067e
a6a74c5
980e7d0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,24 +19,27 @@ import * as SearchUtils from '@libs/SearchUtils'; | |
import Navigation from '@navigation/Navigation'; | ||
import variables from '@styles/variables'; | ||
import * as Report from '@userActions/Report'; | ||
import Timing from '@userActions/Timing'; | ||
import CONST from '@src/CONST'; | ||
import ONYXKEYS from '@src/ONYXKEYS'; | ||
import ROUTES from '@src/ROUTES'; | ||
import {useSearchRouterContext} from './SearchRouterContext'; | ||
import SearchRouterInput from './SearchRouterInput'; | ||
import SearchRouterList from './SearchRouterList'; | ||
|
||
const SEARCH_DEBOUNCE_DELAY = 150; | ||
|
||
function SearchRouter() { | ||
type SearchRouterProps = { | ||
onRouterClose: () => void; | ||
}; | ||
|
||
function SearchRouter({onRouterClose}: SearchRouterProps) { | ||
const styles = useThemeStyles(); | ||
const {translate} = useLocalize(); | ||
const [betas] = useOnyx(ONYXKEYS.BETAS); | ||
const [recentSearches] = useOnyx(ONYXKEYS.RECENT_SEARCHES); | ||
const [isSearchingForReports] = useOnyx(ONYXKEYS.IS_SEARCHING_FOR_REPORTS, {initWithStoredValues: false}); | ||
|
||
const {isSmallScreenWidth} = useResponsiveLayout(); | ||
const {isSearchRouterDisplayed, closeSearchRouter} = useSearchRouterContext(); | ||
const listRef = useRef<SelectionListHandle>(null); | ||
|
||
const [textInputValue, debouncedInputValue, setTextInputValue] = useDebouncedState('', 500); | ||
|
@@ -65,7 +68,9 @@ function SearchRouter() { | |
}; | ||
} | ||
|
||
Timing.start(CONST.TIMING.SEARCH_FILTER_OPTIONS); | ||
const newOptions = OptionsListUtils.filterOptions(searchOptions, debouncedInputValue, {sortByReportTypeInSearch: true, preferChatroomsOverThreads: true}); | ||
Timing.end(CONST.TIMING.SEARCH_FILTER_OPTIONS); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm I think we might wanna end the timing once the list is rendered onLayout? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No this line is correct. There were 2 measures done in the old And this one is just the timing for performing the search of chats, copied directly from here: https://github.com/Expensify/App/blob/main/src/pages/ChatFinderPage/index.tsx#L107-L109 |
||
|
||
return { | ||
recentReports: newOptions.recentReports, | ||
|
@@ -87,15 +92,6 @@ function SearchRouter() { | |
Report.searchInServer(debouncedInputValue.trim()); | ||
}, [debouncedInputValue]); | ||
|
||
useEffect(() => { | ||
if (!textInputValue && isSearchRouterDisplayed) { | ||
return; | ||
} | ||
listRef.current?.updateAndScrollToFocusedIndex(0); | ||
// eslint-disable-next-line react-compiler/react-compiler | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, [isSearchRouterDisplayed]); | ||
|
||
const contextualReportData = contextualReportID ? searchOptions.recentReports?.find((option) => option.reportID === contextualReportID) : undefined; | ||
|
||
const clearUserQuery = () => { | ||
|
@@ -132,40 +128,42 @@ function SearchRouter() { | |
}; | ||
|
||
const closeAndClearRouter = useCallback(() => { | ||
closeSearchRouter(); | ||
onRouterClose(); | ||
clearUserQuery(); | ||
// eslint-disable-next-line react-compiler/react-compiler | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, [closeSearchRouter]); | ||
}, [onRouterClose]); | ||
|
||
const onSearchSubmit = useCallback( | ||
(query: SearchQueryJSON | undefined) => { | ||
if (!query) { | ||
return; | ||
} | ||
closeSearchRouter(); | ||
onRouterClose(); | ||
const queryString = SearchUtils.buildSearchQueryString(query); | ||
Navigation.navigate(ROUTES.SEARCH_CENTRAL_PANE.getRoute({query: queryString})); | ||
clearUserQuery(); | ||
}, | ||
// eslint-disable-next-line react-compiler/react-compiler | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
[closeSearchRouter], | ||
[onRouterClose], | ||
); | ||
|
||
useKeyboardShortcut(CONST.KEYBOARD_SHORTCUTS.ESCAPE, () => { | ||
closeSearchRouter(); | ||
clearUserQuery(); | ||
closeAndClearRouter(); | ||
}); | ||
|
||
const modalWidth = isSmallScreenWidth ? styles.w100 : {width: variables.popoverWidth}; | ||
const modalWidth = isSmallScreenWidth ? styles.w100 : {width: variables.searchRouterPopoverWidth}; | ||
|
||
return ( | ||
<View style={[styles.flex1, modalWidth, styles.h100, !isSmallScreenWidth && styles.mh85vh]}> | ||
<View | ||
style={[styles.flex1, modalWidth, styles.h100, !isSmallScreenWidth && styles.mh85vh]} | ||
testID={SearchRouter.displayName} | ||
> | ||
{isSmallScreenWidth && ( | ||
<HeaderWithBackButton | ||
title={translate('common.search')} | ||
onBackButtonPress={() => closeSearchRouter()} | ||
onBackButtonPress={() => onRouterClose()} | ||
/> | ||
)} | ||
<SearchRouterInput | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.