Fix inifite render loop
[arvados-workbench2.git] / src / services / search-service / search-service.ts
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 export class SearchService {
6     private recentQueries: string[] = this.getRecentQueries();
7     private savedQueries: string[] = this.getSavedQueries();
8
9     saveRecentQuery(query: string) {
10         if (this.recentQueries.length >= MAX_NUMBER_OF_RECENT_QUERIES) {
11             this.recentQueries.shift();
12             this.recentQueries.push(query);
13         } else {
14             this.recentQueries.push(query);
15         }
16         localStorage.setItem('recentQueries', JSON.stringify(this.recentQueries));
17     }
18
19     getRecentQueries() {
20         return JSON.parse(localStorage.getItem('recentQueries') || '[]') as string[];
21     }
22
23     saveQuery(query: string) {
24         this.savedQueries.push(query);
25         localStorage.setItem('savedQueries', JSON.stringify(this.savedQueries));
26     }
27
28     getSavedQueries() {
29         return JSON.parse(localStorage.getItem('savedQueries') || '[]') as string[];
30     }
31
32     deleteSavedQuery(id: number) {
33         this.savedQueries.splice(id, 1);
34         localStorage.setItem('savedQueries', JSON.stringify(this.savedQueries));
35     }
36 }
37
38 const MAX_NUMBER_OF_RECENT_QUERIES = 5;