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

recent_searches_service.js « services « filtered_search « javascripts « assets « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 3e402d5aed00609bd6e36c21cfcb158d55c998f1 (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
class RecentSearchesService {
  constructor(localStorageKey = 'issuable-recent-searches') {
    this.localStorageKey = localStorageKey;
  }

  fetch() {
    const input = window.localStorage.getItem(this.localStorageKey);

    let searches = [];
    if (input && input.length > 0) {
      try {
        searches = JSON.parse(input);
      } catch (err) {
        return Promise.reject(err);
      }
    }

    return Promise.resolve(searches);
  }

  save(searches = []) {
    window.localStorage.setItem(this.localStorageKey, JSON.stringify(searches));
  }
}

export default RecentSearchesService;