Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UX better handling of disabled state #67

Merged
merged 1 commit into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions language/en/webpushnotifications_module_ucp.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,13 @@

$lang = array_merge($lang, [
'NOTIFICATION_METHOD_PHPBB_WPN_WEBPUSH' => 'Web Push',
'NOTIFY_WEBPUSH_NOTIFICATIONS' => 'Web Push Notifications',
'NOTIFY_WEBPUSH_DISABLE' => 'Disable Push Notifications',
'NOTIFY_WEBPUSH_ENABLE' => 'Enable Push Notifications',
'NOTIFY_WEBPUSH_NOTIFICATIONS' => 'Web push notifications',
'NOTIFY_WEBPUSH_DISABLE' => 'Disable push notifications',
'NOTIFY_WEBPUSH_ENABLE' => 'Enable push notifications',
'NOTIFY_WEBPUSH_ENABLE_EXPLAIN' => 'Enabling push notifications will activate them on this device only. You can turn off notifications at any time through your browser settings or by clicking the button above. Additionally, if no web push notification types are selected below, you will not receive any web push notifications.',
'NOTIFY_WEBPUSH_SUBSCRIBE' => 'Enable to subscribe',
'NOTIFY_WEBPUSH_UNSUBSCRIBE' => 'Disable to unsubscribe',
'NOTIFY_WEBPUSH_DROPDOWN_TITLE' => 'Visit notifications settings to set your preferred push notifications.',
'NOTIFY_WEBPUSH_DENIED' => 'You have denied notifications from this site. To enable push notifications, allow notifications from this site in your browser settings.',
'NOTIFY_WEBPUSH_DISABLED' => 'Push notifications not supported',
]);
21 changes: 21 additions & 0 deletions styles/all/template/webpush.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ function PhpbbWebpush() {
// Service workers are only supported in secure context
if (window.isSecureContext !== true) {
subscribeButton.disabled = true;
handleDisabledState();
return;
}

Expand All @@ -71,8 +72,28 @@ function PhpbbWebpush() {
} else {
subscribeButton.disabled = true;
}
handleDisabledState();
};

/**
* If subscribing is disabled, hide dropdown toggle and update subscribe button text
*
* @return void
*/
function handleDisabledState() {
if (subscribeButton.disabled) {
const notificationList = document.getElementById('notification_list');
const footer = notificationList.querySelector('.wpn-notification-dropdown-footer');
if (footer) {
footer.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
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<dl>
<dt><label for="subscribe_webpush">{{ lang('NOTIFY_WEBPUSH_NOTIFICATIONS') ~ lang('COLON') }}</label></dt>
<dd>
<input id="subscribe_webpush" type="submit" name="subscribe_webpush" value="{{ lang('NOTIFY_WEBPUSH_ENABLE') }}" class="wpn button1 button button-form" data-l-err="{{ lang('INFORMATION') }}" data-l-msg="{{ lang('NOTIFY_WEBPUSH_DENIED') }}">
<input id="subscribe_webpush" type="submit" name="subscribe_webpush" value="{{ lang('NOTIFY_WEBPUSH_ENABLE') }}" class="wpn button1 button button-form" data-l-err="{{ lang('INFORMATION') }}" data-l-msg="{{ lang('NOTIFY_WEBPUSH_DENIED') }}" data-disabled-msg="{{ lang('NOTIFY_WEBPUSH_DISABLED') }}">
<input id="unsubscribe_webpush" type="submit" name="unsubscribe_webpush" value="{{ lang('NOTIFY_WEBPUSH_DISABLE') }}" class="wpn button1 button button-form hidden">
<br><span>{{ lang('NOTIFY_WEBPUSH_ENABLE_EXPLAIN') }}</span>
</dd>
Expand Down
Loading