From 4da0a75efa473b5d6530b10bfc04c4a9c7c1b40b Mon Sep 17 00:00:00 2001 From: Matt Friedman Date: Wed, 17 Jul 2024 09:28:33 -0700 Subject: [PATCH 1/3] [ticket/17371] Improve dropdown toggle UX PHPBB-17371 Signed-off-by: Matt Friedman --- phpBB/styles/prosilver/imgs/svg/toggle-off.svg | 1 + phpBB/styles/prosilver/imgs/svg/toggle-on.svg | 1 + .../styles/prosilver/template/notification_dropdown.html | 4 ++-- phpBB/styles/prosilver/theme/colours.css | 8 ++++++++ phpBB/styles/prosilver/theme/icons.css | 6 ++++++ 5 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 phpBB/styles/prosilver/imgs/svg/toggle-off.svg create mode 100644 phpBB/styles/prosilver/imgs/svg/toggle-on.svg diff --git a/phpBB/styles/prosilver/imgs/svg/toggle-off.svg b/phpBB/styles/prosilver/imgs/svg/toggle-off.svg new file mode 100644 index 0000000000..9bd31a7bf5 --- /dev/null +++ b/phpBB/styles/prosilver/imgs/svg/toggle-off.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/phpBB/styles/prosilver/imgs/svg/toggle-on.svg b/phpBB/styles/prosilver/imgs/svg/toggle-on.svg new file mode 100644 index 0000000000..83d2e59c0c --- /dev/null +++ b/phpBB/styles/prosilver/imgs/svg/toggle-on.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/phpBB/styles/prosilver/template/notification_dropdown.html b/phpBB/styles/prosilver/template/notification_dropdown.html index de5a8c79e6..715f04e1a2 100644 --- a/phpBB/styles/prosilver/template/notification_dropdown.html +++ b/phpBB/styles/prosilver/template/notification_dropdown.html @@ -47,8 +47,8 @@ {% if NOTIFICATIONS_WEBPUSH_ENABLE and notification_types is not defined %} {% endif %} {% EVENT notification_dropdown_footer_after %} diff --git a/phpBB/styles/prosilver/theme/colours.css b/phpBB/styles/prosilver/theme/colours.css index 4980cd89f2..eb16158cc3 100644 --- a/phpBB/styles/prosilver/theme/colours.css +++ b/phpBB/styles/prosilver/theme/colours.css @@ -298,6 +298,14 @@ a:hover .icon.icon-black, /* DEPRECATED 4.0 */ color: inherit; } +.push-subscribe-toggle-icon.toggle-on { + color: #0059b3; +} + +.push-subscribe-toggle-icon.toggle-off { + color: #9e9e9e; +} + /* jumpbox */ .jumpbox .dropdown li { border-top-color: #dedede; diff --git a/phpBB/styles/prosilver/theme/icons.css b/phpBB/styles/prosilver/theme/icons.css index a6ad36d22a..d4b7dabefe 100644 --- a/phpBB/styles/prosilver/theme/icons.css +++ b/phpBB/styles/prosilver/theme/icons.css @@ -123,6 +123,12 @@ blockquote cite:before, height: 18px; } +.push-subscribe-toggle-icon { + width: 20px; + height: 20px; + cursor: pointer; +} + /* Contact icons ---------------------------------------- */ .contact-icon { From 7252345911bb2480e8f493a3a18d6452232da0c4 Mon Sep 17 00:00:00 2001 From: Matt Friedman Date: Wed, 17 Jul 2024 09:29:30 -0700 Subject: [PATCH 2/3] [ticket/17371] Improve UX for disabled state PHPBB-17371 Signed-off-by: Matt Friedman --- phpBB/assets/javascript/webpush.js | 26 ++++++++++++++++--- phpBB/language/en/common.php | 5 ++-- .../template/ucp_notifications_options.html | 2 +- 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/phpBB/assets/javascript/webpush.js b/phpBB/assets/javascript/webpush.js index 94e542d2ae..4adb9ecf10 100644 --- a/phpBB/assets/javascript/webpush.js +++ b/phpBB/assets/javascript/webpush.js @@ -51,7 +51,7 @@ function PhpbbWebpush() { // Service workers are only supported in secure context if (window.isSecureContext !== true) { - subscribeButton.disabled = true; + setDisabledState(); return; } @@ -66,13 +66,33 @@ function PhpbbWebpush() { .catch(error => { console.info(error); // Service worker could not be registered - subscribeButton.disabled = true; + setDisabledState(); }); } else { - subscribeButton.disabled = true; + setDisabledState(); } }; + /** + * Disable subscribing buttons, update subscribe button text and hide dropdown toggle + * + * @return void + */ + function setDisabledState() { + subscribeButton.disabled = true; + + const notificationList = document.getElementById('notification-menu'); + const subscribeToggle = notificationList.querySelector('.webpush-subscribe'); + + if (subscribeToggle) { + subscribeToggle.style.display = 'none'; + } + + if (subscribeButton.type === 'submit' || subscribeButton.classList.contains('button')) { + subscribeButton.value = subscribeButton.getAttribute('data-disabled-msg'); + } + } + /** * Update button state depending on notifications state * diff --git a/phpBB/language/en/common.php b/phpBB/language/en/common.php index 43269679bf..d528ef9b2b 100644 --- a/phpBB/language/en/common.php +++ b/phpBB/language/en/common.php @@ -512,10 +512,11 @@ $lang = array_merge($lang, array( ), 'NOTIFY_ADMIN' => 'Please notify the board administrator or webmaster.', 'NOTIFY_ADMIN_EMAIL' => 'Please notify the board administrator or webmaster: %1$s', - 'NOTIFY_WEB_PUSH_ENABLE' => 'Enable Web Push notifications', + 'NOTIFY_WEB_PUSH_DENIED' => 'You have denied notifications from this site. To subscribe, please allow notifications in your browser settings.', + 'NOTIFY_WEB_PUSH_DISABLED' => 'Web Push not supported', + 'NOTIFY_WEB_PUSH_ENABLE' => 'Enable web push notifications', 'NOTIFY_WEB_PUSH_SUBSCRIBE' => 'Subscribe', 'NOTIFY_WEB_PUSH_SUBSCRIBED'=> 'Subscribed', - 'NOTIFY_WEB_PUSH_DENIED' => 'You have denied notifications from this site. To subscribe, please allow notifications in your browser settings.', 'NO_ACCESS_ATTACHMENT' => 'You are not allowed to access this file.', 'NO_ACTION' => 'No action specified.', 'NO_ADMINISTRATORS' => 'There are no administrators.', diff --git a/phpBB/styles/prosilver/template/ucp_notifications_options.html b/phpBB/styles/prosilver/template/ucp_notifications_options.html index 27981581ff..5b953362fe 100644 --- a/phpBB/styles/prosilver/template/ucp_notifications_options.html +++ b/phpBB/styles/prosilver/template/ucp_notifications_options.html @@ -10,7 +10,7 @@

{{ lang('NOTIFY_WEBPUSH_ENABLE_EXPLAIN') }}
- +
From 5e80be96e43ae5d5c11d436aee270a719b0a496c Mon Sep 17 00:00:00 2001 From: Matt Friedman Date: Wed, 17 Jul 2024 09:30:08 -0700 Subject: [PATCH 3/3] [ticket/17371] Code fixes and hard-coded lang vars PHPBB-17371 Signed-off-by: Matt Friedman --- phpBB/phpbb/ucp/controller/webpush.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/phpBB/phpbb/ucp/controller/webpush.php b/phpBB/phpbb/ucp/controller/webpush.php index 15e54956fb..cac2f10291 100644 --- a/phpBB/phpbb/ucp/controller/webpush.php +++ b/phpBB/phpbb/ucp/controller/webpush.php @@ -103,7 +103,7 @@ class webpush { if (!$this->request->is_ajax() || $this->user->data['is_bot'] || $this->user->data['user_type'] == USER_INACTIVE) { - throw new http_exception(Response::HTTP_FORBIDDEN, 'Forbidden'); + throw new http_exception(Response::HTTP_FORBIDDEN, 'NO_AUTH_OPERATION'); } if ($this->user->id() !== ANONYMOUS) @@ -132,7 +132,7 @@ class webpush // Subscribe should only be available for logged-in "normal" users if ($this->user->data['user_type'] == USER_IGNORE) { - throw new http_exception(Response::HTTP_FORBIDDEN, 'Forbidden'); + throw new http_exception(Response::HTTP_FORBIDDEN, 'NO_AUTH_OPERATION'); } $item_id = $this->request->variable('item_id', 0); @@ -192,7 +192,7 @@ class webpush } } - throw new http_exception(Response::HTTP_FORBIDDEN, 'Forbidden'); + throw new http_exception(Response::HTTP_FORBIDDEN, 'NO_AUTH_OPERATION'); } /** @@ -251,7 +251,7 @@ class webpush } // Subscribe should only be available for logged-in "normal" users - if (!$this->request->is_ajax() || $this->user->id() == ANONYMOUS || $this->user->data['is_bot'] + if (!$this->request->is_ajax() || $this->user->id() === ANONYMOUS || $this->user->data['is_bot'] || $this->user->data['user_type'] == USER_IGNORE || $this->user->data['user_type'] == USER_INACTIVE) { throw new http_exception(Response::HTTP_FORBIDDEN, 'NO_AUTH_OPERATION');