cr changes
[arvados-workbench2.git] / src / services / search-service / search-service.ts
index 1fc61dd2199366c2e64b30c36da3c8d5a93dc192..f9392c237a1c46387f49891201e493ca9490cbb3 100644 (file)
@@ -2,11 +2,12 @@
 //
 // SPDX-License-Identifier: AGPL-3.0
 
-export class SearchQueriesService {
+export class SearchService {
     private recentQueries: string[] = this.getRecentQueries();
+    private savedQueries: string[] = this.getSavedQueries();
 
     saveRecentQuery(query: string) {
-        if (this.recentQueries.length >= 5) {
+        if (this.recentQueries.length >= MAX_NUMBER_OF_RECENT_QUERIES) {
             this.recentQueries.shift();
             this.recentQueries.push(query);
         } else {
@@ -18,4 +19,20 @@ export class SearchQueriesService {
     getRecentQueries() {
         return JSON.parse(localStorage.getItem('recentQueries') || '[]') as string[];
     }
-}
\ No newline at end of file
+
+    saveQuery(query: string) {
+        this.savedQueries.push(query);
+        localStorage.setItem('savedQueries', JSON.stringify(this.savedQueries));
+    }
+
+    getSavedQueries() {
+        return JSON.parse(localStorage.getItem('savedQueries') || '[]') as string[];
+    }
+
+    deleteSavedQuery(id: number) {
+        this.savedQueries.splice(id, 1);
+        localStorage.setItem('savedQueries', JSON.stringify(this.savedQueries));
+    }
+}
+
+const MAX_NUMBER_OF_RECENT_QUERIES = 5;
\ No newline at end of file