From 762202c4b0b604c6e2d19b641fc10beb502641d7 Mon Sep 17 00:00:00 2001 From: Hugh Rundle Date: Mon, 27 Sep 2021 11:03:41 +1000 Subject: [PATCH] fix UI for group curated list editing When creating or editing a list, the group selection dropdown will only appear if the user selects "group" as the curation option (or it is already selected). - fix typo in bookwyrm.js comments - add data-hides trigger for hiding elements after they have been unhidden, where simple toggles are not the right approach --- bookwyrm/static/js/bookwyrm.js | 30 ++++++++++++++--- bookwyrm/templates/lists/form.html | 52 +++++++++++++++--------------- 2 files changed, 52 insertions(+), 30 deletions(-) diff --git a/bookwyrm/static/js/bookwyrm.js b/bookwyrm/static/js/bookwyrm.js index f000fd082..049de497c 100644 --- a/bookwyrm/static/js/bookwyrm.js +++ b/bookwyrm/static/js/bookwyrm.js @@ -28,6 +28,12 @@ let BookWyrm = new class { this.revealForm.bind(this)) ); + document.querySelectorAll('[data-hides]') + .forEach(button => button.addEventListener( + 'change', + this.hideForm.bind(this)) + ); + document.querySelectorAll('[data-back]') .forEach(button => button.addEventListener( 'click', @@ -119,7 +125,7 @@ let BookWyrm = new class { } /** - * Toggle form. + * Show form. * * @param {Event} event * @return {undefined} @@ -127,10 +133,26 @@ let BookWyrm = new class { revealForm(event) { let trigger = event.currentTarget; let hidden = trigger.closest('.hidden-form').querySelectorAll('.is-hidden')[0]; - - this.addRemoveClass(hidden, 'is-hidden', !hidden); + // if the form has already been revealed, there is no '.is-hidden' element + // so this doesn't really work as a toggle + if (hidden) { + this.addRemoveClass(hidden, 'is-hidden', !hidden); + } } + /** + * Hide form. + * + * @param {Event} event + * @return {undefined} + */ + hideForm(event) { + let trigger = event.currentTarget; + let targetId = trigger.dataset.hides + let visible = document.getElementById(targetId) + this.addRemoveClass(visible, 'is-hidden', true); + } + /** * Execute actions on targets based on triggers. * @@ -227,7 +249,7 @@ let BookWyrm = new class { } /** - * Check or uncheck a checbox. + * Check or uncheck a checkbox. * * @param {string} checkbox - id of the checkbox * @param {boolean} pressed - Is the trigger pressed? diff --git a/bookwyrm/templates/lists/form.html b/bookwyrm/templates/lists/form.html index d2f17d63b..a98cae94a 100644 --- a/bookwyrm/templates/lists/form.html +++ b/bookwyrm/templates/lists/form.html @@ -18,45 +18,45 @@
{% trans "List curation:" %} -