1
1
import 'reflect-metadata' ;
2
2
import { container , singleton } from 'tsyringe' ;
3
3
import React from 'react' ;
4
- import ReactDOM from 'react-dom' ;
5
4
import { connect } from 'mo/react' ;
6
5
import { Float , IStatusBarItem } from 'mo/model' ;
7
6
import { Controller } from 'mo/react/controller' ;
8
7
import { IActionBarItemProps } from 'mo/components/actionBar' ;
9
8
import { INotificationItem } from 'mo/model/notification' ;
10
- import {
11
- NotificationPane ,
12
- NotificationStatusBarView ,
13
- } from 'mo/workbench/notification' ;
9
+ import { NotificationStatusBarView } from 'mo/workbench/notification' ;
14
10
import {
15
11
IStatusBarService ,
16
12
StatusBarService ,
17
13
INotificationService ,
18
14
NotificationService ,
19
- ILayoutService ,
20
- LayoutService ,
21
15
IBuiltinService ,
22
16
BuiltinService ,
23
17
} from 'mo/services' ;
@@ -41,29 +35,20 @@ export class NotificationController
41
35
implements INotificationController {
42
36
private readonly notificationService : INotificationService ;
43
37
private readonly statusBarService : IStatusBarService ;
44
- private readonly layoutService : ILayoutService ;
45
38
private readonly builtinService : IBuiltinService ;
46
39
47
40
constructor ( ) {
48
41
super ( ) ;
49
42
this . notificationService = container . resolve ( NotificationService ) ;
50
43
this . statusBarService = container . resolve ( StatusBarService ) ;
51
- this . layoutService = container . resolve ( LayoutService ) ;
52
44
this . builtinService = container . resolve ( BuiltinService ) ;
53
45
}
54
46
55
47
public onCloseNotification = ( item : INotificationItem < any > ) : void => {
56
- if ( typeof item . id === 'number' || typeof item . id === 'string' ) {
57
- this . notificationService . remove ( item . id ) ;
58
- }
48
+ this . notificationService . remove ( item . id ) ;
59
49
} ;
60
50
61
- private _notificationPane : HTMLDivElement | undefined = undefined ;
62
-
63
51
public toggleNotifications ( ) {
64
- if ( ! this . _notificationPane ) {
65
- this . renderNotificationPane ( ) ;
66
- }
67
52
this . notificationService . toggleNotification ( ) ;
68
53
}
69
54
@@ -82,7 +67,7 @@ export class NotificationController
82
67
} = this . builtinService . getConstants ( ) ;
83
68
84
69
if ( action === NOTIFICATION_CLEAR_ALL_ID ) {
85
- this . notificationService . toggleNotification ( ) ;
70
+ this . notificationService . clear ( ) ;
86
71
} else if ( action === NOTIFICATION_HIDE_ID ) {
87
72
this . toggleNotifications ( ) ;
88
73
}
@@ -100,35 +85,24 @@ export class NotificationController
100
85
this . notificationService ,
101
86
NotificationStatusBarView
102
87
) ;
88
+ /* istanbul ignore next */
103
89
const defaultNotification = {
104
90
...builtInNotification ,
105
91
actionBar : [ NOTIFICATION_CLEAR_ALL , NOTIFICATION_HIDE ] . filter (
106
92
Boolean
107
93
) as IActionBarItemProps [ ] ,
108
- render : ( ) => < NotificationView onClick = { this . onClick } /> ,
94
+ render : ( ) => (
95
+ < NotificationView
96
+ onClick = { this . onClick }
97
+ onActionBarClick = { this . onActionBarClick }
98
+ onCloseNotification = { this . onCloseNotification }
99
+ />
100
+ ) ,
109
101
} ;
110
102
this . notificationService . setState ( {
111
103
...defaultNotification ,
112
104
} ) ;
113
105
this . statusBarService . add ( defaultNotification , Float . right ) ;
114
106
}
115
107
}
116
-
117
- public renderNotificationPane ( ) {
118
- const NotificationPaneView = connect (
119
- this . notificationService ,
120
- NotificationPane
121
- ) ;
122
- const root = this . layoutService . container ;
123
- const container = document . createElement ( 'div' ) ;
124
- root ?. appendChild ( container ) ;
125
- ReactDOM . render (
126
- < NotificationPaneView
127
- onActionBarClick = { this . onActionBarClick }
128
- onCloseNotification = { this . onCloseNotification }
129
- /> ,
130
- container
131
- ) ;
132
- this . _notificationPane = container ;
133
- }
134
108
}
0 commit comments