remember last used search in boards

This commit is contained in:
marlon-erler
2024-07-27 03:50:56 +02:00
parent 845a9d2f35
commit 461f607444
2 changed files with 40 additions and 10 deletions
+18 -5
View File
@@ -2100,8 +2100,8 @@
TaskViewModel.getStringsForFilter,
this.searchSuggestions
);
this.searchViewModel.appliedQuery.subscribe((newQuery) => {
this.storeSearchTerm(newQuery);
this.searchViewModel.appliedQuery.subscribeSilent((newQuery) => {
this.handleNewSearch(newQuery);
});
}
storageModel;
@@ -2132,6 +2132,9 @@
getPreviousSearchesPath = () => {
return [...this.getBasePath(), "previous-searches" /* PreviousSearches */];
};
getLastSearchPath = () => {
return [...this.getBasePath(), "last-search" /* LastSearch */];
};
// settings
saveSettings = () => {
const newBoardInfoFileContent = BoardsAndTasksModel.createBoardInfoFileContent(
@@ -2174,12 +2177,17 @@
if (lastUsedView == null) return;
this.selectedPage.value = lastUsedView;
};
storeSearchTerm = (searchTerm) => {
const path = [...this.getPreviousSearchesPath(), searchTerm];
this.storageModel.write(path, "");
handleNewSearch = (searchTerm) => {
const suggestionPath = [
...this.getPreviousSearchesPath(),
searchTerm
];
this.storageModel.write(suggestionPath, "");
if (!this.searchSuggestions.value.has(searchTerm)) {
this.searchSuggestions.add(searchTerm);
}
const lastSearchPath = this.getLastSearchPath();
this.storageModel.write(lastSearchPath, searchTerm);
};
// view
showTask = (taskFileContent) => {
@@ -2254,6 +2262,11 @@
const dirPath = this.getPreviousSearchesPath();
const searches = this.storageModel.list(dirPath);
this.searchSuggestions.add(...searches);
const lastSearchPath = this.getLastSearchPath();
const lastSearch = this.storageModel.read(lastSearchPath);
if (lastSearch) {
this.searchViewModel.search(lastSearch);
}
};
loadData = () => {
this.restoreLastUsedView();