Allow deleting individual notifications

This commit is contained in:
Philipp Heckel 2022-02-25 10:23:04 -05:00
parent 703f94a25f
commit f9e22dcaa9
2 changed files with 29 additions and 7 deletions

View file

@ -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 = () => {
<CssBaseline/>
<ActionBar
selectedSubscription={selectedSubscription}
onClearAll={handleClearAll}
onClearAll={handleDeleteAllNotifications}
onUnsubscribe={handleUnsubscribe}
onMobileDrawerToggle={() => setMobileDrawerOpen(!mobileDrawerOpen)}
/>
@ -237,7 +243,11 @@ const App = () => {
backgroundColor: (theme) => theme.palette.mode === 'light' ? theme.palette.grey[100] : theme.palette.grey[900]
}}>
<Toolbar/>
<NotificationList notifications={notifications}/>
{selectedSubscription !== null &&
<NotificationList
subscription={selectedSubscription}
onDeleteNotification={handleDeleteNotification}
/>}
</Box>
</Box>
</ThemeProvider>