@@ -11,6 +11,7 @@ import Screen from './Screen';
11
11
import SelectableOptionRow from './SelectableOptionRow' ;
12
12
import ZulipTextIntl from './ZulipTextIntl' ;
13
13
import { createStyleSheet } from '../styles' ;
14
+ import { TranslationContext } from '../boot/TranslationProvider' ;
14
15
15
16
type Item < TKey > = $ReadOnly < { |
16
17
key : TKey ,
@@ -55,6 +56,8 @@ type Props<TItemKey> = $ReadOnly<{|
55
56
// variable. Better to offer this explicit, side-effect-free way for
56
57
// the data to flow where it should, when it should.
57
58
onRequestSelectionChange : ( itemKey : TItemKey , requestedValue : boolean ) => void ,
59
+
60
+ search ?: boolean ,
58
61
| } ,
59
62
> ,
60
63
| } > ;
@@ -82,7 +85,30 @@ export default function SelectableOptionsScreen<TItemKey: string | number>(
82
85
props: Props< TItemKey > ,
83
86
): Node {
84
87
const { route } = props;
85
- const { title , description , items , onRequestSelectionChange } = route.params;
88
+ const { title , description , items , onRequestSelectionChange , search } = route.params;
89
+
90
+ const _ = React.useContext(TranslationContext);
91
+
92
+ const [filter, setFilter] = React.useState('');
93
+ const filteredItems =
94
+ filter.trim() === ''
95
+ ? items
96
+ : items.filter(item => {
97
+ // TODO: Is this the best way to filter? Where `title` and
98
+ // `subtitle` are present, behavior is matched to the language
99
+ // picker.
100
+
101
+ /* eslint-disable prefer-template */
102
+ const itemData =
103
+ _ ( item . subtitle ?? { text : '{_}' , values : { _ : '' } } ) . toUpperCase ( )
104
+ + ' '
105
+ + _ ( item . title ?? { text : '{_}' , values : { _ : '' } } ) . toUpperCase ( ) ;
106
+ /* eslint-enable prefer-template */
107
+
108
+ const filterData = filter . toUpperCase ( ) ;
109
+
110
+ return itemData . includes ( filterData ) ;
111
+ } );
86
112
87
113
const styles = useMemo(
88
114
() =>
@@ -93,13 +119,13 @@ export default function SelectableOptionsScreen<TItemKey: string | number>(
93
119
);
94
120
95
121
return (
96
- < Screen title = { title } scrollEnabled >
122
+ < Screen title = { title } scrollEnabled search = { search } searchBarOnChange = { setFilter } >
97
123
{ description != null && (
98
124
< View style = { styles . descriptionWrapper } >
99
125
< ZulipTextIntl text = { description } />
100
126
</ View >
101
127
) }
102
- { items . map ( item => (
128
+ { filteredItems . map ( item => (
103
129
< SelectableOptionRow
104
130
key = { item . key }
105
131
itemKey = { item . key }
0 commit comments