Skip to content

Commit

Permalink
#1149 | Refactor code to remove duplication of reset() across SyncSer…
Browse files Browse the repository at this point in the history
…vice.js and MenuView.js
  • Loading branch information
himeshr committed Oct 27, 2023
1 parent 719d0ca commit 00668ba
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 20 deletions.
11 changes: 7 additions & 4 deletions packages/openchs-android/src/service/SyncService.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import AllSyncableEntityMetaData from "../model/AllSyncableEntityMetaData";
import ProgramConfigService from './ProgramConfigService';
import {IndividualSearchActionNames as IndividualSearchActions} from '../action/individual/IndividualSearchActions';
import {LandingViewActionsNames as LandingViewActions} from '../action/LandingViewActions';
import {MyDashboardActionNames} from '../action/mydashboard/MyDashboardActions';

@Service("syncService")
class SyncService extends BaseService {
Expand Down Expand Up @@ -359,24 +360,26 @@ class SyncService extends BaseService {
resetServicesAfterFullSyncCompletion(updatedSyncSource) {
if (updatedSyncSource !== SyncService.syncSources.ONLY_UPLOAD_BACKGROUND_JOB) {
General.logInfo("Sync", "Full Sync completed, performing reset")
setTimeout(() => this.reset(), 1);
setTimeout(() => this.reset(false), 1);
this.getService(SettingsService).initLanguages();
General.logInfo("Sync", 'Full Sync completed, reset completed');
}
}

reset() {
reset(syncRequired: false) {
this.context.getService(RuleEvaluationService).init();
this.context.getService(ProgramConfigService).init();
this.context.getService(MessageService).init();
this.context.getService(RuleService).init();
this.dispatchAction('RESET');
this.context.getService(PrivilegeService).deleteRevokedEntities();
this.context.getService(PrivilegeService).deleteRevokedEntities(); //Invoking this in MenuView.deleteData as well

//To load subjectType after sync
this.dispatchAction(IndividualSearchActions.ON_LOAD);
this.dispatchAction(MyDashboardActionNames.ON_LOAD); //Invoking this after full sync reset as well

//To re-render LandingView after sync
this.dispatchAction(LandingViewActions.ON_LOAD, {syncRequired: false});
this.dispatchAction(LandingViewActions.ON_LOAD, {syncRequired});
}
}

Expand Down
17 changes: 1 addition & 16 deletions packages/openchs-android/src/views/MenuView.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,25 +127,10 @@ class MenuView extends AbstractComponent {
TypedTransition.from(this).to(SettingsView);
}

reset() {
this.context.getService(RuleEvaluationService).init();
this.context.getService(ProgramConfigService).init();
this.context.getService(MessageService).init();
this.context.getService(RuleService).init();
this.dispatchAction('RESET');

//To load subjectType after sync
this.dispatchAction(IndividualSearchActions.ON_LOAD);
this.dispatchAction(MyDashboardActionNames.ON_LOAD);

//To re-render LandingView after sync
this.dispatchAction(LandingViewActions.ON_LOAD);
}

deleteData() {
this.getService(AuthService).getAuthProviderService().logout()
.then(() => this.getService(SyncService).clearData())
.then(() => this.reset())
.then(() => this.getService(SyncService).reset(true))
.then(() => CHSNavigator.navigateToLoginView(this, false));
}

Expand Down

0 comments on commit 00668ba

Please sign in to comment.