mirror of
https://github.com/cheeaun/phanpy.git
synced 2025-02-25 09:18:51 +01:00
Fix policy change not working for push notifications
1. Turns out `policy` needs to be inside `data` hash 2. namedItem(policy) → namedItem('policy') Super embarrassed that these bugs exist for 7 months since push notifications release.
This commit is contained in:
parent
27a7bc7627
commit
9d16c6c12a
1 changed files with 53 additions and 49 deletions
|
@ -690,9 +690,10 @@ function PushNotificationsSection({ onClose }) {
|
||||||
) {
|
) {
|
||||||
setAllowNotifications(true);
|
setAllowNotifications(true);
|
||||||
const { alerts, policy } = backendSubscription;
|
const { alerts, policy } = backendSubscription;
|
||||||
|
console.log('backendSubscription', backendSubscription);
|
||||||
previousPolicyRef.current = policy;
|
previousPolicyRef.current = policy;
|
||||||
const { elements } = pushFormRef.current;
|
const { elements } = pushFormRef.current;
|
||||||
const policyEl = elements.namedItem(policy);
|
const policyEl = elements.namedItem('policy');
|
||||||
if (policyEl) policyEl.value = policy;
|
if (policyEl) policyEl.value = policy;
|
||||||
// alerts is {}, iterate it
|
// alerts is {}, iterate it
|
||||||
Object.keys(alerts).forEach((alert) => {
|
Object.keys(alerts).forEach((alert) => {
|
||||||
|
@ -721,11 +722,12 @@ function PushNotificationsSection({ onClose }) {
|
||||||
<form
|
<form
|
||||||
ref={pushFormRef}
|
ref={pushFormRef}
|
||||||
onChange={() => {
|
onChange={() => {
|
||||||
|
setTimeout(() => {
|
||||||
const values = Object.fromEntries(new FormData(pushFormRef.current));
|
const values = Object.fromEntries(new FormData(pushFormRef.current));
|
||||||
const allowNotifications = !!values['policy-allow'];
|
const allowNotifications = !!values['policy-allow'];
|
||||||
const params = {
|
const params = {
|
||||||
policy: values.policy,
|
|
||||||
data: {
|
data: {
|
||||||
|
policy: values.policy,
|
||||||
alerts: {
|
alerts: {
|
||||||
mention: !!values.mention,
|
mention: !!values.mention,
|
||||||
favourite: !!values.favourite,
|
favourite: !!values.favourite,
|
||||||
|
@ -749,7 +751,8 @@ function PushNotificationsSection({ onClose }) {
|
||||||
alertsCount++;
|
alertsCount++;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
const policyChanged = previousPolicyRef.current !== params.policy;
|
const policyChanged =
|
||||||
|
previousPolicyRef.current !== params.data.policy;
|
||||||
|
|
||||||
console.log('PN Form', {
|
console.log('PN Form', {
|
||||||
values,
|
values,
|
||||||
|
@ -780,6 +783,7 @@ function PushNotificationsSection({ onClose }) {
|
||||||
alert('Failed to remove subscription. Please try again.');
|
alert('Failed to remove subscription. Please try again.');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
}, 100);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<h3>Push Notifications (beta)</h3>
|
<h3>Push Notifications (beta)</h3>
|
||||||
|
|
Loading…
Reference in a new issue