From 9ca680f84285dc546c33455987c8bf77069ffe35 Mon Sep 17 00:00:00 2001 From: zadam Date: Wed, 20 Mar 2019 21:01:00 +0100 Subject: [PATCH] handle empty search note --- src/public/javascripts/services/note_detail_search.js | 2 -- src/public/javascripts/services/tree_builder.js | 11 +++++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/public/javascripts/services/note_detail_search.js b/src/public/javascripts/services/note_detail_search.js index 9ee52c9a6..9973a26a1 100644 --- a/src/public/javascripts/services/note_detail_search.js +++ b/src/public/javascripts/services/note_detail_search.js @@ -9,8 +9,6 @@ const $refreshButton = $('#note-detail-search-refresh-results-button'); function show() { $component.show(); - console.log(noteDetailService.getActiveNote()); - try { const json = JSON.parse(noteDetailService.getActiveNote().noteContent.content); diff --git a/src/public/javascripts/services/tree_builder.js b/src/public/javascripts/services/tree_builder.js index ac7aeed57..7dabd0a57 100644 --- a/src/public/javascripts/services/tree_builder.js +++ b/src/public/javascripts/services/tree_builder.js @@ -116,8 +116,19 @@ async function prepareRealBranch(parentNote) { async function prepareSearchBranch(note) { const fullNote = await noteDetailService.loadNote(note.noteId); + + console.log("ZZZ", fullNote.noteContent.content); + + if (!fullNote.noteContent.content || !fullNote.noteContent.content.trim()) { + return []; + } + const json = JSON.parse(fullNote.noteContent.content); + if (!json.searchString || !json.searchString.trim()) { + return []; + } + const results = (await server.get('search/' + encodeURIComponent(json.searchString))) .filter(res => res.noteId !== note.noteId); // this is necessary because title of the search note is often the same as the search text which would match and create circle