Skip to content
This repository has been archived by the owner on Dec 6, 2022. It is now read-only.

MES-3574 reload app config when app resumes #757

Merged
merged 6 commits into from
Sep 16, 2019

Conversation

buzzub
Copy link
Contributor

@buzzub buzzub commented Sep 12, 2019

Description

When the app starts up and loads the configuration successfully, store the current date in the appInfo part of the store.

Then using the platform 'resume` event, check if the date the app config was loaded is different to today's date, and if so, reload the app by setting the app root as the login page.

Checklist

  • PR title includes the JIRA ticket number
  • Branch is rebased against the latest develop
  • Code has been tested manually
  • PR link added to JIRA ticket
  • One review from each scrum team
  • Squashed commit contains the JIRA ticket number

Screenshots (optional)

),
),
)),
filter(([action, dateConfigLoaded]) => dateConfigLoaded !== this.dateTimeProvider.now().format('YYYY-MM-DD')),
Copy link
Contributor

Choose a reason for hiding this comment

The 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());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this action used for anything or is it just for info

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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 of() but the benefit of this is I'll be able to write a test.

There's also an AppSuspended action. It get's dispatched, but nothing acts on it (yet).

Copy link
Contributor

@TomBillingtonUK TomBillingtonUK left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice , clean and simple :)

@buzzub buzzub marked this pull request as ready for review September 13, 2019 13:57
Copy link
Contributor

@ammarhaiderbjss ammarhaiderbjss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implementation looks good, happy once tested on an enrolled device :)

Copy link
Contributor

@mgoldson mgoldson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just looked at this to try and broaden my understanding of the app - looks nice!
One thing I would like to see is a consistent approach to naming actions. Looks like the established pattern is VERB_NOUN using present tense for the verb. Some of the new actions introduced go with NOUN_VERB using past tense for the verb.

@buzzub
Copy link
Contributor Author

buzzub commented Sep 16, 2019

Just looked at this to try and broaden my understanding of the app - looks nice!
One thing I would like to see is a consistent approach to naming actions. Looks like the established pattern is VERB_NOUN using present tense for the verb. Some of the new actions introduced go with NOUN_VERB using past tense for the verb.

Just looked at this to try and broaden my understanding of the app - looks nice!
One thing I would like to see is a consistent approach to naming actions. Looks like the established pattern is VERB_NOUN using present tense for the verb. Some of the new actions introduced go with NOUN_VERB using past tense for the verb.

Good observation. If this refers to AppSuspended and AppResumed, then I think in this case the actions are correctly named because they are dispatched when the platform plugin events fire and as such they are past tense.

ResumeApp wouldn't make sense because that implies the action will cause an effect, where as it was the cordova plugin that did the resuming and the new action is reacting to that.

ResumedApp could work I guess but it sounds wrong.

@buzzub
Copy link
Contributor Author

buzzub commented Sep 16, 2019

Implementation looks good, happy once tested on an enrolled device :)

Andy tested and found no problems.

}

configureAccessibility = () => {
window.MobileAccessibility.updateTextZoom();
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor Author

@buzzub buzzub Sep 16, 2019

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:

constructor(mobileAccessibility: MobileAccessibility) {
  this.platform.ready()
    .then(() => mobileAccessibility.getTextZoom())
    .then(e => this.zoomLevel = e);
}

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.

Copy link
Contributor

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

loadConfigSuccessEffect$ = this.actions$.pipe(
ofType(appInfoActions.LOAD_CONFIG_SUCCESS),
switchMap(() => {
console.log('Config loaded successfully');
Copy link
Contributor

@rossfauldsbjss rossfauldsbjss Sep 16, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need console.logs?

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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.

Copy link
Contributor

@rossfauldsbjss rossfauldsbjss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good.
Couple of comments, but nothing that affects approval.

@buzzub buzzub merged commit a5009ff into develop Sep 16, 2019
@buzzub buzzub deleted the mes-3574-refresh-app-daily branch September 19, 2019 10:38
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging this pull request may close these issues.

5 participants