File tree 7 files changed +50
-4
lines changed 7 files changed +50
-4
lines changed Original file line number Diff line number Diff line change
1
+ import { ResolveState } from 'overmind' ;
2
+ import { Reaction , Config } from '..' ;
3
+
4
+ export default ( ( ) => {
5
+ let _reaction : Reaction ;
6
+
7
+ return {
8
+ initialize ( reaction : Reaction ) {
9
+ _reaction = reaction ;
10
+ } ,
11
+ waitUntil (
12
+ test : ( state : ResolveState < Config [ 'state' ] > ) => boolean
13
+ ) : Promise < boolean > {
14
+ return new Promise ( resolve => {
15
+ _reaction ( test , bool => {
16
+ if ( bool === true ) {
17
+ resolve ( ) ;
18
+ }
19
+ } ) ;
20
+ } ) ;
21
+ } ,
22
+ } ;
23
+ } ) ( ) ;
Original file line number Diff line number Diff line change @@ -25,3 +25,4 @@ export { default as executor } from './executor';
25
25
export { default as stripe } from './stripe' ;
26
26
export { default as jwt } from './jwt' ;
27
27
export { default as preview } from './preview' ;
28
+ export { default as flows } from './flows' ;
Original file line number Diff line number Diff line change @@ -10,7 +10,10 @@ import {
10
10
export default {
11
11
convertTypeToStatus,
12
12
add ( notification : NotificationMessage ) {
13
- notificationState . addNotification ( notification ) ;
13
+ return notificationState . addNotification ( notification ) ;
14
+ } ,
15
+ remove ( id : string ) {
16
+ notificationState . removeNotification ( id ) ;
14
17
} ,
15
18
error ( message : string ) {
16
19
notificationState . addNotification ( {
Original file line number Diff line number Diff line change @@ -460,13 +460,16 @@ export const onOperation: Operator<LiveMessage<{
460
460
} ) ;
461
461
462
462
export const onConnectionLoss : Operator < LiveMessage > = mutate (
463
- ( { state, effects } ) => {
463
+ async ( { state, effects } ) => {
464
464
if ( ! state . live . reconnecting ) {
465
- effects . notificationToast . add ( {
465
+ const id = effects . notificationToast . add ( {
466
466
message : 'We lost connection with the live server, reconnecting...' ,
467
467
status : NotificationStatus . ERROR ,
468
468
} ) ;
469
469
state . live . reconnecting = true ;
470
+
471
+ await effects . flows . waitUntil ( s => s . live . reconnecting === false ) ;
472
+ effects . notificationToast . remove ( id ) ;
470
473
}
471
474
}
472
475
) ;
Original file line number Diff line number Diff line change @@ -17,6 +17,8 @@ export const onInitialize: OnInitialize = async (
17
17
onApplyOperation : actions . live . applyTransformation ,
18
18
} ) ;
19
19
20
+ effects . flows . initialize ( overmindInstance . reaction ) ;
21
+
20
22
effects . keybindingManager . initialize ( overmindInstance ) ;
21
23
22
24
effects . api . initialize ( {
Original file line number Diff line number Diff line change @@ -71,7 +71,7 @@ const DEFAULT_COLORS = {
71
71
} ;
72
72
73
73
const DEFAULT_BUTTON : IButtonType = props =>
74
- React . createElement ( 'button' , props ) ;
74
+ React . createElement ( 'button' , props ) ; // eslint-disable-line
75
75
76
76
export function Toasts ( {
77
77
state,
@@ -150,6 +150,18 @@ export function Toasts({
150
150
} ;
151
151
} , [ state ] ) ;
152
152
153
+ React . useEffect ( ( ) => {
154
+ const removeListener = state . onNotificationRemoved ( event => {
155
+ setNotificationsToShow ( notifications =>
156
+ notifications . filter ( n => n . id !== event . id )
157
+ ) ;
158
+ } ) ;
159
+
160
+ return ( ) => {
161
+ removeListener ( ) ;
162
+ } ;
163
+ } , [ state ] ) ;
164
+
153
165
const transitions = useTransition <
154
166
NotificationToast ,
155
167
{ overflow : string ; opacity : number ; height : number }
Original file line number Diff line number Diff line change @@ -55,9 +55,11 @@ export class NotificationState {
55
55
private readonly _onNotificationUpdated = new Emitter <
56
56
NotificationUpdatedEvent
57
57
> ( ) ;
58
+
58
59
private readonly _onNotificationRemoved = new Emitter <
59
60
NotificationRemovedEvent
60
61
> ( ) ;
62
+
61
63
onNotificationUpdated = this . _onNotificationUpdated . event ;
62
64
onNotificationRemoved = this . _onNotificationRemoved . event ;
63
65
You can’t perform that action at this time.
0 commit comments