From bb0ee0b36c7830a7b1a04b7307808ffa6b7ec5ea Mon Sep 17 00:00:00 2001 From: zadam Date: Mon, 26 Oct 2020 22:52:12 +0100 Subject: [PATCH] expand all / collapse all will re-render list instead of doing that manually --- src/public/app/services/note_list_renderer.js | 32 ++++--------------- 1 file changed, 6 insertions(+), 26 deletions(-) diff --git a/src/public/app/services/note_list_renderer.js b/src/public/app/services/note_list_renderer.js index abcd11b55..dd8711252 100644 --- a/src/public/app/services/note_list_renderer.js +++ b/src/public/app/services/note_list_renderer.js @@ -161,30 +161,20 @@ class NoteListRenderer { this.$noteList.find('.grid-view-button').on('click', () => this.toggleViewType('grid')); this.$noteList.find('.expand-children-button').on('click', async () => { - for (let i = 1; i < 30; i++) { // protection against infinite cycle - const $unexpandedCards = this.$noteList.find('.note-book-card:not(.expanded)'); - - if ($unexpandedCards.length === 0) { - break; - } - - await this.toggleCards($unexpandedCards, true); - - if (!this.parentNote.hasLabel('expanded')) { - await attributeService.addLabel(this.parentNote.noteId, 'expanded'); - } + if (!this.parentNote.hasLabel('expanded')) { + await attributeService.addLabel(this.parentNote.noteId, 'expanded'); } + + await this.renderList(); }); this.$noteList.find('.collapse-all-button').on('click', async () => { - const $expandedCards = this.$noteList.find('.note-book-card.expanded'); - - await this.toggleCards($expandedCards, false); - // owned is important - we shouldn't remove inherited expanded labels for (const expandedAttr of this.parentNote.getOwnedLabels('expanded')) { await attributeService.removeAttributeById(this.parentNote.noteId, expandedAttr.attributeId); } + + await this.renderList(); }); } @@ -253,16 +243,6 @@ class NoteListRenderer { } } - async toggleCards(cards, expand) { - for (const card of cards) { - const $card = $(card); - const noteId = $card.attr('data-note-id'); - const note = await treeCache.getNote(noteId); - - await this.toggleContent($card, note, expand); - } - } - // TODO: we should also render (promoted) attributes // FIXME: showing specific path might be necessary because of a match in the patch async renderNote(note, expand = false) {