mirror of
https://github.com/cinnyapp/cinny.git
synced 2025-11-13 18:50:29 +03:00
Swap to using the atom values instead of raw setting them in the component. Passing the values forward as needed.
This commit is contained in:
parent
f31087e685
commit
72bb04f190
1 changed files with 11 additions and 10 deletions
|
|
@ -93,12 +93,15 @@ function EmailNotification() {
|
||||||
function WebPushNotificationSetting() {
|
function WebPushNotificationSetting() {
|
||||||
const mx = useMatrixClient();
|
const mx = useMatrixClient();
|
||||||
const clientConfig = useClientConfig();
|
const clientConfig = useClientConfig();
|
||||||
const [userPushPreference, setUserPushPreference] = useState<boolean>(false);
|
|
||||||
const [isLoading, setIsLoading] = useState<boolean>(true);
|
const [isLoading, setIsLoading] = useState<boolean>(true);
|
||||||
|
const [usePushNotifications, setPushNotifications] = useSetting(
|
||||||
|
settingsAtom,
|
||||||
|
'usePushNotifications'
|
||||||
|
);
|
||||||
|
const pushSubAtom = useAtom(pushSubscriptionAtom);
|
||||||
|
|
||||||
const browserPermission = usePermissionState('notifications', getNotificationState());
|
const browserPermission = usePermissionState('notifications', getNotificationState());
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const storedPreference = localStorage.getItem('cinny_web_push_enabled');
|
|
||||||
setUserPushPreference(storedPreference === 'true');
|
|
||||||
setIsLoading(false);
|
setIsLoading(false);
|
||||||
}, []);
|
}, []);
|
||||||
const handleRequestPermissionAndEnable = async () => {
|
const handleRequestPermissionAndEnable = async () => {
|
||||||
|
|
@ -106,9 +109,8 @@ function WebPushNotificationSetting() {
|
||||||
try {
|
try {
|
||||||
const permissionResult = await requestBrowserNotificationPermission();
|
const permissionResult = await requestBrowserNotificationPermission();
|
||||||
if (permissionResult === 'granted') {
|
if (permissionResult === 'granted') {
|
||||||
await enablePushNotifications(mx, clientConfig);
|
await enablePushNotifications(mx, clientConfig, pushSubAtom);
|
||||||
localStorage.setItem('cinny_web_push_enabled', 'true');
|
setPushNotifications(true);
|
||||||
setUserPushPreference(true);
|
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
setIsLoading(false);
|
setIsLoading(false);
|
||||||
|
|
@ -120,12 +122,11 @@ function WebPushNotificationSetting() {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (wantsPush) {
|
if (wantsPush) {
|
||||||
await enablePushNotifications(mx, clientConfig);
|
await enablePushNotifications(mx, clientConfig, pushSubAtom);
|
||||||
} else {
|
} else {
|
||||||
await disablePushNotifications(mx, clientConfig);
|
await disablePushNotifications(mx, clientConfig, pushSubAtom);
|
||||||
}
|
}
|
||||||
localStorage.setItem('cinny_web_push_enabled', String(wantsPush));
|
setPushNotifications(wantsPush);
|
||||||
setUserPushPreference(wantsPush);
|
|
||||||
} finally {
|
} finally {
|
||||||
setIsLoading(false);
|
setIsLoading(false);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue