diff --git a/src/models/chart.js b/src/models/chart.js index a1ded2cfc1b92c050337c48ed6af6c22cd17b3a5..6922a7511e3c4e9f51d399b728d65a4c98be4aed 100644 --- a/src/models/chart.js +++ b/src/models/chart.js @@ -14,10 +14,15 @@ export default { salesTypeDataOnline: [], salesTypeDataOffline: [], radarData: [], + loading: false, }, effects: { *fetch(_, { call, put }) { + yield put({ + type: 'changeLoading', + payload: true, + }); const response = yield call(fakeChartData); yield put({ type: 'save', @@ -40,12 +45,7 @@ export default { return { ...state, ...payload, - }; - }, - setter(state, { payload }) { - return { - ...state, - ...payload, + loading: false, }; }, clear() { @@ -62,5 +62,11 @@ export default { radarData: [], }; }, + changeLoading(state, { payload }) { + return { + ...state, + loading: payload, + }; + }, }, }; diff --git a/src/routes/Dashboard/Analysis.js b/src/routes/Dashboard/Analysis.js index 1e4228c98479bf4fc5776248a8d39efd89c71fb5..a2bd4df7ab722ea1c3fec8de8ce985d6672b27af 100644 --- a/src/routes/Dashboard/Analysis.js +++ b/src/routes/Dashboard/Analysis.js @@ -27,7 +27,6 @@ for (let i = 0; i < 7; i += 1) { })) export default class Analysis extends Component { state = { - loading: true, salesType: 'all', currentTabKey: '', rangePickerValue: [], @@ -36,7 +35,7 @@ export default class Analysis extends Component { componentDidMount() { this.props.dispatch({ type: 'chart/fetch', - }).then(() => this.setState({ loading: false })); + }); } componentWillUnmount() { @@ -90,7 +89,7 @@ export default class Analysis extends Component { } render() { - const { rangePickerValue, salesType, currentTabKey, loading } = this.state; + const { rangePickerValue, salesType, currentTabKey } = this.state; const { chart } = this.props; const { visitData, @@ -102,6 +101,7 @@ export default class Analysis extends Component { salesTypeData, salesTypeDataOnline, salesTypeDataOffline, + loading, } = chart; const salesPieData = salesType === 'all' ?