From 9fff48a49f89423ea67c89bdd3c16021971ee61a Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Thu, 23 Jun 2022 17:29:10 -0500 Subject: [PATCH] Alerts: refactor notifications_container --- .../ui/containers/notifications_container.tsx | 86 +++++++++++-------- app/soapbox/reducers/alerts.ts | 4 + app/soapbox/selectors/index.ts | 25 ------ 3 files changed, 55 insertions(+), 60 deletions(-) diff --git a/app/soapbox/features/ui/containers/notifications_container.tsx b/app/soapbox/features/ui/containers/notifications_container.tsx index 9cbcc6e98..566acffbb 100644 --- a/app/soapbox/features/ui/containers/notifications_container.tsx +++ b/app/soapbox/features/ui/containers/notifications_container.tsx @@ -1,57 +1,73 @@ import React from 'react'; import { useIntl } from 'react-intl'; import { NotificationStack, NotificationObject, StyleFactoryFn } from 'react-notification'; -import { Link } from 'react-router-dom'; +import { useHistory } from 'react-router-dom'; +import { dismissAlert } from 'soapbox/actions/alerts'; import { Button } from 'soapbox/components/ui'; import { useAppSelector, useAppDispatch } from 'soapbox/hooks'; -import { dismissAlert } from '../../../actions/alerts'; -import { getAlerts } from '../../../selectors'; - -const defaultBarStyleFactory: StyleFactoryFn = (index, style, _notification) => { - return Object.assign( - {}, - style, - { bottom: `${14 + index * 12 + index * 42}px` }, - ); -}; +import type { Alert } from 'soapbox/reducers/alerts'; +/** Portal for snackbar alerts. */ const SnackbarContainer: React.FC = () => { const intl = useIntl(); + const history = useHistory(); const dispatch = useAppDispatch(); - const notifications = useAppSelector(getAlerts); + const alerts = useAppSelector(state => state.alerts); - notifications.forEach(notification => { - ['title', 'message', 'actionLabel'].forEach(key => { - // @ts-ignore - const value = notification[key]; - - if (typeof value === 'object') { - // @ts-ignore - notification[key] = intl.formatMessage(value); - } - }); - - if (notification.action) { - const { action } = notification; - notification.action = ( -