-
Notifications
You must be signed in to change notification settings - Fork 4
MES-3574 reload app config when app resumes #757
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,17 +2,26 @@ import { Injectable } from '@angular/core'; | |
import { Effect, Actions, ofType } from '@ngrx/effects'; | ||
|
||
import { of } from 'rxjs/observable/of'; | ||
import { map, switchMap, catchError } from 'rxjs/operators'; | ||
|
||
import { map, switchMap, catchError, concatMap, withLatestFrom, filter } from 'rxjs/operators'; | ||
import { StoreModel } from '../../shared/models/store.model'; | ||
import { Store, select } from '@ngrx/store'; | ||
import * as appInfoActions from './app-info.actions'; | ||
import { AppInfoProvider } from '../../providers/app-info/app-info'; | ||
import { HttpErrorResponse } from '@angular/common/http'; | ||
import { DateTimeProvider } from '../../providers/date-time/date-time'; | ||
import { getAppInfoState } from './app-info.reducer'; | ||
import { getDateConfigLoaded } from './app-info.selector'; | ||
import { LOGIN_PAGE } from '../../pages/page-names.constants'; | ||
import { NavigationProvider } from '../../providers/navigation/navigation'; | ||
|
||
@Injectable() | ||
export class AppInfoEffects { | ||
constructor( | ||
private actions$: Actions, | ||
private appInfoProvider: AppInfoProvider, | ||
private dateTimeProvider: DateTimeProvider, | ||
private store$: Store<StoreModel>, | ||
private navigationProvider: NavigationProvider, | ||
) {} | ||
|
||
@Effect() | ||
|
@@ -27,4 +36,32 @@ export class AppInfoEffects { | |
); | ||
}), | ||
); | ||
|
||
@Effect() | ||
loadConfigSuccessEffect$ = this.actions$.pipe( | ||
ofType(appInfoActions.LOAD_CONFIG_SUCCESS), | ||
switchMap(() => { | ||
console.log('Config loaded successfully'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do we need console.logs? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think Ammar wanted this. I can't remember exactly why... but it definitely made sense at the time. |
||
return of(new appInfoActions.SetDateConfigLoaded(this.dateTimeProvider.now().format('YYYY-MM-DD'))); | ||
}), | ||
); | ||
|
||
@Effect() | ||
appResumedEffect$ = this.actions$.pipe( | ||
ofType(appInfoActions.APP_RESUMED), | ||
concatMap(action => of(action).pipe( | ||
withLatestFrom( | ||
this.store$.pipe( | ||
select(getAppInfoState), | ||
select(getDateConfigLoaded), | ||
), | ||
), | ||
)), | ||
filter(([action, dateConfigLoaded]) => dateConfigLoaded !== this.dateTimeProvider.now().format('YYYY-MM-DD')), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice 😍 |
||
switchMap(([action, dateConfigLoaded]) => { | ||
console.log('App resumed after being suspended. Config was not loaded today... app will refresh'); | ||
this.navigationProvider.getNav().setRoot(LOGIN_PAGE); | ||
return of(new appInfoActions.RestartApp()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this action used for anything or is it just for info There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, it's just for info. Need to return an observable, so figured I'd return a descriptive action. Could easily just return empty There's also an |
||
}), | ||
); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wondering about the removal of the window && window.MobileAccessibility line (51).
Is this because window is guaranteed to exists and this was an unnecessary check?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Exactly. And we can assume
MobileAccessibility
will exist too unless the plugin fails.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, we shouldn't really need to use
window.MobileAccessibility
as this should work:see more at danielsogl/awesome-cordova-plugins#2138
...but it doesn't. The signature is wrong - it doesn't return a promise, it returns a callback ... but you can't pass it a function. Went down a rabbit hole trying to reference the plugin correctly. In the end, decided to leave the code as is because it works.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How does this react in the browser , we know the plugin won't be there and that line will error