-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
162 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import moment from 'moment'; | ||
import { CACHING, PAGES } from '../../../constants'; | ||
import * as actionTypes from '../../types'; | ||
import { getAll } from '../../../views/Shared/Api'; | ||
|
||
export const loadOtzTotalWithDurableVLResults = () => async (dispatch, getState) => { | ||
const diffInMinutes = moment().diff( | ||
moment(getState().otzTotalWithDurableVlResults.lastFetch), | ||
'minutes' | ||
); | ||
if (getState().ui.ctTab !== 'otz' && | ||
getState().ui.currentPage !== PAGES.ct) { | ||
return; | ||
} | ||
else if ((diffInMinutes < CACHING.LONG) && getState().filters.filtered === false) { | ||
return; | ||
} else { | ||
await dispatch(fetchOtzTotalWithDurableVLResults()); | ||
} | ||
} | ||
|
||
export const fetchOtzTotalWithDurableVLResults = () => async (dispatch, getState) => { | ||
dispatch({ type: actionTypes.CT_OTZ_TOTAL_WITH_DURABLE_VL_RESULTS_REQUEST }); | ||
const params = { | ||
county: getState().filters.counties, | ||
subCounty: getState().filters.subCounties, | ||
facility: getState().filters.facilities, | ||
partner: getState().filters.partners, | ||
agency: getState().filters.agencies, | ||
project: getState().filters.projects, | ||
gender: getState().filters.genders, | ||
datimAgeGroup: getState().filters.datimAgeGroups | ||
}; | ||
const response = await getAll('care-treatment/getOtzTotalWithDurableVl', params); | ||
dispatch({ type: actionTypes.CT_OTZ_TOTAL_WITH_DURABLE_VL_RESULTS_FETCH, payload: { filtered: getState().filters.filtered, list: response }}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import * as actionTypes from "../../../actions/types"; | ||
|
||
const initialState = { | ||
lastFetch: null, | ||
loading: false, | ||
listUnfiltered: [], | ||
listFiltered: [], | ||
}; | ||
|
||
export default (state = initialState, action) => { | ||
let newState = { ...state }; | ||
switch (action.type) { | ||
case actionTypes.CT_OTZ_TOTAL_WITH_DURABLE_VL_RESULTS_REQUEST: | ||
newState.loading = true; | ||
return newState; | ||
case actionTypes.CT_OTZ_TOTAL_WITH_DURABLE_VL_RESULTS_FETCH: | ||
if (action.payload.filtered === true) { | ||
newState.listFiltered = action.payload.list; | ||
} else { | ||
newState.listUnfiltered = action.payload.list; | ||
newState.lastFetch = Date.now(); | ||
} | ||
newState.loading = false; | ||
return newState; | ||
case actionTypes.CT_OTZ_TOTAL_WITH_DURABLE_VL_RESULTS_FAILED: | ||
newState.loading = false; | ||
return newState; | ||
default: | ||
return state; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { createSelector } from 'reselect'; | ||
|
||
const filtered = state => state.filters.filtered; | ||
const listFiltered = state => state.otzTotalWithDurableVlResults.listFiltered; | ||
const listUnfiltered = state => state.otzTotalWithDurableVlResults.listUnfiltered; | ||
|
||
export const getOtzTotalWithDurableVlResults = createSelector( | ||
[listUnfiltered, listFiltered, filtered], | ||
(listUnfiltered, listFiltered, filtered) => { | ||
return filtered ? listFiltered : listUnfiltered; | ||
} | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters