From 47d5b907ac53ba90db1e5b6c72670499f4bb814b Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Sun, 17 Jan 2021 10:10:59 -0800 Subject: [PATCH] Readthrough interactions --- bookwyrm/static/css/format.css | 2 +- bookwyrm/static/js/shared.js | 27 ++++-- .../templates/snippets/components/modal.html | 23 +++++ .../snippets/delete_readthrough_modal.html | 13 +++ .../snippets/finish_reading_modal.html | 87 ++++++++++--------- bookwyrm/templates/snippets/readthrough.html | 63 ++++---------- .../templates/snippets/shelve_button.html | 10 ++- .../snippets/start_reading_modal.html | 70 +++++++-------- .../snippets/toggle/close_button.html | 1 + .../snippets/toggle/open_button.html | 1 + .../snippets/toggle/toggle_button.html | 2 +- 11 files changed, 165 insertions(+), 134 deletions(-) create mode 100644 bookwyrm/templates/snippets/components/modal.html create mode 100644 bookwyrm/templates/snippets/delete_readthrough_modal.html create mode 100644 bookwyrm/templates/snippets/toggle/close_button.html create mode 100644 bookwyrm/templates/snippets/toggle/open_button.html diff --git a/bookwyrm/static/css/format.css b/bookwyrm/static/css/format.css index f08f6739..69ac202d 100644 --- a/bookwyrm/static/css/format.css +++ b/bookwyrm/static/css/format.css @@ -18,7 +18,7 @@ background-color: hsl(171, 100%, 41%); color: white; } -.hide-active[aria-pressed=true] { +.hide-active[aria-pressed=true], .hide-active { display: none; } diff --git a/bookwyrm/static/js/shared.js b/bookwyrm/static/js/shared.js index e7b87dd8..f4b9a588 100644 --- a/bookwyrm/static/js/shared.js +++ b/bookwyrm/static/js/shared.js @@ -60,13 +60,14 @@ function toggleAction(e) { if (targetId) { var target = document.getElementById(targetId); - if (pressed) { - removeClass(target, 'hidden'); - addClass(target, 'is-active'); - } else { - addClass(target, 'hidden'); - removeClass(target, 'is-active'); - } + addRemoveClass(target, 'hidden', !pressed); + addRemoveClass(target, 'is-active', pressed); + } + + // show/hide container + var container = document.getElementById('hide-' + targetId); + if (!!container) { + addRemoveClass(container, 'hidden', pressed); } // set checkbox, if appropriate @@ -82,13 +83,23 @@ function toggleAction(e) { } } +function addRemoveClass(el, classname, bool) { + if (bool) { + addClass(el, classname) + } else { + removeClass(el, classname) + } +} function addClass(el, classname) { el.className = el.className.split(' ').concat(classname).join(' '); } function removeClass(el, className) { - var classes = el.className.split(' '); + var classes = [] + if (el.className) { + var classes = el.className.split(' '); + } const idx = classes.indexOf(className); if (idx > -1) { classes.splice(idx, 1); diff --git a/bookwyrm/templates/snippets/components/modal.html b/bookwyrm/templates/snippets/components/modal.html new file mode 100644 index 00000000..63db1168 --- /dev/null +++ b/bookwyrm/templates/snippets/components/modal.html @@ -0,0 +1,23 @@ + + diff --git a/bookwyrm/templates/snippets/delete_readthrough_modal.html b/bookwyrm/templates/snippets/delete_readthrough_modal.html new file mode 100644 index 00000000..1456cc76 --- /dev/null +++ b/bookwyrm/templates/snippets/delete_readthrough_modal.html @@ -0,0 +1,13 @@ +{% extends 'snippets/components/modal.html' %} +{% block modal-title %}Delete this read-though?{% endblock %} + +{% block modal-footer %} +
+ {% csrf_token %} + + + {% include 'snippets/toggle/toggle_button.html' with text="Cancel" controls_text="delete-readthrough" controls_uid=readthrough.id %} +
+{% endblock %} diff --git a/bookwyrm/templates/snippets/finish_reading_modal.html b/bookwyrm/templates/snippets/finish_reading_modal.html index cce89092..10af1162 100644 --- a/bookwyrm/templates/snippets/finish_reading_modal.html +++ b/bookwyrm/templates/snippets/finish_reading_modal.html @@ -1,45 +1,46 @@ -{% load bookwyrm_tags %} - -{% include 'snippets/start_reading_modal.html' with book=active_shelf.book %} -{% include 'snippets/finish_reading_modal.html' with book=active_shelf.book %} + +{% include 'snippets/start_reading_modal.html' with book=active_shelf.book controls_text="start-reading" controls_uid=uuid %} + +{% latest_read_through book request.user as readthrough %} +{% include 'snippets/finish_reading_modal.html' with book=active_shelf.book controls_text="finish-reading" controls_uid=uuid readthrough=readthrough %} + {% endwith %} {% endif %} diff --git a/bookwyrm/templates/snippets/start_reading_modal.html b/bookwyrm/templates/snippets/start_reading_modal.html index 267c70f7..50724e11 100644 --- a/bookwyrm/templates/snippets/start_reading_modal.html +++ b/bookwyrm/templates/snippets/start_reading_modal.html @@ -1,36 +1,38 @@ -