Skip to content

Wallos: Open-source, self-hostable personal subscription tracker. Visualize your recurring expenses, manage your budget, and save money.

feat(bulk): polish the bulk toolbar and keep Apply disabled until it has something to apply

Miguel Ribeiro29b5b5d2a1e6
diff --git a/scripts/subscriptions.js b/scripts/subscriptions.js
index d7abde6..f0a1600 100644
--- a/scripts/subscriptions.js
+++ b/scripts/subscriptions.js
@@ -1400,7 +1400,7 @@ function visibleBulkCheckboxes() {
function toggleBulkMode() {
const active = document.querySelector("#subscriptions").classList.toggle("bulk-mode");
document.querySelector("#bulk-toolbar").classList.toggle("is-open", active);
- document.querySelector("#bulk-mode-button").classList.toggle("selected", active);
+ document.querySelectorAll(".bulk-mode-button").forEach((button) => button.classList.toggle("selected", active));
if (!active) {
document.querySelectorAll(".bulk-select-checkbox").forEach((checkbox) => checkbox.checked = false);
@@ -1425,11 +1425,25 @@ function updateBulkSelection() {
const selected = checkboxes.filter((checkbox) => checkbox.checked).length;
const selectAll = document.querySelector("#bulk-select-all");
- counter.textContent = translate("bulk_selected_count")
+ counter.textContent = "(" + translate("bulk_selected_count")
.replace("{count}", selected)
- .replace("{total}", checkboxes.length);
+ .replace("{total}", checkboxes.length) + ")";
selectAll.checked = checkboxes.length > 0 && selected === checkboxes.length;
selectAll.indeterminate = selected > 0 && selected < checkboxes.length;
+ updateBulkApplyState();
+}
+
+// Apply stays disabled until there is something to apply: at least one
+// subscription selected and an action chosen.
+function updateBulkApplyState() {
+ const apply = document.querySelector("#bulk-apply");
+ if (!apply) {
+ return;
+ }
+
+ const selected = visibleBulkCheckboxes().some((checkbox) => checkbox.checked);
+ const action = document.querySelector("#bulk-action").value;
+ apply.disabled = !selected || action === "";
}
function updateBulkActionValue() {
@@ -1437,6 +1451,7 @@ function updateBulkActionValue() {
document.querySelector("#bulk-notify-days").hidden = action !== "set_notify_days";
document.querySelector("#bulk-category").hidden = action !== "set_category";
document.querySelector("#bulk-payment-method").hidden = action !== "set_payment_method";
+ updateBulkApplyState();
}
function applyBulkAction() {
diff --git a/styles/styles.css b/styles/styles.css
index 828dc05..4abb0ee 100644
--- a/styles/styles.css
+++ b/styles/styles.css
@@ -277,11 +277,41 @@ main>.contain {
display: none;
}
+/* The bulk button exists twice: next to the new subscription button on mobile,
+ with the other tools on desktop. Only one of them is shown. */
+.main-actions-primary {
+ display: contents;
+}
+
+.main-actions .bulk-mode-button-mobile {
+ display: none;
+}
+
@media (max-width: 768px) {
.main-actions {
justify-content: space-between;
flex-direction: column-reverse;
}
+
+ .main-actions-primary {
+ display: flex;
+ flex-direction: row;
+ gap: 16px;
+ }
+
+ /* The bulk button takes the space it needs, the new subscription button the rest */
+ .main-actions-primary > .button {
+ flex: 1 1 auto;
+ }
+
+ .main-actions-primary > .bulk-mode-button-mobile {
+ display: flex;
+ flex: 0 0 auto;
+ }
+
+ .main-actions .bulk-mode-button-desktop {
+ display: none;
+ }
}
.button {
@@ -4071,7 +4101,7 @@ input[type="radio"]:checked+label::after {
color: var(--main-color);
}
-#bulk-mode-button.selected {
+.bulk-mode-button.selected {
background-color: rgba(var(--main-color-rgb), 0.12);
color: var(--main-color);
}
@@ -4096,6 +4126,7 @@ input[type="radio"]:checked+label::after {
display: flex;
align-items: center;
gap: 6px;
+ margin: 0px;
cursor: pointer;
}
@@ -4121,6 +4152,7 @@ input[type="radio"]:checked+label::after {
.bulk-select {
display: none;
+ margin: 0px;
}
.subscriptions.bulk-mode .bulk-select {
@@ -4169,6 +4201,12 @@ input[type="radio"]:checked+label::after {
flex: 1;
max-width: none;
}
+
+ /* The action select gets a line of its own; the value select it reveals, and the buttons, follow below */
+ .bulk-toolbar #bulk-action {
+ flex-basis: 100%;
+ margin: 2px 0px;
+ }
}
.subscriptions.grid-view {
diff --git a/subscriptions.php b/subscriptions.php
index 6882e0c..289a7ce 100644
--- a/subscriptions.php
+++ b/subscriptions.php
@@ -155,10 +155,16 @@ $subscriptionsView = (isset($_COOKIE['subscriptionsView']) && $_COOKIE['subscrip
<section class="contain">
<header class="<?= $headerClass ?>" id="main-actions">
- <button class="button" onClick="addSubscription()">
- <i class="fa-solid fa-circle-plus"></i>
- <?= translate('new_subscription', $i18n) ?>
- </button>
+ <div class="main-actions-primary">
+ <button class="button secondary-button bulk-mode-button bulk-mode-button-mobile"
+ title="<?= translate('bulk_actions', $i18n) ?>" onClick="toggleBulkMode()">
+ <i class="fa-solid fa-square-check"></i>
+ </button>
+ <button class="button" onClick="addSubscription()">
+ <i class="fa-solid fa-circle-plus"></i>
+ <?= translate('new_subscription', $i18n) ?>
+ </button>
+ </div>
<div class="top-actions">
<button class="button secondary-button mobile-search-toggle" id="mobile-search-toggle"
title="<?= translate('search', $i18n) ?>" onClick="toggleMobileSearch()">
@@ -197,9 +203,9 @@ $subscriptionsView = (isset($_COOKIE['subscriptionsView']) && $_COOKIE['subscrip
</button>
</div>
- <button class="button secondary-button" id="bulk-mode-button" title="<?= translate('bulk_actions', $i18n) ?>"
- onClick="toggleBulkMode()">
- <i class="fa-solid fa-list-check"></i>
+ <button class="button secondary-button bulk-mode-button bulk-mode-button-desktop"
+ title="<?= translate('bulk_actions', $i18n) ?>" onClick="toggleBulkMode()">
+ <i class="fa-solid fa-square-check"></i>
</button>
</div>
</header>
@@ -248,8 +254,8 @@ $subscriptionsView = (isset($_COOKIE['subscriptionsView']) && $_COOKIE['subscrip
}
?>
</select>
- <button class="button" onClick="applyBulkAction()"><?= translate('apply', $i18n) ?></button>
- <button class="button secondary-button" onClick="toggleBulkMode()"><?= translate('cancel', $i18n) ?></button>
+ <button class="button mobile-grow" id="bulk-apply" onClick="applyBulkAction()" disabled><?= translate('apply', $i18n) ?></button>
+ <button class="button secondary-button mobile-grow" onClick="toggleBulkMode()"><?= translate('cancel', $i18n) ?></button>
</div>
<div class="subscriptions<?= $subscriptionsView === 'grid' ? ' grid-view' : '' ?>" id="subscriptions">
<?php