mirror of
https://github.com/flarum/core.git
synced 2025-08-03 15:07:53 +02:00
feat: Delete all notifications (#3529)
* Add delete all notifications option * chore: `DELETE /api/notifications` as per conventions * test: can delete all notifications Co-authored-by: Sami Mazouz <ilyasmazouz@gmail.com>
This commit is contained in:
@@ -6,6 +6,7 @@ import Link from '../../common/components/Link';
|
||||
import LoadingIndicator from '../../common/components/LoadingIndicator';
|
||||
import Discussion from '../../common/models/Discussion';
|
||||
import ItemList from '../../common/utils/ItemList';
|
||||
import Tooltip from '../../common/components/Tooltip';
|
||||
|
||||
/**
|
||||
* The `NotificationList` component displays a list of the logged-in user's
|
||||
@@ -34,15 +35,36 @@ export default class NotificationList extends Component {
|
||||
|
||||
items.add(
|
||||
'mark_all_as_read',
|
||||
<Button
|
||||
className="Button Button--link"
|
||||
icon="fas fa-check"
|
||||
title={app.translator.trans('core.forum.notifications.mark_all_as_read_tooltip')}
|
||||
onclick={state.markAllAsRead.bind(state)}
|
||||
/>,
|
||||
<Tooltip text={app.translator.trans('core.forum.notifications.mark_all_as_read_tooltip')}>
|
||||
<Button
|
||||
className="Button Button--link"
|
||||
data-container=".NotificationList"
|
||||
icon="fas fa-check"
|
||||
title={app.translator.trans('core.forum.notifications.mark_all_as_read_tooltip')}
|
||||
onclick={state.markAllAsRead.bind(state)}
|
||||
/>
|
||||
</Tooltip>,
|
||||
70
|
||||
);
|
||||
|
||||
items.add(
|
||||
'delete_all',
|
||||
<Tooltip text={app.translator.trans('core.forum.notifications.delete_all_tooltip')}>
|
||||
<Button
|
||||
className="Button Button--link"
|
||||
data-container=".NotificationList"
|
||||
icon="fas fa-trash-alt"
|
||||
title={app.translator.trans('core.forum.notifications.delete_all_tooltip')}
|
||||
onclick={() => {
|
||||
if (confirm(app.translator.trans('core.forum.notifications.delete_all_confirm'))) {
|
||||
state.deleteAll.call(state);
|
||||
}
|
||||
}}
|
||||
/>
|
||||
</Tooltip>,
|
||||
50
|
||||
);
|
||||
|
||||
return items;
|
||||
}
|
||||
|
||||
|
@@ -46,4 +46,20 @@ export default class NotificationListState extends PaginatedListState<Notificati
|
||||
method: 'POST',
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete all of the notifications for this user.
|
||||
*/
|
||||
deleteAll() {
|
||||
if (this.pages.length === 0) return;
|
||||
|
||||
app.session.user?.pushAttributes({ unreadNotificationCount: 0 });
|
||||
|
||||
this.pages = [];
|
||||
|
||||
return app.request({
|
||||
url: app.forum.attribute('apiUrl') + '/notifications',
|
||||
method: 'DELETE',
|
||||
});
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user