1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 export class SearchService {
6 private recentQueries: string[] = this.getRecentQueries();
7 private savedQueries: string[] = this.getSavedQueries();
9 saveRecentQuery(query: string) {
10 if (this.recentQueries.length >= MAX_NUMBER_OF_RECENT_QUERIES) {
11 this.recentQueries.shift();
12 this.recentQueries.push(query);
14 this.recentQueries.push(query);
16 localStorage.setItem('recentQueries', JSON.stringify(this.recentQueries));
20 return JSON.parse(localStorage.getItem('recentQueries') || '[]') as string[];
23 saveQuery(query: string) {
24 this.savedQueries.push(query);
25 localStorage.setItem('savedQueries', JSON.stringify(this.savedQueries));
29 return JSON.parse(localStorage.getItem('savedQueries') || '[]') as string[];
32 deleteSavedQuery(id: number) {
33 this.savedQueries.splice(id, 1);
34 localStorage.setItem('savedQueries', JSON.stringify(this.savedQueries));
38 const MAX_NUMBER_OF_RECENT_QUERIES = 5;