Skip to content

Commit

Permalink
#23 release/v0.5;
Browse files Browse the repository at this point in the history
- fix redundant autosearch hide item logic;
  • Loading branch information
eddielee394 committed Nov 8, 2019
1 parent 83682c8 commit 9e8776e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 18 deletions.
7 changes: 2 additions & 5 deletions app/components/Search/SearchContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,7 @@ function SearchContainer() {
const handleWatchlistIconStyles = symbol => {
return includes(symbols, symbol) ? styles.negative : styles.positive;
};

const handleHideResults = results.length < 1 || query === '';


const renderWatchlistIcon = symbol => {
return includes(symbols, symbol)
? 'md-remove-circle-outline'
Expand All @@ -80,7 +78,7 @@ function SearchContainer() {
<Body style={styles.bodyContainer}>
<Text numberOfLines={2}>{companyName}</Text>
</Body>
<View styl={styles.rightContainer}>
<View style={styles.rightContainer}>
<TouchableOpacity onPress={() => handleAddToWatchlist(symbol)}>
<Icon
name={renderWatchlistIcon(symbol)}
Expand All @@ -101,7 +99,6 @@ function SearchContainer() {
data={results}
renderTextInput={_renderInput}
defaultValue={query}
hideResults={handleHideResults}
onChangeText={handleSearch}
placeholder="Enter symbol"
renderItem={_renderListItem}
Expand Down
26 changes: 13 additions & 13 deletions app/components/Search/store/reducers/search.reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,26 @@ const symbolsReducer = (state = initialState, action) => {
switch (action.type) {
case Actions.GET_SYMBOLS:
return { ...state, isLoading: true };

case Actions.GET_SYMBOLS_SUCCESS:
return { ...state, symbols: action.payload, isLoading: false };

case Actions.GET_SYMBOLS_ERROR:
return { ...state, isLoading: true, error: action.payload };

case Actions.GET_RESULTS:
let results;
if (action.query === '') {
results = [];
} else {
results = state.symbols
.filter(d =>
d.symbol.toLowerCase().startsWith(action.query.toLowerCase()),
)
.slice(0, 20);
}

action.query === ''
? (results = [])
: (results = state.symbols
.filter(d =>
d.symbol.toLowerCase().startsWith(action.query.toLowerCase()),
)
.slice(0, 20));

return { ...state, results: results };

default:
return state;
}
Expand Down

0 comments on commit 9e8776e

Please sign in to comment.