| 1 |
import { localStorageSyncedStore } from "../lib/store"; |
| 2 |
import { array, string } from "../lib/validation"; |
| 3 |
|
| 4 |
const { update, set, subscribe } = localStorageSyncedStore( |
| 5 |
"query-history", |
| 6 |
array(string), |
| 7 |
() => [], |
| 8 |
); |
| 9 |
|
| 10 |
/** The query shell history. */ |
| 11 |
export const query_shell_history = { |
| 12 |
subscribe, |
| 13 |
/** Completely clear the history. */ |
| 14 |
clear(): void { |
| 15 |
set([]); |
| 16 |
}, |
| 17 |
/** Add a new entry to the query history (this does avoid duplicates). */ |
| 18 |
add(query: string): void { |
| 19 |
if (query) { |
| 20 |
update((hist) => [...new Set([query, ...hist])]); |
| 21 |
} |
| 22 |
}, |
| 23 |
/** Remove a query string from the query history. */ |
| 24 |
remove(query: string): void { |
| 25 |
if (query) { |
| 26 |
update((hist) => hist.filter((item) => item !== query)); |
| 27 |
} |
| 28 |
}, |
| 29 |
}; |