File tree Expand file tree Collapse file tree 7 files changed +50
-4
lines changed
Expand file tree Collapse file tree 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';
2525export { default as stripe } from './stripe' ;
2626export { default as jwt } from './jwt' ;
2727export { 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 {
1010export default {
1111 convertTypeToStatus,
1212 add ( notification : NotificationMessage ) {
13- notificationState . addNotification ( notification ) ;
13+ return notificationState . addNotification ( notification ) ;
14+ } ,
15+ remove ( id : string ) {
16+ notificationState . removeNotification ( id ) ;
1417 } ,
1518 error ( message : string ) {
1619 notificationState . addNotification ( {
Original file line number Diff line number Diff line change @@ -460,13 +460,16 @@ export const onOperation: Operator<LiveMessage<{
460460} ) ;
461461
462462export const onConnectionLoss : Operator < LiveMessage > = mutate (
463- ( { state, effects } ) => {
463+ async ( { state, effects } ) => {
464464 if ( ! state . live . reconnecting ) {
465- effects . notificationToast . add ( {
465+ const id = effects . notificationToast . add ( {
466466 message : 'We lost connection with the live server, reconnecting...' ,
467467 status : NotificationStatus . ERROR ,
468468 } ) ;
469469 state . live . reconnecting = true ;
470+
471+ await effects . flows . waitUntil ( s => s . live . reconnecting === false ) ;
472+ effects . notificationToast . remove ( id ) ;
470473 }
471474 }
472475) ;
Original file line number Diff line number Diff line change @@ -17,6 +17,8 @@ export const onInitialize: OnInitialize = async (
1717 onApplyOperation : actions . live . applyTransformation ,
1818 } ) ;
1919
20+ effects . flows . initialize ( overmindInstance . reaction ) ;
21+
2022 effects . keybindingManager . initialize ( overmindInstance ) ;
2123
2224 effects . api . initialize ( {
Original file line number Diff line number Diff line change @@ -71,7 +71,7 @@ const DEFAULT_COLORS = {
7171} ;
7272
7373const DEFAULT_BUTTON : IButtonType = props =>
74- React . createElement ( 'button' , props ) ;
74+ React . createElement ( 'button' , props ) ; // eslint-disable-line
7575
7676export function Toasts ( {
7777 state,
@@ -150,6 +150,18 @@ export function Toasts({
150150 } ;
151151 } , [ state ] ) ;
152152
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+
153165 const transitions = useTransition <
154166 NotificationToast ,
155167 { overflow : string ; opacity : number ; height : number }
Original file line number Diff line number Diff line change @@ -55,9 +55,11 @@ export class NotificationState {
5555 private readonly _onNotificationUpdated = new Emitter <
5656 NotificationUpdatedEvent
5757 > ( ) ;
58+
5859 private readonly _onNotificationRemoved = new Emitter <
5960 NotificationRemovedEvent
6061 > ( ) ;
62+
6163 onNotificationUpdated = this . _onNotificationUpdated . event ;
6264 onNotificationRemoved = this . _onNotificationRemoved . event ;
6365
You can’t perform that action at this time.
0 commit comments