Dismiss reading goal using localstorage

This commit is contained in:
Mouse Reeve 2021-01-16 09:21:19 -08:00
parent 11ea829657
commit 739b6e19e2
3 changed files with 34 additions and 7 deletions

View file

@ -21,11 +21,38 @@ window.onload = function() {
// handle aria settings on menus // handle aria settings on menus
Array.from(document.getElementsByClassName('pulldown-menu')) Array.from(document.getElementsByClassName('pulldown-menu'))
.forEach(t => t.onclick = toggleMenu); .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) { function toggleAction(e) {
// set hover, if appropriate // set hover, if appropriate
var hover = e.target.getAttribute('data-hover-target') var hover = e.target.getAttribute('data-hover-target');
if (hover) { if (hover) {
document.getElementById(hover).focus(); document.getElementById(hover).focus();
} }

View file

@ -95,8 +95,8 @@
{# announcements and system messages #} {# announcements and system messages #}
{% if not goal and tab == 'home' %} {% if not goal and tab == 'home' %}
<section class="block" aria-title="Announcements">
{% now 'Y' as year %} {% now 'Y' as year %}
<section class="block hidden" aria-title="Announcements" data-hide="hide-{{ year }}-reading-goal">
<article class="card"> <article class="card">
<header class="card-header"> <header class="card-header">
<h3 class="card-header-title has-background-primary has-text-white"> <h3 class="card-header-title has-background-primary has-text-white">
@ -110,14 +110,14 @@
</section> </section>
<footer class="card-footer has-background-white-bis"> <footer class="card-footer has-background-white-bis">
<div class="card-footer-item is-flex-direction-column"> <div class="card-footer-item is-flex-direction-column">
<button class="button is-danger is-light is-block">Dismiss message</button> <button class="button is-danger is-light is-block set-display" data-id="hide-{{ year }}-reading-goal" data-value="true">Dismiss message</button>
<p class="help">You can set or change your reading goal any time from your <a href="{{ request.user.local_path }}">profile page</a></p> <p class="help">You can set or change your reading goal any time from your <a href="{{ request.user.local_path }}">profile page</a></p>
</div> </div>
</footer> </footer>
</article> </article>
<hr>
</section> </section>
{% endif %} {% endif %}
<hr>
{# activity feed #} {# activity feed #}
{% if not activities %} {% if not activities %}

View file

@ -20,8 +20,8 @@
<footer class="modal-card-foot"> <footer class="modal-card-foot">
<div class="columns"> <div class="columns">
<div class="column field"> <div class="column field">
<label for="post_status-{{ uuid }}"> <label for="post_status_start-{{ uuid }}">
<input type="checkbox" name="post-status" class="checkbox" id="post_status-{{ uuid }}" checked> <input type="checkbox" name="post-status" class="checkbox" id="post_status_start-{{ uuid }}" checked>
Post to feed Post to feed
</label> </label>
{% include 'snippets/privacy_select.html' %} {% include 'snippets/privacy_select.html' %}