Skip to content

Commit

Permalink
#1303 | On opening of app or completing full-sync, refresh CustomDash…
Browse files Browse the repository at this point in the history
…board counts only if one of them is marked as primary
  • Loading branch information
himeshr committed Mar 1, 2024
1 parent 25b2e30 commit fdfe251
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
8 changes: 7 additions & 1 deletion packages/openchs-android/src/action/LandingViewActions.js
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -17,6 +19,7 @@ class LandingViewActions {
static reset(state) {
return {
...state,
renderCustomDashboard: false,
home: false,
search: false,
register: false,
Expand All @@ -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,
};
}
Expand Down
14 changes: 10 additions & 4 deletions packages/openchs-android/src/service/SyncService.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down Expand Up @@ -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);
}
}
}

Expand Down
6 changes: 2 additions & 4 deletions packages/openchs-android/src/views/LandingView.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -58,7 +57,7 @@ class LandingView extends AbstractComponent {
}

didFocus() {
this.refreshCustomDashboardsCounts();
this.state.renderCustomDashboard && this.refreshCustomDashboardsCounts();
}

refreshCustomDashboardsCounts() {
Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit fdfe251

Please sign in to comment.