2017-03-30 02:04:05 +00:00
|
|
|
import _ from 'underscore';
|
|
|
|
|
|
|
|
class RecentSearchesStore {
|
2017-05-23 16:35:54 +00:00
|
|
|
constructor(initialState = {}, allowedKeys) {
|
2017-03-30 02:04:05 +00:00
|
|
|
this.state = Object.assign({
|
2017-05-06 02:33:21 +00:00
|
|
|
isLocalStorageAvailable: true,
|
2017-03-30 02:04:05 +00:00
|
|
|
recentSearches: [],
|
2017-05-23 16:35:54 +00:00
|
|
|
allowedKeys,
|
2017-03-30 02:04:05 +00:00
|
|
|
}, initialState);
|
|
|
|
}
|
|
|
|
|
|
|
|
addRecentSearch(newSearch) {
|
|
|
|
this.setRecentSearches([newSearch].concat(this.state.recentSearches));
|
|
|
|
|
|
|
|
return this.state.recentSearches;
|
|
|
|
}
|
|
|
|
|
|
|
|
setRecentSearches(searches = []) {
|
|
|
|
const trimmedSearches = searches.map(search => search.trim());
|
|
|
|
this.state.recentSearches = _.uniq(trimmedSearches).slice(0, 5);
|
|
|
|
return this.state.recentSearches;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default RecentSearchesStore;
|