diff --git a/bookwyrm/migrations/0122_alter_annualgoal_year.py b/bookwyrm/migrations/0122_alter_annualgoal_year.py new file mode 100644 index 00000000..90af5fcc --- /dev/null +++ b/bookwyrm/migrations/0122_alter_annualgoal_year.py @@ -0,0 +1,19 @@ +# Generated by Django 3.2.5 on 2022-01-04 18:59 + +import bookwyrm.models.user +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("bookwyrm", "0121_user_summary_keys"), + ] + + operations = [ + migrations.AlterField( + model_name="annualgoal", + name="year", + field=models.IntegerField(default=bookwyrm.models.user.get_current_year), + ), + ] diff --git a/bookwyrm/models/user.py b/bookwyrm/models/user.py index deec2a44..bd340b01 100644 --- a/bookwyrm/models/user.py +++ b/bookwyrm/models/user.py @@ -415,12 +415,17 @@ class KeyPair(ActivitypubMixin, BookWyrmModel): return activity_object +def get_current_year(): + """sets default year for annual goal to this year""" + return timezone.now().year + + class AnnualGoal(BookWyrmModel): """set a goal for how many books you read in a year""" user = models.ForeignKey("User", on_delete=models.PROTECT) goal = models.IntegerField(validators=[MinValueValidator(1)]) - year = models.IntegerField(default=timezone.now().year) + year = models.IntegerField(default=get_current_year) privacy = models.CharField( max_length=255, default="public", choices=fields.PrivacyLevels.choices ) diff --git a/bookwyrm/static/css/bookwyrm.css b/bookwyrm/static/css/bookwyrm.css index 5ea65d22..15324a14 100644 --- a/bookwyrm/static/css/bookwyrm.css +++ b/bookwyrm/static/css/bookwyrm.css @@ -135,6 +135,18 @@ button::-moz-focus-inner { border-bottom: 1px solid #ededed; border-right: 0; } + + .is-flex-direction-row-mobile { + flex-direction: row !important; + } + + .is-flex-direction-column-mobile { + flex-direction: column !important; + } +} + +.tag.is-small { + height: auto; } .button.is-transparent { @@ -215,7 +227,7 @@ input[type=file]::file-selector-button:hover { /** General `details` element styles ******************************************************************************/ -summary { +details summary { cursor: pointer; } @@ -223,22 +235,22 @@ summary::-webkit-details-marker { display: none; } -summary::marker { +details summary::marker { content: none; } -.detail-pinned-button summary { +details.detail-pinned-button summary { position: absolute; right: 0; } -.detail-pinned-button form { +details.detail-pinned-button form { float: left; - width: -webkit-fill-available; + width: 100%; margin-top: 1em; } -/** Details dropdown +/** Dropdown w/ Details element ******************************************************************************/ details.dropdown[open] summary.dropdown-trigger::before { @@ -250,11 +262,11 @@ details.dropdown[open] summary.dropdown-trigger::before { right: 0; } -details .dropdown-menu { +details.dropdown .dropdown-menu { display: block !important; } -details .dropdown-menu button { +details.dropdown .dropdown-menu button { /* Fix weird Safari defaults */ box-sizing: border-box; } @@ -289,6 +301,46 @@ details.dropdown .dropdown-menu a:focus-visible { } } +/** Details panel + ******************************************************************************/ + +details.details-panel { + box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.1); + transition: box-shadow 0.2s ease; + padding: 0.75rem; +} + +details[open].details-panel, +details.details-panel:hover { + box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.2); +} + +details.details-panel summary { + position: relative; +} + +details.details-panel summary .details-close { + position: absolute; + right: 0; + top: 0; + transform: rotate(45deg); + transition: transform 0.2s ease; +} + +details[open].details-panel summary .details-close { + transform: rotate(0deg); +} + +@media only screen and (min-width: 769px) { + .details-panel .filters-field:not(:last-child) { + border-right: 1px solid rgba(0, 0, 0, 0.1); + margin-top: 0.75rem; + margin-bottom: 0.75rem; + padding-top: 0.25rem; + padding-bottom: 0.25rem; + } +} + /** Shelving ******************************************************************************/ @@ -1149,3 +1201,93 @@ ol.ordered-list li::before { margin-bottom: 0.75rem !important; } } + +/* Gaps (for Flexbox and Grid) + * + * Those are supplementary rules to Bulma’s. They follow the same conventions. + * Add those you’ll need. + ******************************************************************************/ + +.is-gap-0 { + gap: 0; +} + +.is-gap-1 { + gap: 0.25rem; +} + +.is-gap-2 { + gap: 0.5rem; +} + +.is-gap-3 { + gap: 0.75rem; +} + +.is-gap-4 { + gap: 1rem; +} + +.is-gap-5 { + gap: 1.5rem; +} + +.is-gap-6 { + gap: 3rem; +} + +.is-row-gap-0 { + row-gap: 0; +} + +.is-row-gap-1 { + row-gap: 0.25rem; +} + +.is-row-gap-2 { + row-gap: 0.5rem; +} + +.is-row-gap-3 { + row-gap: 0.75rem; +} + +.is-row-gap-4 { + row-gap: 1rem; +} + +.is-row-gap-5 { + row-gap: 1.5rem; +} + +.is-row-gap-6 { + row-gap: 3rem; +} + +.is-column-gap-0 { + column-gap: 0; +} + +.is-column-gap-1 { + column-gap: 0.25rem; +} + +.is-column-gap-2 { + column-gap: 0.5rem; +} + +.is-column-gap-3 { + column-gap: 0.75rem; +} + +.is-column-gap-4 { + column-gap: 1rem; +} + +.is-column-gap-5 { + column-gap: 1.5rem; +} + +.is-column-gap-6 { + column-gap: 3rem; +} diff --git a/bookwyrm/static/css/vendor/icons.css b/bookwyrm/static/css/vendor/icons.css index 9c35b1be..4bc7cca5 100644 --- a/bookwyrm/static/css/vendor/icons.css +++ b/bookwyrm/static/css/vendor/icons.css @@ -25,6 +25,10 @@ -moz-osx-font-smoothing: grayscale; } +.icon.is-small { + font-size: small; +} + .icon-book:before { content: "\e901"; } diff --git a/bookwyrm/static/js/bookwyrm.js b/bookwyrm/static/js/bookwyrm.js index 6d21c207..cf3944b3 100644 --- a/bookwyrm/static/js/bookwyrm.js +++ b/bookwyrm/static/js/bookwyrm.js @@ -41,6 +41,7 @@ let BookWyrm = new (class { document .querySelectorAll("[data-duplicate]") .forEach((node) => node.addEventListener("click", this.duplicateInput.bind(this))); + document .querySelectorAll("details.dropdown") .forEach((node) => @@ -60,6 +61,9 @@ let BookWyrm = new (class { .querySelectorAll('input[type="file"]') .forEach(bookwyrm.disableIfTooLarge.bind(bookwyrm)); document.querySelectorAll("[data-copytext]").forEach(bookwyrm.copyText.bind(bookwyrm)); + document + .querySelectorAll(".modal.is-active") + .forEach(bookwyrm.handleActiveModal.bind(bookwyrm)); }); } @@ -405,7 +409,7 @@ let BookWyrm = new (class { } /** - * Handle the modal component. + * Handle the modal component with a button trigger. * * @param {Event} event - Event fired by an element * with the `data-modal-open` attribute @@ -416,6 +420,7 @@ let BookWyrm = new (class { * for information about using the modal. */ handleModalButton(event) { + const { handleFocusTrap } = this; const modalButton = event.currentTarget; const targetModalId = modalButton.dataset.modalOpen; const htmlElement = document.querySelector("html"); @@ -427,6 +432,8 @@ let BookWyrm = new (class { // Helper functions function handleModalOpen(modalElement) { + event.preventDefault(); + htmlElement.classList.add("is-clipped"); modalElement.classList.add("is-active"); modalElement.getElementsByClassName("modal-card")[0].focus(); @@ -455,42 +462,48 @@ let BookWyrm = new (class { modalButton.focus(); } - function handleFocusTrap(event) { - if (event.key !== "Tab") { - return; - } - - const focusableEls = event.currentTarget.querySelectorAll( - [ - "a[href]:not([disabled])", - "button:not([disabled])", - "textarea:not([disabled])", - 'input:not([type="hidden"]):not([disabled])', - "select:not([disabled])", - "details:not([disabled])", - '[tabindex]:not([tabindex="-1"]):not([disabled])', - ].join(",") - ); - const firstFocusableEl = focusableEls[0]; - const lastFocusableEl = focusableEls[focusableEls.length - 1]; - - if (event.shiftKey) { - /* Shift + tab */ if (document.activeElement === firstFocusableEl) { - lastFocusableEl.focus(); - event.preventDefault(); - } - } /* Tab */ else { - if (document.activeElement === lastFocusableEl) { - firstFocusableEl.focus(); - event.preventDefault(); - } - } - } - // Open modal handleModalOpen(modal); } + /** + * Handle the modal component when opened at page load. + * + * @param {Element} modalElement - Active modal element + * @return {undefined} + * + */ + handleActiveModal(modalElement) { + if (!modalElement) { + return; + } + + const { handleFocusTrap } = this; + + modalElement.getElementsByClassName("modal-card")[0].focus(); + + const closeButtons = modalElement.querySelectorAll("[data-modal-close]"); + + closeButtons.forEach((button) => { + button.addEventListener("click", function () { + handleModalClose(modalElement); + }); + }); + + document.addEventListener("keydown", function (event) { + if (event.key === "Escape") { + handleModalClose(modalElement); + } + }); + + modalElement.addEventListener("keydown", handleFocusTrap); + + function handleModalClose(modalElement) { + modalElement.removeEventListener("keydown", handleFocusTrap); + history.back(); + } + } + /** * Display pop up window. * diff --git a/bookwyrm/templates/annual_summary/layout.html b/bookwyrm/templates/annual_summary/layout.html index b5ba9cc7..ab25458c 100644 --- a/bookwyrm/templates/annual_summary/layout.html +++ b/bookwyrm/templates/annual_summary/layout.html @@ -192,6 +192,31 @@ + {% if goal_status and goal_status.percent >= 100 %} +
{% trans "Way to go!" %}
+