mirror of
https://github.com/muerwre/vault-frontend.git
synced 2025-04-25 04:46:40 +07:00
notifications: show toggle button on list if notifications disabled
This commit is contained in:
parent
f9e0ecdd0c
commit
14bf5be65f
8 changed files with 52 additions and 31 deletions
|
@ -5,4 +5,5 @@
|
||||||
grid-template-columns: 1fr auto;
|
grid-template-columns: 1fr auto;
|
||||||
row-gap: $gap;
|
row-gap: $gap;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
|
font: $font_14_medium;
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,26 +51,18 @@ const NotificationSettingsForm: FC<NotificationSettingsFormProps> = ({
|
||||||
return (
|
return (
|
||||||
<Group>
|
<Group>
|
||||||
<Card>
|
<Card>
|
||||||
<InputRow className={styles.row} input={toggle('enabled')}>
|
<InputRow input={toggle('enabled')}>Получать уведомления</InputRow>
|
||||||
Получать уведомления
|
|
||||||
</InputRow>
|
|
||||||
</Card>
|
</Card>
|
||||||
|
|
||||||
<div />
|
<div />
|
||||||
|
|
||||||
<Zone title="Типы уведомлений">
|
<Zone title="Типы уведомлений">
|
||||||
<Group>
|
<Group>
|
||||||
<InputRow
|
<InputRow input={toggle('flow', !values.enabled)}>
|
||||||
className={styles.row}
|
|
||||||
input={toggle('flow', !values.enabled)}
|
|
||||||
>
|
|
||||||
Новые посты
|
Новые посты
|
||||||
</InputRow>
|
</InputRow>
|
||||||
|
|
||||||
<InputRow
|
<InputRow input={toggle('comments', !values.enabled)}>
|
||||||
className={styles.row}
|
|
||||||
input={toggle('comments', !values.enabled)}
|
|
||||||
>
|
|
||||||
Комментарии
|
Комментарии
|
||||||
</InputRow>
|
</InputRow>
|
||||||
</Group>
|
</Group>
|
||||||
|
@ -80,16 +72,11 @@ const NotificationSettingsForm: FC<NotificationSettingsFormProps> = ({
|
||||||
|
|
||||||
<Zone title="Способы доставки">
|
<Zone title="Способы доставки">
|
||||||
<Group>
|
<Group>
|
||||||
<InputRow
|
<InputRow input={toggle('showIndicator', !values.enabled)}>
|
||||||
className={styles.row}
|
|
||||||
input={toggle('showIndicator', !values.enabled)}
|
|
||||||
>
|
|
||||||
На иконке профиля
|
На иконке профиля
|
||||||
</InputRow>
|
</InputRow>
|
||||||
|
|
||||||
<InputRow className={styles.row} input={telegramInput}>
|
<InputRow input={telegramInput}>Телеграм</InputRow>
|
||||||
Телеграм
|
|
||||||
</InputRow>
|
|
||||||
</Group>
|
</Group>
|
||||||
</Zone>
|
</Zone>
|
||||||
</Group>
|
</Group>
|
||||||
|
|
|
@ -5,7 +5,3 @@
|
||||||
grid-auto-flow: row;
|
grid-auto-flow: row;
|
||||||
row-gap: $gap;
|
row-gap: $gap;
|
||||||
}
|
}
|
||||||
|
|
||||||
.row {
|
|
||||||
font: $font_14_regular;
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,5 +1,9 @@
|
||||||
import { FC, useEffect } from 'react';
|
import { FC, useEffect } from 'react';
|
||||||
|
|
||||||
|
import classNames from 'classnames';
|
||||||
|
|
||||||
|
import { Button } from '~/components/input/Button';
|
||||||
|
import { InputRow } from '~/components/input/InputRow';
|
||||||
import { LoaderScreen } from '~/components/input/LoaderScreen';
|
import { LoaderScreen } from '~/components/input/LoaderScreen';
|
||||||
import { NotificationComment } from '~/components/notifications/NotificationComment';
|
import { NotificationComment } from '~/components/notifications/NotificationComment';
|
||||||
import { useNotificationsList } from '~/hooks/notifications/useNotificationsList';
|
import { useNotificationsList } from '~/hooks/notifications/useNotificationsList';
|
||||||
|
@ -11,6 +15,7 @@ interface NotificationListProps {}
|
||||||
|
|
||||||
const NotificationList: FC<NotificationListProps> = () => {
|
const NotificationList: FC<NotificationListProps> = () => {
|
||||||
const { isLoading, items } = useNotificationsList();
|
const { isLoading, items } = useNotificationsList();
|
||||||
|
const { enabled, toggleEnabled } = useNotifications();
|
||||||
const { markAsRead } = useNotifications();
|
const { markAsRead } = useNotifications();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
@ -23,8 +28,21 @@ const NotificationList: FC<NotificationListProps> = () => {
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={styles.grid}>
|
<div className={styles.grid}>
|
||||||
{/* <div className={styles.head}>HEAD</div> */}
|
{!enabled && (
|
||||||
<div className={styles.list}>
|
<div className={styles.head}>
|
||||||
|
<InputRow
|
||||||
|
input={
|
||||||
|
<Button size="small" onClick={toggleEnabled}>
|
||||||
|
Включить
|
||||||
|
</Button>
|
||||||
|
}
|
||||||
|
>
|
||||||
|
Уведомления выключены
|
||||||
|
</InputRow>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
<div className={classNames(styles.list, { [styles.inactive]: !enabled })}>
|
||||||
<div className={styles.items}>
|
<div className={styles.items}>
|
||||||
{items?.map((item) => (
|
{items?.map((item) => (
|
||||||
<div className={styles.item} key={item.created_at}>
|
<div className={styles.item} key={item.created_at}>
|
||||||
|
|
|
@ -23,6 +23,21 @@
|
||||||
flex: 1 1;
|
flex: 1 1;
|
||||||
overflow: auto;
|
overflow: auto;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
|
position: relative;
|
||||||
|
|
||||||
|
&.inactive {
|
||||||
|
opacity: 0.3;
|
||||||
|
overflow: hidden;
|
||||||
|
|
||||||
|
&::after {
|
||||||
|
content: ' ';
|
||||||
|
inset: 0;
|
||||||
|
position: absolute;
|
||||||
|
background: linear-gradient(transparent, $content_bg_backdrop);
|
||||||
|
pointer-events: none;
|
||||||
|
touch-action: none;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.items {
|
.items {
|
||||||
|
|
|
@ -38,6 +38,11 @@ export const useNotificationSettings = () => {
|
||||||
update({ lastSeen: lastDate.toISOString() });
|
update({ lastSeen: lastDate.toISOString() });
|
||||||
}, [update, lastDate, lastSeen]);
|
}, [update, lastDate, lastSeen]);
|
||||||
|
|
||||||
|
const toggleEnabled = useCallback(
|
||||||
|
() => update({ enabled: !settings?.enabled }),
|
||||||
|
[update, settings],
|
||||||
|
);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
enabled,
|
enabled,
|
||||||
hasNew,
|
hasNew,
|
||||||
|
@ -48,5 +53,6 @@ export const useNotificationSettings = () => {
|
||||||
refresh,
|
refresh,
|
||||||
update,
|
update,
|
||||||
loading: isLoading,
|
loading: isLoading,
|
||||||
|
toggleEnabled,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -8,13 +8,10 @@ import { useAuth } from '../auth/useAuth';
|
||||||
export const useNotificationsList = () => {
|
export const useNotificationsList = () => {
|
||||||
const { isUser } = useAuth();
|
const { isUser } = useAuth();
|
||||||
|
|
||||||
const {
|
const { data, isValidating, error } = useSWR(
|
||||||
data,
|
isUser ? API.NOTIFICATIONS.LIST : null,
|
||||||
isValidating: isLoading,
|
async () => apiGetNotifications(),
|
||||||
error,
|
|
||||||
} = useSWR(isUser ? API.NOTIFICATIONS.LIST : null, async () =>
|
|
||||||
apiGetNotifications(),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
return { isLoading, error, ...data };
|
return { isLoading: isValidating && !data, error, ...data };
|
||||||
};
|
};
|
||||||
|
|
|
@ -11,6 +11,7 @@ const defaultValue = {
|
||||||
enabled: false,
|
enabled: false,
|
||||||
hasNew: false,
|
hasNew: false,
|
||||||
indicatorEnabled: false,
|
indicatorEnabled: false,
|
||||||
|
toggleEnabled: () => {},
|
||||||
markAsRead: () => {},
|
markAsRead: () => {},
|
||||||
refresh: () => Promise.resolve() as Promise<unknown>,
|
refresh: () => Promise.resolve() as Promise<unknown>,
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue