Simplify notification un-subscription process (#3870)
This commit is contained in:
parent
3b0f6f2834
commit
64c9b36a40
2 changed files with 15 additions and 3 deletions
|
|
@ -41,13 +41,25 @@ function loadFunctionality() {
|
|||
};
|
||||
} else {
|
||||
updateStatus = target => {
|
||||
let payload = '';
|
||||
const shouldUnsubscribeToNotifications = target.classList.contains('selected')
|
||||
|| target.classList.contains('selected-emoji');
|
||||
const allButtons = document.getElementsByClassName(
|
||||
'notification-subscription-label',
|
||||
);
|
||||
for (let i = 0; i < allButtons.length; i += 1) {
|
||||
allButtons[i].classList.remove('selected');
|
||||
}
|
||||
target.classList.add('selected');
|
||||
if (shouldUnsubscribeToNotifications) {
|
||||
const unsubscribeButton = allButtons.namedItem(
|
||||
'unsubscribe',
|
||||
);
|
||||
unsubscribeButton.classList.add('selected');
|
||||
payload = unsubscribeButton.dataset.payload;
|
||||
} else {
|
||||
target.classList.add('selected');
|
||||
payload = target.dataset.payload;
|
||||
}
|
||||
fetch(`/notification_subscriptions/${notifiableType}/${notifiableId}`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
|
|
@ -57,7 +69,7 @@ function loadFunctionality() {
|
|||
},
|
||||
credentials: 'same-origin',
|
||||
body: JSON.stringify({
|
||||
config: target.dataset.payload,
|
||||
config: payload,
|
||||
// notifiable params are passed via URL
|
||||
}),
|
||||
});
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@
|
|||
<div class="dropdown-link-row notification-subscriptions-area-row"
|
||||
id="notification-subscriptions-area" data-notifiable-id="<%= @article.id %>" data-notifiable-type="Article">
|
||||
<div class="notification-subscriptions-area-header">🔔 Notification Subscriptions
|
||||
<button for="subscribe_notifications" id="notification-subscription-label_not_subscribed" class="notification-subscription-label notification-subscription-label-unsubscribe" data-payload="not_subscribed">
|
||||
<button for="subscribe_notifications" id="notification-subscription-label_not_subscribed" class="notification-subscription-label notification-subscription-label-unsubscribe" data-payload="not_subscribed" name="unsubscribe">
|
||||
Unsubscribe
|
||||
</button>
|
||||
</div>
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue