move board search suggestions to CoreViewModel

This commit is contained in:
marlon-erler
2024-07-27 15:31:45 +02:00
parent 5a961b0f74
commit 644a0ad2fa
3 changed files with 15 additions and 10 deletions
+7 -5
View File
@@ -2104,7 +2104,7 @@
this.taskViewModels, this.taskViewModels,
this.filteredTaskViewModels, this.filteredTaskViewModels,
TaskViewModel.getStringsForFilter, TaskViewModel.getStringsForFilter,
this.searchSuggestions this.coreViewModel.boardSearchSuggestions
); );
this.searchViewModel.appliedQuery.subscribeSilent((newQuery) => { this.searchViewModel.appliedQuery.subscribeSilent((newQuery) => {
this.handleNewSearch(newQuery); this.handleNewSearch(newQuery);
@@ -2127,7 +2127,6 @@
isPresentingFilterModal = new State(false); isPresentingFilterModal = new State(false);
searchViewModel; searchViewModel;
filteredTaskViewModels = new ListState(); filteredTaskViewModels = new ListState();
searchSuggestions = new ListState();
// paths // paths
getBasePath = () => { getBasePath = () => {
return [...this.taskPageViewModel.getBoardViewPath(this.boardInfo.fileId)]; return [...this.taskPageViewModel.getBoardViewPath(this.boardInfo.fileId)];
@@ -2189,8 +2188,8 @@
searchTerm searchTerm
]; ];
this.storageModel.write(suggestionPath, ""); this.storageModel.write(suggestionPath, "");
if (!this.searchSuggestions.value.has(searchTerm)) { if (!this.coreViewModel.boardSearchSuggestions.value.has(searchTerm)) {
this.searchSuggestions.add(searchTerm); this.coreViewModel.boardSearchSuggestions.add(searchTerm);
} }
const lastSearchPath = this.getLastSearchPath(); const lastSearchPath = this.getLastSearchPath();
this.storageModel.write(lastSearchPath, searchTerm); this.storageModel.write(lastSearchPath, searchTerm);
@@ -2267,7 +2266,7 @@
loadSearchSuggestions = () => { loadSearchSuggestions = () => {
const dirPath = this.getPreviousSearchesPath(); const dirPath = this.getPreviousSearchesPath();
const searches = this.storageModel.list(dirPath); const searches = this.storageModel.list(dirPath);
this.searchSuggestions.add(...searches); this.coreViewModel.boardSearchSuggestions.add(...searches);
const lastSearchPath = this.getLastSearchPath(); const lastSearchPath = this.getLastSearchPath();
const lastSearch = this.storageModel.read(lastSearchPath); const lastSearch = this.storageModel.read(lastSearchPath);
if (lastSearch) { if (lastSearch) {
@@ -4363,7 +4362,10 @@
// src/ViewModel/Global/coreViewModel.ts // src/ViewModel/Global/coreViewModel.ts
var CoreViewModel = class { var CoreViewModel = class {
// drag&drop
draggedObject = new State(void 0); draggedObject = new State(void 0);
// suggestions
boardSearchSuggestions = new ListState();
}; };
// src/View/Components/chatEntry.tsx // src/View/Components/chatEntry.tsx
+4
View File
@@ -1,5 +1,9 @@
import * as React from "bloatless-react"; import * as React from "bloatless-react";
export default class CoreViewModel { export default class CoreViewModel {
// drag&drop
draggedObject: React.State<any> = new React.State<any>(undefined); draggedObject: React.State<any> = new React.State<any>(undefined);
// suggestions
boardSearchSuggestions: React.ListState<string> = new React.ListState();
} }
+4 -5
View File
@@ -39,7 +39,6 @@ export default class BoardViewModel extends TaskContainingPageViewModel {
searchViewModel: SearchViewModel<TaskViewModel>; searchViewModel: SearchViewModel<TaskViewModel>;
filteredTaskViewModels: React.ListState<TaskViewModel> = filteredTaskViewModels: React.ListState<TaskViewModel> =
new React.ListState(); new React.ListState();
searchSuggestions: React.ListState<string> = new React.ListState();
// paths // paths
getBasePath = (): string[] => { getBasePath = (): string[] => {
@@ -116,8 +115,8 @@ export default class BoardViewModel extends TaskContainingPageViewModel {
searchTerm, searchTerm,
]; ];
this.storageModel.write(suggestionPath, ""); this.storageModel.write(suggestionPath, "");
if (!this.searchSuggestions.value.has(searchTerm)) { if (!this.coreViewModel.boardSearchSuggestions.value.has(searchTerm)) {
this.searchSuggestions.add(searchTerm); this.coreViewModel.boardSearchSuggestions.add(searchTerm);
} }
const lastSearchPath: string[] = this.getLastSearchPath(); const lastSearchPath: string[] = this.getLastSearchPath();
@@ -214,7 +213,7 @@ export default class BoardViewModel extends TaskContainingPageViewModel {
loadSearchSuggestions = (): void => { loadSearchSuggestions = (): void => {
const dirPath: string[] = this.getPreviousSearchesPath(); const dirPath: string[] = this.getPreviousSearchesPath();
const searches: string[] = this.storageModel.list(dirPath); const searches: string[] = this.storageModel.list(dirPath);
this.searchSuggestions.add(...searches); this.coreViewModel.boardSearchSuggestions.add(...searches);
const lastSearchPath: string[] = this.getLastSearchPath(); const lastSearchPath: string[] = this.getLastSearchPath();
const lastSearch: string | null = this.storageModel.read(lastSearchPath); const lastSearch: string | null = this.storageModel.read(lastSearchPath);
@@ -278,7 +277,7 @@ export default class BoardViewModel extends TaskContainingPageViewModel {
this.taskViewModels, this.taskViewModels,
this.filteredTaskViewModels, this.filteredTaskViewModels,
TaskViewModel.getStringsForFilter, TaskViewModel.getStringsForFilter,
this.searchSuggestions this.coreViewModel.boardSearchSuggestions
); );
this.searchViewModel.appliedQuery.subscribeSilent((newQuery) => { this.searchViewModel.appliedQuery.subscribeSilent((newQuery) => {
this.handleNewSearch(newQuery); this.handleNewSearch(newQuery);