Welcome to mirror list, hosted at ThFree Co, Russian Federation.

recent_searches_store.js « stores « filtered_search « javascripts « assets « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: cdbc9ec84bd004faa0936bbdc43b6fe6c43e3610 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import { uniq } from 'lodash';

class RecentSearchesStore {
  constructor(initialState = {}, allowedKeys) {
    this.state = {
      isLocalStorageAvailable: true,
      recentSearches: [],
      allowedKeys,
      ...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;