Skip to content

Build your personal knowledge base with Trilium Notes

created a specific widget for search result to add "no results" message

zadamc94fb7a62de9
diff --git a/src/public/app/layouts/desktop_extra_window_layout.js b/src/public/app/layouts/desktop_extra_window_layout.js
index aef4df0da8..b89b976e4b 100644
--- a/src/public/app/layouts/desktop_extra_window_layout.js
+++ b/src/public/app/layouts/desktop_extra_window_layout.js
@@ -22,6 +22,7 @@ import ImagePropertiesWidget from "../widgets/type_property_widgets/image_proper
import NotePropertiesWidget from "../widgets/type_property_widgets/note_properties.js";
import NoteIconWidget from "../widgets/note_icon.js";
import NotePathsWidget from "../widgets/note_paths.js";
+import SearchResultWidget from "../widgets/search_result.js";
export default class DesktopExtraWindowLayout {
constructor(customWidgets) {
@@ -69,6 +70,7 @@ export default class DesktopExtraWindowLayout {
.child(new TabCachingWidget(() => new SqlTableSchemasWidget()))
.child(new TabCachingWidget(() => new NoteDetailWidget()))
.child(new TabCachingWidget(() => new NoteListWidget()))
+ .child(new TabCachingWidget(() => new SearchResultWidget()))
.child(new TabCachingWidget(() => new SqlResultWidget()))
)
.child(...this.customWidgets.get('center-pane'))
diff --git a/src/public/app/layouts/desktop_main_window_layout.js b/src/public/app/layouts/desktop_main_window_layout.js
index 663a7bfe9f..37286d9c2b 100644
--- a/src/public/app/layouts/desktop_main_window_layout.js
+++ b/src/public/app/layouts/desktop_main_window_layout.js
@@ -32,6 +32,7 @@ import FilePropertiesWidget from "../widgets/type_property_widgets/file_properti
import ImagePropertiesWidget from "../widgets/type_property_widgets/image_properties.js";
import NotePropertiesWidget from "../widgets/type_property_widgets/note_properties.js";
import NoteIconWidget from "../widgets/note_icon.js";
+import SearchResultWidget from "../widgets/search_result.js";
const RIGHT_PANE_CSS = `
<style>
@@ -179,6 +180,7 @@ export default class DesktopMainWindowLayout {
.child(new TabCachingWidget(() => new SqlTableSchemasWidget()))
.child(new TabCachingWidget(() => new NoteDetailWidget()))
.child(new TabCachingWidget(() => new NoteListWidget()))
+ .child(new TabCachingWidget(() => new SearchResultWidget()))
.child(new TabCachingWidget(() => new SqlResultWidget()))
)
.child(new TabCachingWidget(() => new SimilarNotesWidget()))
diff --git a/src/public/app/services/tree_cache.js b/src/public/app/services/tree_cache.js
index 6e2e67dd3c..2614f23ef7 100644
--- a/src/public/app/services/tree_cache.js
+++ b/src/public/app/services/tree_cache.js
@@ -195,6 +195,8 @@ class TreeCache {
branches,
attributes: []
});
+
+ treeCache.notes[note.noteId].searchResultsLoaded = true;
}
}
diff --git a/src/public/app/widgets/note_list.js b/src/public/app/widgets/note_list.js
index e61170a332..73af0ba076 100644
--- a/src/public/app/widgets/note_list.js
+++ b/src/public/app/widgets/note_list.js
@@ -23,11 +23,9 @@ const TPL = `
export default class NoteListWidget extends TabAwareWidget {
isEnabled() {
return super.isEnabled()
+ && ['book', 'text', 'code'].includes(this.note.type)
&& this.note.mime !== 'text/x-sqlite;schema=trilium'
- && (
- ['book', 'search', 'code'].includes(this.note.type)
- || (this.note.type === 'text' && this.note.hasChildren())
- )
+ && this.note.hasChildren()
&& !this.note.hasLabel('hideChildrenOverview');
}
@@ -89,17 +87,6 @@ export default class NoteListWidget extends TabAwareWidget {
setTimeout(() => this.checkRenderStatus(), 100);
}
- searchRefreshedEvent({tabId}) {
- if (!this.isTab(tabId)) {
- return;
- }
-
- this.noteIdRefreshed = this.noteId;
- this.shownNoteId = null;
-
- this.checkRenderStatus();
- }
-
notesReloadedEvent({noteIds}) {
if (noteIds.includes(this.noteId)) {
this.refresh();
diff --git a/src/public/app/widgets/search_result.js b/src/public/app/widgets/search_result.js
new file mode 100644
index 0000000000..22a273121b
--- /dev/null
+++ b/src/public/app/widgets/search_result.js
@@ -0,0 +1,72 @@
+import TabAwareWidget from "./tab_aware_widget.js";
+import NoteListRenderer from "../services/note_list_renderer.js";
+
+const TPL = `
+<div class="search-result-widget">
+ <style>
+ .search-result-widget {
+ flex-grow: 100000;
+ flex-shrink: 100000;
+ min-height: 0;
+ overflow: auto;
+ }
+
+ .search-result-widget .note-list {
+ padding: 10px;
+ }
+
+ .search-no-results, .search-not-executed-yet {
+ margin: 20px;
+ padding: 20px;
+ }
+ </style>
+
+ <div class="search-no-results alert alert-info">
+ No notes have been found for given search parameters.
+ </div>
+
+ <div class="search-not-executed-yet alert alert-info">
+ Search has not been executed yet. Click on "Search" button above to see the results.
+ </div>
+
+ <div class="search-result-widget-content">
+ </div>
+</div>`;
+
+export default class SearchResultWidget extends TabAwareWidget {
+ isEnabled() {
+ return super.isEnabled()
+ && this.note.type === 'search';
+ }
+
+ doRender() {
+ this.$widget = $(TPL);
+ this.$content = this.$widget.find('.search-result-widget-content');
+ this.$noResults = this.$widget.find('.search-no-results');
+ this.$notExecutedYet = this.$widget.find('.search-not-executed-yet');
+ this.contentSized();
+ }
+
+ async refreshWithNote(note) {
+ this.$content.empty();
+ this.$noResults.toggle(note.getChildNoteIds().length === 0 && !!note.searchResultsLoaded);
+ this.$notExecutedYet.toggle(!note.searchResultsLoaded);
+
+ const noteListRenderer = new NoteListRenderer(this.$content, note, note.getChildNoteIds());
+ await noteListRenderer.renderList();
+ }
+
+ searchRefreshedEvent({tabId}) {
+ if (!this.isTab(tabId)) {
+ return;
+ }
+
+ this.refresh();
+ }
+
+ notesReloadedEvent({noteIds}) {
+ if (noteIds.includes(this.noteId)) {
+ this.refresh();
+ }
+ }
+}