forked from Expensify/App
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add basic code skeleton for new Search Router PoC
- Loading branch information
Showing
5 changed files
with
154 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
import React, {useState} from 'react'; | ||
import {View} from 'react-native'; | ||
import Button from '@components/Button'; | ||
import * as Expensicons from '@components/Icon/Expensicons'; | ||
import Modal from '@components/Modal'; | ||
import SelectionList from '@components/SelectionList'; | ||
import TableListItem from '@components/SelectionList/TableListItem'; | ||
import useLocalize from '@hooks/useLocalize'; | ||
import useResponsiveLayout from '@hooks/useResponsiveLayout'; | ||
import useThemeStyles from '@hooks/useThemeStyles'; | ||
import Navigation from '@libs/Navigation/Navigation'; | ||
import * as SearchUtils from '@libs/SearchUtils'; | ||
import CONST from '@src/CONST'; | ||
import ROUTES from '@src/ROUTES'; | ||
import type {SearchDataTypes} from '@src/types/onyx/SearchResults'; | ||
import SearchRouterInput from './SearchRouter/SearchRouterInput'; | ||
import type {SearchQueryJSON} from './types'; | ||
|
||
type SearchRouterProps = { | ||
type?: SearchDataTypes; | ||
}; | ||
|
||
function SearchRouter({type}: SearchRouterProps) { | ||
const styles = useThemeStyles(); | ||
const {translate} = useLocalize(); | ||
const {isSmallScreenWidth} = useResponsiveLayout(); | ||
|
||
const [isDisplayed, setIsDisplayed] = useState(false); | ||
const [currentQuery, setCurrentQuery] = useState<SearchQueryJSON | undefined>(undefined); | ||
|
||
const modalType = isSmallScreenWidth ? CONST.MODAL.MODAL_TYPE.CENTERED_UNSWIPEABLE : CONST.MODAL.MODAL_TYPE.POPOVER; | ||
const fullscreen = true; | ||
|
||
const onSearch = (userQuery: string) => { | ||
if (userQuery.length < 3) { | ||
return; | ||
} | ||
|
||
const query = type ? `type:${type} ${userQuery}` : userQuery; | ||
const queryJSON = SearchUtils.buildSearchQueryJSON(query); | ||
|
||
if (queryJSON) { | ||
setCurrentQuery(queryJSON); | ||
} | ||
}; | ||
|
||
const sectionData = currentQuery | ||
? [ | ||
{ | ||
text: `Search for: ${currentQuery.inputQuery}`, | ||
}, | ||
] | ||
: []; | ||
|
||
return ( | ||
<> | ||
<Button | ||
text={translate('common.search')} | ||
icon={Expensicons.MagnifyingGlass} | ||
onPress={() => { | ||
setIsDisplayed(true); | ||
}} | ||
medium | ||
/> | ||
<Modal | ||
type={modalType} | ||
fullscreen={fullscreen} | ||
isVisible={isDisplayed} | ||
popoverAnchorPosition={{right: 20, top: 20}} | ||
onClose={() => { | ||
setIsDisplayed(false); | ||
}} | ||
> | ||
<View style={[styles.flex1, styles.p4, styles.m5]}> | ||
<SearchRouterInput onSearch={onSearch} /> | ||
{currentQuery ? ( | ||
<View> | ||
<SelectionList | ||
sections={[{data: sectionData}]} | ||
ListItem={TableListItem} | ||
onSelectRow={() => { | ||
// Todo different items will have different functionalities on click | ||
const query = SearchUtils.buildSearchQueryString(currentQuery); | ||
|
||
setIsDisplayed(false); | ||
Navigation.navigate(ROUTES.SEARCH_CENTRAL_PANE.getRoute({query})); | ||
}} | ||
/> | ||
</View> | ||
) : null} | ||
</View> | ||
</Modal> | ||
</> | ||
); | ||
} | ||
|
||
SearchRouter.displayName = 'SearchRouter'; | ||
|
||
export default SearchRouter; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import React, {useState} from 'react'; | ||
import {View} from 'react-native'; | ||
import TextInput from '@components/TextInput'; | ||
import useTheme from '@hooks/useTheme'; | ||
import useThemeStyles from '@hooks/useThemeStyles'; | ||
import CONST from '@src/CONST'; | ||
|
||
type SearchRouterInputProps = { | ||
onSearch: (searchTerm: string) => void; | ||
}; | ||
|
||
function SearchRouterInput({onSearch}: SearchRouterInputProps) { | ||
const styles = useThemeStyles(); | ||
const theme = useTheme(); | ||
|
||
const [value, setValue] = useState(''); | ||
|
||
const onChangeText = (text: string) => { | ||
setValue(text); | ||
onSearch(text); | ||
}; | ||
|
||
return ( | ||
<View style={[]}> | ||
<TextInput | ||
value={value} | ||
onChangeText={onChangeText} | ||
textInputContainerStyles={[]} | ||
containerStyles={[]} | ||
inputStyle={[ | ||
styles.w80, | ||
styles.h13, | ||
{ | ||
width: 400, | ||
}, | ||
{ | ||
borderRadius: 8, | ||
borderWidth: 4, | ||
borderColor: theme.borderFocus, | ||
}, | ||
]} | ||
role={CONST.ROLE.PRESENTATION} | ||
/> | ||
</View> | ||
); | ||
} | ||
|
||
SearchRouterInput.displayName = 'SearchRouterInput'; | ||
|
||
export default SearchRouterInput; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters