From 739b6e19e2202ffd3b737f93b69bebdde82c9714 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Sat, 16 Jan 2021 09:21:19 -0800 Subject: [PATCH] Dismiss reading goal using localstorage --- bookwyrm/static/js/shared.js | 29 ++++++++++++++++++- bookwyrm/templates/feed.html | 8 ++--- .../snippets/start_reading_modal.html | 4 +-- 3 files changed, 34 insertions(+), 7 deletions(-) diff --git a/bookwyrm/static/js/shared.js b/bookwyrm/static/js/shared.js index de6d44f99..b2de57368 100644 --- a/bookwyrm/static/js/shared.js +++ b/bookwyrm/static/js/shared.js @@ -21,11 +21,38 @@ window.onload = function() { // handle aria settings on menus Array.from(document.getElementsByClassName('pulldown-menu')) .forEach(t => t.onclick = toggleMenu); + + // display based on localstorage vars + document.querySelectorAll('[data-hide]') + .forEach(t => setDisplay(t)); + + // update localstorage + Array.from(document.getElementsByClassName('set-display')) + .forEach(t => t.onclick = updateDisplay); }; +function updateDisplay(e) { + var key = e.target.getAttribute('data-id'); + var value = e.target.getAttribute('data-value'); + window.localStorage.setItem(key, value); + + document.querySelectorAll('[data-hide="' + key + '"]') + .forEach(t => setDisplay(t)); +} + +function setDisplay(el) { + var key = el.getAttribute('data-hide'); + var value = window.localStorage.getItem(key) + if (!value) { + el.className = el.className.replace('hidden', ''); + } else if (value != null && !!value) { + el.className += ' hidden'; + } +} + function toggleAction(e) { // set hover, if appropriate - var hover = e.target.getAttribute('data-hover-target') + var hover = e.target.getAttribute('data-hover-target'); if (hover) { document.getElementById(hover).focus(); } diff --git a/bookwyrm/templates/feed.html b/bookwyrm/templates/feed.html index 7448a31bc..b37c6b74b 100644 --- a/bookwyrm/templates/feed.html +++ b/bookwyrm/templates/feed.html @@ -95,8 +95,8 @@ {# announcements and system messages #} {% if not goal and tab == 'home' %} -
- {% now 'Y' as year %} + {% now 'Y' as year %} +
+
{% endif %} -
{# activity feed #} {% if not activities %} diff --git a/bookwyrm/templates/snippets/start_reading_modal.html b/bookwyrm/templates/snippets/start_reading_modal.html index 796f09844..be0ed7064 100644 --- a/bookwyrm/templates/snippets/start_reading_modal.html +++ b/bookwyrm/templates/snippets/start_reading_modal.html @@ -20,8 +20,8 @@