Skip to content

Commit

Permalink
Merge pull request #868 from LiskHQ/857-search-delegate-autosuggest-r…
Browse files Browse the repository at this point in the history
…edux-store

Provide actions reducers for autosuggest search - Closes #857
  • Loading branch information
faival committed Jun 7, 2018
2 parents 62f4de7 + d25abe0 commit 1c7d11b
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 1 deletion.
2 changes: 2 additions & 0 deletions karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ module.exports = function (config) {
'src/components/register/register.js',
'src/components/voteUrlProcessor/index.js',
'src/utils/api/liskService.js',
'src/store/reducers/liskService.js',
'src/store/reducers/search.js',
'src/components/errorBoundary/index.js',
],
overrides: {
Expand Down
13 changes: 13 additions & 0 deletions src/actions/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import actionTypes from '../constants/actions';
import { loadingStarted, loadingFinished } from '../utils/loading';
import { transactions, getAccount } from '../utils/api/account';
import { getDelegate, getVoters, getVotes } from '../utils/api/delegate';
import { searchAll } from '../utils/api/search';

const searchDelegate = ({ activePeer, publicKey, address }) =>
(dispatch) => {
Expand Down Expand Up @@ -97,3 +98,15 @@ export const searchMoreTransactions = ({
});
});
};

export const searchSuggestions = ({ activePeer, searchTerm }) =>
(dispatch) => {
dispatch({
data: {},
type: actionTypes.searchClearSuggestions,
});
searchAll({ activePeer, searchTerm }).then(response => dispatch({
data: response,
type: actionTypes.searchSuggestions,
}));
};
1 change: 0 additions & 1 deletion src/components/autoSuggest/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import i18n from '../../i18n';
import styles from './autoSuggest.css';

import * as searchActions from './../search/keyAction';

import routes from '../../constants/routes';
import keyCodes from './../../constants/keyCodes';
import mockSearchResults from './searchResults.mock';
Expand Down
2 changes: 2 additions & 0 deletions src/constants/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ const actionTypes = {
clearDataOfCurrencyGraph: 'CLEAR_DATA_OF_CURRENCY_GRAPH',
loadingStarted: 'LOADING_STARTED',
loadingFinished: 'LOADING_FINISHED',
searchSuggestions: 'SEARCH_SUGGESTIONS',
searchClearSuggestions: 'SEARCH_CLEAR_SUGGESTIONS',
searchTransactions: 'SEARCH_TRANSACTIONS',
searchMoreTransactions: 'SEARCH_MORE_TRANSACTIONS',
searchAccount: 'SEARCH_ACCOUNT',
Expand Down
12 changes: 12 additions & 0 deletions src/store/reducers/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,18 @@ const search = (state = {
[action.data.address]: action.data.voters,
},
};
case actionTypes.searchSuggestions:
return {
...state,
suggestions: {
...action.data,
},
};
case actionTypes.searchClearSuggestions:
return {
...state,
suggestions: {},
};
default:
return state;
}
Expand Down

0 comments on commit 1c7d11b

Please sign in to comment.