-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1916 from coopcycle/feature/1705-search
Search feature in the restaurant interface
- Loading branch information
Showing
15 changed files
with
161 additions
and
54 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import React from 'react'; | ||
import { SafeAreaView } from 'react-native-safe-area-context'; | ||
|
||
export default function BasicSafeAreaView({ children }) { | ||
return ( | ||
<SafeAreaView style={{ flex: 1 }} edges={['left', 'right', 'bottom']}> | ||
{children} | ||
</SafeAreaView> | ||
); | ||
} |
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
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
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
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
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,72 @@ | ||
import React, { useMemo, useRef, useState } from 'react' | ||
import _ from 'lodash' | ||
import { FormControl, IconButton, Input } from 'native-base' | ||
import { FlatList } from 'react-native' | ||
import FontAwesome5 from 'react-native-vector-icons/FontAwesome5' | ||
import { useSelector } from 'react-redux' | ||
import { selectOrders } from '../../redux/Restaurant/selectors' | ||
import OrderListItem from './components/OrderListItem' | ||
import { useNavigation } from '@react-navigation/native' | ||
import { useTranslation } from 'react-i18next' | ||
import BasicSafeAreaView from '../../components/BasicSafeAreaView' | ||
|
||
export default function Search() { | ||
const orders = useSelector(selectOrders) | ||
|
||
const navigation = useNavigation() | ||
const { t } = useTranslation() | ||
|
||
const textInput = useRef(null) | ||
|
||
const [ query, setQuery ] = useState(null) | ||
|
||
const filteredOrders = useMemo(() => { | ||
if (!query) { | ||
return [] | ||
} | ||
|
||
return orders.filter(order => { | ||
return order.number.toLowerCase().includes(query.toLowerCase()) | ||
}) | ||
}, [ orders, query ]) | ||
|
||
return ( | ||
<BasicSafeAreaView> | ||
<FormControl> | ||
<Input | ||
size="md" | ||
m={ 4 } | ||
p={ 2 } | ||
ref={ textInput } | ||
keyboardType="web-search" | ||
blurOnSubmit={ true } | ||
autoCorrect={ false } | ||
InputRightElement={ | ||
<IconButton | ||
_icon={ { as: FontAwesome5, name: 'times' } } | ||
onPress={ () => { | ||
setQuery(null) | ||
textInput.current.clear() | ||
textInput.current.blur() | ||
} } | ||
/> | ||
} | ||
onChangeText={ _.debounce(setQuery, 350) } | ||
placeholder={ t('RESTAURANT_SEARCH_ORDERS_INPUT_PLACEHOLDER') } | ||
/> | ||
</FormControl> | ||
<FlatList | ||
data={ filteredOrders } | ||
keyExtractor={ (item, index) => item['@id'] } | ||
renderItem={ ({ item }) => ( | ||
<OrderListItem | ||
order={ item } | ||
onItemClick={ order => | ||
navigation.navigate('RestaurantOrder', { order }) | ||
} | ||
/> | ||
) } | ||
/> | ||
</BasicSafeAreaView> | ||
) | ||
} |
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
Oops, something went wrong.