Fix unread reset and notification settings (#1824)

* reset unread with client sync state change

* fix notification toggle setting not working

* revert formatOnSave vscode setting
This commit is contained in:
Ajay Bura 2024-07-23 10:44:32 +05:30 committed by GitHub
parent e2228a18c1
commit e6d6b0349e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 62 additions and 100 deletions

View file

@ -7,9 +7,8 @@ import settings from '../../../client/state/settings';
import navigation from '../../../client/state/navigation';
import {
toggleSystemTheme,
toggleNotifications, toggleNotificationSounds,
} from '../../../client/action/settings';
import { usePermission } from '../../hooks/usePermission';
import { usePermissionState } from '../../hooks/usePermission';
import Text from '../../atoms/text/Text';
import IconButton from '../../atoms/button/IconButton';
@ -230,23 +229,25 @@ function AppearanceSection() {
}
function NotificationsSection() {
const [permission, setPermission] = usePermission('notifications', window.Notification?.permission);
const [, updateState] = useState({});
const notifPermission = usePermissionState('notifications', window.Notification?.permission ?? "denied");
const [showNotifications, setShowNotifications] = useSetting(settingsAtom, 'showNotifications')
const [isNotificationSounds, setIsNotificationSounds] = useSetting(settingsAtom, 'isNotificationSounds')
const renderOptions = () => {
if (window.Notification === undefined) {
return <Text className="settings-notifications__not-supported">Not supported in this browser.</Text>;
}
if (permission === 'granted') {
if (notifPermission === 'denied') {
return <Text>Permission Denied</Text>
}
if (notifPermission === 'granted') {
return (
<Toggle
isActive={settings._showNotifications}
isActive={showNotifications}
onToggle={() => {
toggleNotifications();
setPermission(window.Notification?.permission);
updateState({});
setShowNotifications(!showNotifications);
}}
/>
);
@ -255,7 +256,9 @@ function NotificationsSection() {
return (
<Button
variant="primary"
onClick={() => window.Notification.requestPermission().then(setPermission)}
onClick={() => window.Notification.requestPermission().then(() => {
setShowNotifications(window.Notification?.permission === 'granted');
})}
>
Request permission
</Button>
@ -275,8 +278,8 @@ function NotificationsSection() {
title="Notification Sound"
options={(
<Toggle
isActive={settings.isNotificationSounds}
onToggle={() => { toggleNotificationSounds(); updateState({}); }}
isActive={isNotificationSounds}
onToggle={() => setIsNotificationSounds(!isNotificationSounds)}
/>
)}
content={<Text variant="b3">Play sound when new messages arrive.</Text>}