mirror of
https://github.com/cinnyapp/cinny.git
synced 2025-02-28 08:03:05 +01:00
add system notification settings
This commit is contained in:
parent
e8ace5f784
commit
97ec9965ca
3 changed files with 114 additions and 0 deletions
|
@ -10,6 +10,7 @@ import { getMxIdLocalPart, mxcUrlToHttp } from '../../utils/matrix';
|
||||||
import { useMediaAuthentication } from '../../hooks/useMediaAuthentication';
|
import { useMediaAuthentication } from '../../hooks/useMediaAuthentication';
|
||||||
import { UserAvatar } from '../../components/user-avatar';
|
import { UserAvatar } from '../../components/user-avatar';
|
||||||
import { nameInitials } from '../../utils/common';
|
import { nameInitials } from '../../utils/common';
|
||||||
|
import { Notifications } from './notifications';
|
||||||
|
|
||||||
enum SettingsPages {
|
enum SettingsPages {
|
||||||
GeneralPage,
|
GeneralPage,
|
||||||
|
@ -162,6 +163,9 @@ export function Settings({ requestClose }: SettingsProps) {
|
||||||
{activePage === SettingsPages.AccountPage && (
|
{activePage === SettingsPages.AccountPage && (
|
||||||
<Account requestClose={handlePageRequestClose} />
|
<Account requestClose={handlePageRequestClose} />
|
||||||
)}
|
)}
|
||||||
|
{activePage === SettingsPages.NotificationPage && (
|
||||||
|
<Notifications requestClose={handlePageRequestClose} />
|
||||||
|
)}
|
||||||
</PageRoot>
|
</PageRoot>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
109
src/app/features/settings/notifications/Notifications.tsx
Normal file
109
src/app/features/settings/notifications/Notifications.tsx
Normal file
|
@ -0,0 +1,109 @@
|
||||||
|
import React from 'react';
|
||||||
|
import { Box, Text, IconButton, Icon, Icons, Scroll, Switch, Button, color } from 'folds';
|
||||||
|
import { Page, PageContent, PageHeader } from '../../../components/page';
|
||||||
|
import { SequenceCard } from '../../../components/sequence-card';
|
||||||
|
import { SequenceCardStyle } from '../styles.css';
|
||||||
|
import { SettingTile } from '../../../components/setting-tile';
|
||||||
|
import { useSetting } from '../../../state/hooks/settings';
|
||||||
|
import { settingsAtom } from '../../../state/settings';
|
||||||
|
import { usePermissionState } from '../../../hooks/usePermission';
|
||||||
|
|
||||||
|
function SystemNotification() {
|
||||||
|
const notifPermission = usePermissionState(
|
||||||
|
'notifications',
|
||||||
|
window.Notification.permission === 'default' ? 'prompt' : window.Notification.permission
|
||||||
|
);
|
||||||
|
const [showNotifications, setShowNotifications] = useSetting(settingsAtom, 'showNotifications');
|
||||||
|
const [isNotificationSounds, setIsNotificationSounds] = useSetting(
|
||||||
|
settingsAtom,
|
||||||
|
'isNotificationSounds'
|
||||||
|
);
|
||||||
|
|
||||||
|
const requestNotificationPermission = () => {
|
||||||
|
window.Notification.requestPermission();
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Box direction="Column" gap="100">
|
||||||
|
<Text size="L400">System</Text>
|
||||||
|
<SequenceCard
|
||||||
|
className={SequenceCardStyle}
|
||||||
|
variant="SurfaceVariant"
|
||||||
|
direction="Column"
|
||||||
|
gap="400"
|
||||||
|
>
|
||||||
|
<SettingTile
|
||||||
|
title="Desktop Notifications"
|
||||||
|
description={
|
||||||
|
notifPermission === 'denied' ? (
|
||||||
|
<Text as="span" style={{ color: color.Critical.Main }} size="T200">
|
||||||
|
Notification permission is blocked. Please allow notification permission from
|
||||||
|
browser address bar.
|
||||||
|
</Text>
|
||||||
|
) : (
|
||||||
|
<span>Show desktop notifications when message arrive.</span>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
after={
|
||||||
|
notifPermission === 'prompt' ? (
|
||||||
|
<Button size="300" radii="300" onClick={requestNotificationPermission}>
|
||||||
|
<Text size="B300">Enable</Text>
|
||||||
|
</Button>
|
||||||
|
) : (
|
||||||
|
<Switch
|
||||||
|
disabled={notifPermission !== 'granted'}
|
||||||
|
value={showNotifications}
|
||||||
|
onChange={setShowNotifications}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
</SequenceCard>
|
||||||
|
<SequenceCard
|
||||||
|
className={SequenceCardStyle}
|
||||||
|
variant="SurfaceVariant"
|
||||||
|
direction="Column"
|
||||||
|
gap="400"
|
||||||
|
>
|
||||||
|
<SettingTile
|
||||||
|
title="Notification Sound"
|
||||||
|
description="Play sound when new message arrive."
|
||||||
|
after={<Switch value={isNotificationSounds} onChange={setIsNotificationSounds} />}
|
||||||
|
/>
|
||||||
|
</SequenceCard>
|
||||||
|
</Box>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
type NotificationsProps = {
|
||||||
|
requestClose: () => void;
|
||||||
|
};
|
||||||
|
export function Notifications({ requestClose }: NotificationsProps) {
|
||||||
|
return (
|
||||||
|
<Page>
|
||||||
|
<PageHeader outlined={false}>
|
||||||
|
<Box grow="Yes" gap="200">
|
||||||
|
<Box grow="Yes" alignItems="Center" gap="200">
|
||||||
|
<Text size="H3" truncate>
|
||||||
|
Notifications
|
||||||
|
</Text>
|
||||||
|
</Box>
|
||||||
|
<Box shrink="No">
|
||||||
|
<IconButton onClick={requestClose} variant="Surface">
|
||||||
|
<Icon src={Icons.Cross} />
|
||||||
|
</IconButton>
|
||||||
|
</Box>
|
||||||
|
</Box>
|
||||||
|
</PageHeader>
|
||||||
|
<Box grow="Yes">
|
||||||
|
<Scroll hideTrack visibility="Hover">
|
||||||
|
<PageContent>
|
||||||
|
<Box direction="Column" gap="700">
|
||||||
|
<SystemNotification />
|
||||||
|
</Box>
|
||||||
|
</PageContent>
|
||||||
|
</Scroll>
|
||||||
|
</Box>
|
||||||
|
</Page>
|
||||||
|
);
|
||||||
|
}
|
1
src/app/features/settings/notifications/index.ts
Normal file
1
src/app/features/settings/notifications/index.ts
Normal file
|
@ -0,0 +1 @@
|
||||||
|
export * from './Notifications';
|
Loading…
Reference in a new issue