From f9e22dcaa942f5ce2fab2282e733af0940fec5be Mon Sep 17 00:00:00 2001 From: Philipp Heckel Date: Fri, 25 Feb 2022 10:23:04 -0500 Subject: [PATCH] Allow deleting individual notifications --- web/src/components/App.js | 18 ++++++++++++++---- web/src/components/NotificationList.js | 18 +++++++++++++++--- 2 files changed, 29 insertions(+), 7 deletions(-) diff --git a/web/src/components/App.js b/web/src/components/App.js index 5c56a4b9..63055aa3 100644 --- a/web/src/components/App.js +++ b/web/src/components/App.js @@ -181,7 +181,14 @@ const App = () => { }); }); }; - const handleClearAll = (subscriptionId) => { + const handleDeleteNotification = (subscriptionId, notificationId) => { + console.log(`[App] Deleting notification ${notificationId} from ${subscriptionId}`); + setSubscriptions(prev => { + const newSubscription = prev.get(subscriptionId).deleteNotification(notificationId); + return prev.update(newSubscription).clone(); + }); + }; + const handleDeleteAllNotifications = (subscriptionId) => { console.log(`[App] Deleting all notifications from ${subscriptionId}`); setSubscriptions(prev => { const newSubscription = prev.get(subscriptionId).deleteAllNotifications(); @@ -196,7 +203,6 @@ const App = () => { return newSubscriptions; }); }; - const notifications = (selectedSubscription !== null) ? selectedSubscription.getNotifications() : []; useEffect(() => { setSubscriptions(repository.loadSubscriptions()); }, [/* initial render only */]); @@ -212,7 +218,7 @@ const App = () => { setMobileDrawerOpen(!mobileDrawerOpen)} /> @@ -237,7 +243,11 @@ const App = () => { backgroundColor: (theme) => theme.palette.mode === 'light' ? theme.palette.grey[100] : theme.palette.grey[900] }}> - + {selectedSubscription !== null && + } diff --git a/web/src/components/NotificationList.js b/web/src/components/NotificationList.js index 48b0e3f8..3c3cc75f 100644 --- a/web/src/components/NotificationList.js +++ b/web/src/components/NotificationList.js @@ -1,17 +1,26 @@ import Container from "@mui/material/Container"; -import {CardContent, Stack} from "@mui/material"; +import {CardContent, CardHeader, Stack} from "@mui/material"; import Card from "@mui/material/Card"; import Typography from "@mui/material/Typography"; import * as React from "react"; import {formatTitle, formatMessage, unmatchedTags} from "../app/utils"; +import IconButton from "@mui/material/IconButton"; +import CloseIcon from '@mui/icons-material/Close'; const NotificationList = (props) => { - const sortedNotifications = props.notifications.sort((a, b) => a.time < b.time); + const subscription = props.subscription; + const sortedNotifications = subscription.getNotifications() + .sort((a, b) => a.time < b.time); return ( {sortedNotifications.map(notification => - )} + props.onDeleteNotification(subscription.id, notificationId)} + />)} ); @@ -26,6 +35,9 @@ const NotificationItem = (props) => { return ( + props.onDelete(notification.id)} sx={{ float: 'right', marginRight: -1, marginTop: -1 }}> + + {date} {[1,2,4,5].includes(notification.priority) &&