diff --git a/dist/index.js b/dist/index.js index 31e7f464..f76ae792 100644 --- a/dist/index.js +++ b/dist/index.js @@ -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(); diff --git a/src/ViewModel/Pages/boardViewModel.ts b/src/ViewModel/Pages/boardViewModel.ts index 528c7e7a..ea9ffc79 100644 --- a/src/ViewModel/Pages/boardViewModel.ts +++ b/src/ViewModel/Pages/boardViewModel.ts @@ -54,6 +54,10 @@ export default class BoardViewModel extends TaskContainingPageViewModel { return [...this.getBasePath(), BoardViewModelSubPath.PreviousSearches]; }; + getLastSearchPath = (): string[] => { + return [...this.getBasePath(), BoardViewModelSubPath.LastSearch]; + }; + // settings saveSettings = (): void => { const newBoardInfoFileContent: BoardInfoFileContent = @@ -106,12 +110,18 @@ export default class BoardViewModel extends TaskContainingPageViewModel { this.selectedPage.value = lastUsedView as BoardPageType; }; - storeSearchTerm = (searchTerm: string): void => { - const path: string[] = [...this.getPreviousSearchesPath(), searchTerm]; - this.storageModel.write(path, ""); + handleNewSearch = (searchTerm: string): void => { + const suggestionPath: string[] = [ + ...this.getPreviousSearchesPath(), + searchTerm, + ]; + this.storageModel.write(suggestionPath, ""); if (!this.searchSuggestions.value.has(searchTerm)) { this.searchSuggestions.add(searchTerm); } + + const lastSearchPath: string[] = this.getLastSearchPath(); + this.storageModel.write(lastSearchPath, searchTerm); }; // view @@ -205,6 +215,12 @@ export default class BoardViewModel extends TaskContainingPageViewModel { const dirPath: string[] = this.getPreviousSearchesPath(); const searches: string[] = this.storageModel.list(dirPath); this.searchSuggestions.add(...searches); + + const lastSearchPath: string[] = this.getLastSearchPath(); + const lastSearch: string | null = this.storageModel.read(lastSearchPath); + if (lastSearch) { + this.searchViewModel.search(lastSearch); + } }; loadData = (): void => { @@ -264,8 +280,8 @@ export default class BoardViewModel extends TaskContainingPageViewModel { TaskViewModel.getStringsForFilter, this.searchSuggestions ); - this.searchViewModel.appliedQuery.subscribe((newQuery) => { - this.storeSearchTerm(newQuery); + this.searchViewModel.appliedQuery.subscribeSilent((newQuery) => { + this.handleNewSearch(newQuery); }); } } @@ -273,6 +289,7 @@ export default class BoardViewModel extends TaskContainingPageViewModel { export enum BoardViewModelSubPath { LastUsedView = "last-used-view", PreviousSearches = "previous-searches", + LastSearch = "last-search", } // types