Skip to content

Commit 5a5412d

Browse files
wip
1 parent 03ecef3 commit 5a5412d

File tree

1 file changed

+25
-10
lines changed

1 file changed

+25
-10
lines changed

framework/core/js/src/forum/components/NotificationList.js renamed to framework/core/js/src/forum/components/NotificationList.tsx

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import app from '../../forum/app';
2-
import Component from '../../common/Component';
1+
import app from '../app';
2+
import Component, { ComponentAttrs } from '../../common/Component';
33
import listItems from '../../common/helpers/listItems';
44
import Button from '../../common/components/Button';
55
import Link from '../../common/components/Link';
@@ -9,12 +9,26 @@ import Tooltip from '../../common/components/Tooltip';
99
import HeaderList from './HeaderList';
1010
import HeaderListGroup from './HeaderListGroup';
1111
import NotificationType from './NotificationType';
12+
import extractText from '../../common/utils/extractText';
13+
14+
import type NotificationListState from '../states/NotificationListState';
15+
import type Notification from '../../common/models/Notification';
16+
import type Mithril from 'mithril';
17+
18+
export type NotificationGroup = {
19+
discussion: Discussion | null;
20+
notifications: Notification[];
21+
};
22+
23+
export interface INotificationListAttrs extends ComponentAttrs {
24+
state: NotificationListState;
25+
}
1226

1327
/**
1428
* The `NotificationList` component displays a list of the logged-in user's
1529
* notifications, grouped by discussion.
1630
*/
17-
export default class NotificationList extends Component {
31+
export default class NotificationList<CustomAttrs extends INotificationListAttrs = INotificationListAttrs> extends Component<CustomAttrs> {
1832
view() {
1933
const state = this.attrs.state;
2034

@@ -34,7 +48,7 @@ export default class NotificationList extends Component {
3448
}
3549

3650
controlItems() {
37-
const items = new ItemList();
51+
const items = new ItemList<Mithril.Children>();
3852
const state = this.attrs.state;
3953

4054
items.add(
@@ -58,7 +72,7 @@ export default class NotificationList extends Component {
5872
icon="fas fa-trash-alt"
5973
title={app.translator.trans('core.forum.notifications.delete_all_tooltip')}
6074
onclick={() => {
61-
if (confirm(app.translator.trans('core.forum.notifications.delete_all_confirm'))) {
75+
if (confirm(extractText(app.translator.trans('core.forum.notifications.delete_all_confirm')))) {
6276
state.deleteAll.call(state);
6377
}
6478
}}
@@ -70,13 +84,13 @@ export default class NotificationList extends Component {
7084
return items;
7185
}
7286

73-
content(state) {
87+
content(state: NotificationListState) {
7488
if (!state.isLoading() && state.hasItems()) {
7589
return state.getPages().map((page) => {
76-
const groups = [];
90+
const groups: NotificationGroup[] = [];
7791
const discussions = {};
7892

79-
page.items.forEach((notification) => {
93+
page.items.forEach((notification: Notification) => {
8094
const subject = notification.subject();
8195

8296
if (typeof subject === 'undefined') return;
@@ -101,7 +115,6 @@ export default class NotificationList extends Component {
101115

102116
return groups.map((group) => {
103117
const badges = group.discussion && group.discussion.badges().toArray();
104-
105118
return (
106119
<HeaderListGroup
107120
label={
@@ -115,7 +128,9 @@ export default class NotificationList extends Component {
115128
)
116129
}
117130
>
118-
{group.notifications.map((notification) => <NotificationType notification={notification} />).filter((component) => !!component)}
131+
{group.notifications
132+
.map((notification: Notification) => <NotificationType notification={notification} />)
133+
.filter((component: Mithril.Children) => !!component)}
119134
</HeaderListGroup>
120135
);
121136
});

0 commit comments

Comments
 (0)