diff --git a/bookwyrm/migrations/0037_auto_20210118_1954.py b/bookwyrm/migrations/0037_auto_20210118_1954.py new file mode 100644 index 00000000..9da0265d --- /dev/null +++ b/bookwyrm/migrations/0037_auto_20210118_1954.py @@ -0,0 +1,22 @@ +# Generated by Django 3.0.7 on 2021-01-18 19:54 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('bookwyrm', '0036_annualgoal'), + ] + + operations = [ + migrations.AlterModelOptions( + name='shelfbook', + options={'ordering': ('-created_date',)}, + ), + migrations.AlterField( + model_name='user', + name='email', + field=models.EmailField(max_length=254, null=True, unique=True), + ), + ] diff --git a/bookwyrm/models/user.py b/bookwyrm/models/user.py index 6697b1b8..1e9db401 100644 --- a/bookwyrm/models/user.py +++ b/bookwyrm/models/user.py @@ -25,6 +25,7 @@ from . import fields, Review class User(OrderedCollectionPageMixin, AbstractUser): ''' a user who wants to read books ''' username = fields.UsernameField() + email = models.EmailField(unique=True, null=True) key_pair = fields.OneToOneField( 'KeyPair', @@ -246,7 +247,7 @@ class AnnualGoal(BookWyrmModel): ''' the books you've read this year ''' return self.user.readthrough_set.filter( finish_date__year__gte=self.year - ).order_by('finish_date').all() + ).order_by('-finish_date').all() @property diff --git a/bookwyrm/static/css/format.css b/bookwyrm/static/css/format.css index e99513b0..f10549ed 100644 --- a/bookwyrm/static/css/format.css +++ b/bookwyrm/static/css/format.css @@ -14,20 +14,16 @@ } /* --- TOGGLES --- */ -input.toggle-control { +.toggle-button[aria-pressed=true], .toggle-button[aria-pressed=true]:hover { + background-color: hsl(171, 100%, 41%); + color: white; +} +.hide-active[aria-pressed=true], .hide-inactive[aria-pressed=false] { display: none; } .hidden { - display: none; -} - -input.toggle-control:checked ~ .toggle-content { - display: block; -} - -input.toggle-control:checked ~ .modal.toggle-content { - display: flex; + display: none !important; } /* --- STARS --- */ diff --git a/bookwyrm/static/js/shared.js b/bookwyrm/static/js/shared.js index b2de5736..55a5c1b2 100644 --- a/bookwyrm/static/js/shared.js +++ b/bookwyrm/static/js/shared.js @@ -1,7 +1,7 @@ // set up javascript listeners window.onload = function() { - // let buttons set keyboard focus - Array.from(document.getElementsByClassName('toggle-control')) + // buttons that display or hide content + document.querySelectorAll('[data-controls]') .forEach(t => t.onclick = toggleAction); // javascript interactions (boost/fav) @@ -13,8 +13,6 @@ window.onload = function() { .forEach(t => t.onclick = selectAll); // toggle between tabs - Array.from(document.getElementsByClassName('tab-change-nested')) - .forEach(t => t.onclick = tabChangeNested); Array.from(document.getElementsByClassName('tab-change')) .forEach(t => t.onclick = tabChange); @@ -29,9 +27,22 @@ window.onload = function() { // update localstorage Array.from(document.getElementsByClassName('set-display')) .forEach(t => t.onclick = updateDisplay); + + // hidden submit button in a form + document.querySelectorAll('.hidden-form input') + .forEach(t => t.onchange = revealForm); }; +function revealForm(e) { + var hidden = e.currentTarget.closest('.hidden-form').getElementsByClassName('hidden')[0]; + if (hidden) { + removeClass(hidden, 'hidden'); + } +} + + function updateDisplay(e) { + // used in set reading goal var key = e.target.getAttribute('data-id'); var value = e.target.getAttribute('data-value'); window.localStorage.setItem(key, value); @@ -41,37 +52,52 @@ function updateDisplay(e) { } function setDisplay(el) { + // used in set reading goal 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'; - } + var value = window.localStorage.getItem(key); + addRemoveClass(el, 'hidden', value); } + function toggleAction(e) { - // set hover, if appropriate - var hover = e.target.getAttribute('data-hover-target'); - if (hover) { - document.getElementById(hover).focus(); + var el = e.currentTarget; + var pressed = el.getAttribute('aria-pressed') == 'false'; + + var targetId = el.getAttribute('data-controls'); + document.querySelectorAll('[data-controls="' + targetId + '"]') + .forEach(t => t.setAttribute('aria-pressed', (t.getAttribute('aria-pressed') == 'false'))); + + if (targetId) { + var target = document.getElementById(targetId); + 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 + var checkbox = el.getAttribute('data-controls-checkbox'); + if (checkbox) { + document.getElementById(checkbox).checked = !!pressed; + } + + // set focus, if appropriate + var focus = el.getAttribute('data-focus-target'); + if (focus) { + document.getElementById(focus).focus(); } } - function interact(e) { e.preventDefault(); ajaxPost(e.target); var identifier = e.target.getAttribute('data-id'); - var elements = document.getElementsByClassName(identifier); - for (var i = 0; i < elements.length; i++) { - if (elements[i].className.includes('hidden')) { - elements[i].className = elements[i].className.replace('hidden', ''); - } else { - elements[i].className += ' hidden'; - } - } - return true; + Array.from(document.getElementsByClassName(identifier)) + .forEach(t => addRemoveClass(t, 'hidden', t.className.indexOf('hidden') == -1)); } function selectAll(e) { @@ -79,32 +105,32 @@ function selectAll(e) { .forEach(t => t.checked=true); } -function tabChangeNested(e) { - var target = e.target.closest('li') - var parentElement = target.parentElement.closest('li').parentElement; - handleTabChange(target, parentElement) -} - function tabChange(e) { - var target = e.target.closest('li') - var parentElement = target.parentElement; - handleTabChange(target, parentElement) -} + var el = e.currentTarget; + var parentElement = el.closest('[role="tablist"]'); - -function handleTabChange(target, parentElement) { parentElement.querySelectorAll('[aria-selected="true"]') .forEach(t => t.setAttribute("aria-selected", false)); - target.querySelector('[role="tab"]').setAttribute("aria-selected", true); + el.setAttribute("aria-selected", true); parentElement.querySelectorAll('li') - .forEach(t => t.className=''); - target.className = 'is-active'; + .forEach(t => removeClass(t, 'is-active')); + addClass(el, 'is-active'); + + var tabId = el.getAttribute('data-tab'); + Array.from(document.getElementsByClassName(el.getAttribute('data-category'))) + .forEach(t => addRemoveClass(t, 'hidden', t.id != tabId)); } function toggleMenu(e) { - var el = e.target.closest('.pulldown-menu'); - el.setAttribute('aria-expanded', el.getAttribute('aria-expanded') == 'false'); + var el = e.currentTarget; + var expanded = el.getAttribute('aria-expanded') == 'false'; + el.setAttribute('aria-expanded', expanded); + var targetId = el.getAttribute('data-controls'); + if (targetId) { + var target = document.getElementById(targetId); + addRemoveClass(target, 'is-active', expanded); + } } function ajaxPost(form) { @@ -113,3 +139,31 @@ function ajaxPost(form) { body: new FormData(form) }); } + +function addRemoveClass(el, classname, bool) { + if (bool) { + addClass(el, classname); + } else { + removeClass(el, classname); + } +} + +function addClass(el, classname) { + var classes = el.className.split(' '); + if (classes.indexOf(classname) > -1) { + return; + } + el.className = classes.concat(classname).join(' '); +} + +function removeClass(el, className) { + var classes = []; + if (el.className) { + classes = el.className.split(' '); + } + const idx = classes.indexOf(className); + if (idx > -1) { + classes.splice(idx, 1); + } + el.className = classes.join(' '); +} diff --git a/bookwyrm/templates/book.html b/bookwyrm/templates/book.html index 4e65ecf8..4a95237c 100644 --- a/bookwyrm/templates/book.html +++ b/bookwyrm/templates/book.html @@ -39,14 +39,28 @@ {% if request.user.is_authenticated and not book.cover %}
+

