mirror of
https://github.com/cinnyapp/cinny.git
synced 2025-11-17 20:50:29 +03:00
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:
parent
e2228a18c1
commit
e6d6b0349e
9 changed files with 62 additions and 100 deletions
|
|
@ -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>}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue