diff --git a/packages/openchs-android/src/action/LandingViewActions.js b/packages/openchs-android/src/action/LandingViewActions.js index 5b7a4d471..6fa46e4bd 100644 --- a/packages/openchs-android/src/action/LandingViewActions.js +++ b/packages/openchs-android/src/action/LandingViewActions.js @@ -1,8 +1,10 @@ import _ from 'lodash' +import CustomDashboardService from '../service/customDashboard/CustomDashboardService'; class LandingViewActions { static getInitialState() { return { + renderCustomDashboard: false, dummy: false, home: false, search: false, @@ -17,6 +19,7 @@ class LandingViewActions { static reset(state) { return { ...state, + renderCustomDashboard: false, home: false, search: false, register: false, @@ -25,14 +28,17 @@ class LandingViewActions { } } - static onLoad(state, action) { + static onLoad(state, action, context) { const newState = LandingViewActions.reset(state); const syncRequired = _.isNil(action.syncRequired) ? true : action.syncRequired; + const customDashboardService = context.get(CustomDashboardService); + const renderCustomDashboard = customDashboardService.isCustomDashboardMarkedPrimary(); return { ...newState, dummy: !state.dummy, home: true, syncRequired, + renderCustomDashboard, previouslySelectedSubjectTypeUUID: action.cachedSubjectTypeUUID || newState.previouslySelectedSubjectTypeUUID, }; } diff --git a/packages/openchs-android/src/service/SyncService.js b/packages/openchs-android/src/service/SyncService.js index 0af8c61fa..b31984d5d 100644 --- a/packages/openchs-android/src/service/SyncService.js +++ b/packages/openchs-android/src/service/SyncService.js @@ -39,6 +39,7 @@ import {LandingViewActionsNames as LandingViewActions} from '../action/LandingVi import {MyDashboardActionNames} from '../action/mydashboard/MyDashboardActions'; import {CustomDashboardActionNames} from '../action/customDashboard/CustomDashboardActions'; import LocalCacheService from "./LocalCacheService"; +import CustomDashboardService from './customDashboard/CustomDashboardService'; function transformResourceToEntity(entityMetaData, entityResources) { return (acc, resource) => { @@ -402,13 +403,18 @@ class SyncService extends BaseService { this.context.getService(PrivilegeService).deleteRevokedEntities(); //Invoking this in MenuView.deleteData as well this.dispatchAction(IndividualSearchActions.ON_LOAD); - this.dispatchAction(MyDashboardActionNames.ON_LOAD); LocalCacheService.getPreviouslySelectedSubjectTypeUuid().then(cachedSubjectTypeUUID => { this.dispatchAction(LandingViewActions.ON_LOAD, {syncRequired, cachedSubjectTypeUUID}); }); - this.dispatchAction(CustomDashboardActionNames.ON_LOAD, {onlyPrimary: false}); - this.dispatchAction(CustomDashboardActionNames.REMOVE_OLDER_COUNTS); - setTimeout(() => this.dispatchAction(CustomDashboardActionNames.REFRESH_COUNT), 500); + const customDashboardService = this.context.getService(CustomDashboardService); + const renderCustomDashboard = customDashboardService.isCustomDashboardMarkedPrimary(); + if(!renderCustomDashboard) { + this.dispatchAction(MyDashboardActionNames.ON_LOAD); + } else { + this.dispatchAction(CustomDashboardActionNames.ON_LOAD, {onlyPrimary: false}); + this.dispatchAction(CustomDashboardActionNames.REMOVE_OLDER_COUNTS); + setTimeout(() => this.dispatchAction(CustomDashboardActionNames.REFRESH_COUNT), 500); + } } } diff --git a/packages/openchs-android/src/views/LandingView.js b/packages/openchs-android/src/views/LandingView.js index 476bd58c7..3387d2225 100644 --- a/packages/openchs-android/src/views/LandingView.js +++ b/packages/openchs-android/src/views/LandingView.js @@ -25,7 +25,6 @@ import EntypoIcon from "react-native-vector-icons/Entypo"; import PrivilegeService from "../service/PrivilegeService"; import CustomFilterService from "../service/CustomFilterService"; import CustomDashboardView from "./customDashboard/CustomDashboardView"; -import CustomDashboardService from "../service/customDashboard/CustomDashboardService"; import NewsService from "../service/news/NewsService"; import {CustomDashboardActionNames} from "../action/customDashboard/CustomDashboardActions"; import LocalCacheService from '../service/LocalCacheService'; @@ -58,7 +57,7 @@ class LandingView extends AbstractComponent { } didFocus() { - this.refreshCustomDashboardsCounts(); + this.state.renderCustomDashboard && this.refreshCustomDashboardsCounts(); } refreshCustomDashboardsCounts() { @@ -121,8 +120,7 @@ class LandingView extends AbstractComponent { } renderDashboard(startSync) { - const renderCustomDashboard = this.getService(CustomDashboardService).isCustomDashboardMarkedPrimary(); - return renderCustomDashboard ? this.renderCustomDashboard(startSync) : this.renderDefaultDashboard(startSync); + return this.state.renderCustomDashboard ? this.renderCustomDashboard(startSync) : this.renderDefaultDashboard(startSync); } render() {