Add cover

{% csrf_token %} -
- - -
-
- +
+
+
+ +
+
+
+ +
@@ -94,30 +108,20 @@ {% include 'snippets/trimmed_text.html' with full=book|book_description %} {% if request.user.is_authenticated and perms.bookwyrm.edit_book and not book|book_description %} -
- - -
+ {% include 'snippets/toggle/open_button.html' with text="Add description" controls_text="add-description" controls_uid=book.id focus="id_description" hide_active=True id="hide-description" %} -
- - {% if readthroughs.exists %} -
-

Your reading activity

- {% for readthrough in readthroughs %} - {% include 'snippets/readthrough.html' with readthrough=readthrough %} - {% endfor %} -
- {% endif %} -
-
- - -
- - +
+ {% include 'snippets/toggle/close_button.html' with text="Cancel" controls_text="add-readthrough" %} +
+
+ + + {% for readthrough in readthroughs %} + {% include 'snippets/readthrough.html' with readthrough=readthrough %} + {% endfor %} + + {% endif %} {% if request.user.is_authenticated %} -
+
{% include 'snippets/create_status.html' with book=book hide_cover=True %} -
+ -
+
{% csrf_token %} @@ -185,7 +187,7 @@
-
+ {% endif %}
diff --git a/bookwyrm/templates/edit_user.html b/bookwyrm/templates/edit_user.html index 7e963b5b..413f2cae 100644 --- a/bookwyrm/templates/edit_user.html +++ b/bookwyrm/templates/edit_user.html @@ -8,40 +8,40 @@ {% endif %}
{% csrf_token %} -

+

{{ form.avatar }} {% for error in form.avatar.errors %}

{{ error | escape }}

{% endfor %} -

-

+

+
{{ form.name }} {% for error in form.name.errors %}

{{ error | escape }}

{% endfor %} -

-

+

+
{{ form.summary }} {% for error in form.summary.errors %}

{{ error | escape }}

{% endfor %} -

-

+

+
{{ form.email }} {% for error in form.email.errors %}

{{ error | escape }}

{% endfor %} -

-

+

+
-

+
@@ -50,14 +50,14 @@

Change password

{% csrf_token %} -

+

-

-

+

+
-

+
diff --git a/bookwyrm/templates/feed.html b/bookwyrm/templates/feed.html index 3f06c4e0..7da2a285 100644 --- a/bookwyrm/templates/feed.html +++ b/bookwyrm/templates/feed.html @@ -9,7 +9,7 @@

There are no books here right now! Try searching for a book to get started

{% else %}
-
    +
      {% for shelf in suggested_books %} {% if shelf.books %} {% with shelf_counter=forloop.counter %} @@ -17,17 +17,13 @@

      {{ shelf.name }}

      -
      +
      @@ -41,41 +37,33 @@ {% for shelf in suggested_books %} {% with shelf_counter=forloop.counter %} {% for book in shelf.books %} -
      - - - -