#104 - Refactored search history to use IndexedDB

This commit is contained in:
Simon Cambier
2022-10-22 16:37:31 +02:00
parent 8696f1381d
commit 9eed978e8a
9 changed files with 75 additions and 72 deletions

View File

@@ -1,23 +0,0 @@
import { historyFilePath } from '../globals'
export let searchHistory: string[] = []
export async function loadSearchHistory(): Promise<void> {
if (await app.vault.adapter.exists(historyFilePath)) {
try {
searchHistory = JSON.parse(await app.vault.adapter.read(historyFilePath))
// Keep the last 100 searches
searchHistory = searchHistory.slice(0, 100)
} catch (e) {
console.trace('Could not load search history from the file')
console.error(e)
searchHistory = []
}
} else {
searchHistory = []
}
}
export async function saveSearchHistory(): Promise<void> {
await app.vault.adapter.write(historyFilePath, JSON.stringify(searchHistory))
}