From d82a7300297150f00d606124e76a9b8084712ee2 Mon Sep 17 00:00:00 2001 From: Sam Date: Thu, 10 May 2018 20:17:03 +0200 Subject: [PATCH] Client: refactor --- mpwo_client/src/actions/user.js | 2 ++ .../src/components/Activities/ActivityAdd.jsx | 34 ++++++------------- .../components/Activities/ActivityDisplay.jsx | 5 +-- .../components/Activities/ActivityEdit.jsx | 1 - .../components/Admin/Sports/AdminSport.jsx | 4 +-- .../components/Admin/Sports/AdminSports.jsx | 1 - .../components/Admin/generic/AdminPage.jsx | 5 ++- mpwo_client/src/components/Admin/index.jsx | 5 ++- .../src/components/Dashboard/index.jsx | 1 - 9 files changed, 21 insertions(+), 37 deletions(-) diff --git a/mpwo_client/src/actions/user.js b/mpwo_client/src/actions/user.js index 38ce8cf9..d07997a2 100644 --- a/mpwo_client/src/actions/user.js +++ b/mpwo_client/src/actions/user.js @@ -1,6 +1,7 @@ import mpwoApiUser from '../mwpoApi/user' import { history } from '../index' import { generateIds } from '../utils' +import { getData } from './index' const AuthError = message => ({ type: 'AUTH_ERROR', message }) @@ -39,6 +40,7 @@ export const getProfile = () => dispatch => mpwoApiUser .getProfile() .then(ret => { if (ret.status === 'success') { + dispatch(getData('sports')) return dispatch(ProfileSuccess(ret)) } return dispatch(ProfileError(ret.message)) diff --git a/mpwo_client/src/components/Activities/ActivityAdd.jsx b/mpwo_client/src/components/Activities/ActivityAdd.jsx index 857a0893..77526ec9 100644 --- a/mpwo_client/src/components/Activities/ActivityAdd.jsx +++ b/mpwo_client/src/components/Activities/ActivityAdd.jsx @@ -2,26 +2,19 @@ import React from 'react' import { connect } from 'react-redux' import ActivityAddOrEdit from './ActivityAddOrEdit' -import { getData } from '../../actions/index' -class ActivityAdd extends React.Component { - componentDidMount() { - this.props.loadSports() - } - - render() { - const { message, sports } = this.props - return ( -
- -
- ) - } +function ActivityAdd (props) { + const { message, sports } = props + return ( +
+ +
+ ) } export default connect( @@ -30,9 +23,4 @@ export default connect( sports: state.sports.data, user: state.user, }), - dispatch => ({ - loadSports: () => { - dispatch(getData('sports')) - }, - }) )(ActivityAdd) diff --git a/mpwo_client/src/components/Activities/ActivityDisplay.jsx b/mpwo_client/src/components/Activities/ActivityDisplay.jsx index 2b01a6a5..fcfdf83e 100644 --- a/mpwo_client/src/components/Activities/ActivityDisplay.jsx +++ b/mpwo_client/src/components/Activities/ActivityDisplay.jsx @@ -17,9 +17,7 @@ class ActivityDisplay extends React.Component { } componentDidMount() { - this.props.loadActivity( - this.props.match.params.activityId - ) + this.props.loadActivity(this.props.match.params.activityId) } render() { @@ -148,7 +146,6 @@ export default connect( }, loadActivity: activityId => { dispatch(getData('activities', activityId)) - dispatch(getData('sports')) }, }) )(ActivityDisplay) diff --git a/mpwo_client/src/components/Activities/ActivityEdit.jsx b/mpwo_client/src/components/Activities/ActivityEdit.jsx index 684f4a56..21bedf29 100644 --- a/mpwo_client/src/components/Activities/ActivityEdit.jsx +++ b/mpwo_client/src/components/Activities/ActivityEdit.jsx @@ -38,7 +38,6 @@ export default connect( }), dispatch => ({ loadActivity: activityId => { - dispatch(getData('sports')) dispatch(getData('activities', activityId)) }, }) diff --git a/mpwo_client/src/components/Admin/Sports/AdminSport.jsx b/mpwo_client/src/components/Admin/Sports/AdminSport.jsx index 8ff1aae8..6a291228 100644 --- a/mpwo_client/src/components/Admin/Sports/AdminSport.jsx +++ b/mpwo_client/src/components/Admin/Sports/AdminSport.jsx @@ -6,9 +6,7 @@ import AdminDetail from '../generic/AdminDetail' class AdminSports extends React.Component { componentDidMount() { - this.props.loadSport( - this.props.location.pathname.replace('/admin/sport/', '') - ) + this.props.loadSport(this.props.match.params.sportId) } render() { const { sports } = this.props diff --git a/mpwo_client/src/components/Admin/Sports/AdminSports.jsx b/mpwo_client/src/components/Admin/Sports/AdminSports.jsx index 1f1bd410..2fb36f39 100644 --- a/mpwo_client/src/components/Admin/Sports/AdminSports.jsx +++ b/mpwo_client/src/components/Admin/Sports/AdminSports.jsx @@ -15,7 +15,6 @@ class AdminSports extends React.Component {
diff --git a/mpwo_client/src/components/Admin/generic/AdminPage.jsx b/mpwo_client/src/components/Admin/generic/AdminPage.jsx index 9b18c621..d72600e1 100644 --- a/mpwo_client/src/components/Admin/generic/AdminPage.jsx +++ b/mpwo_client/src/components/Admin/generic/AdminPage.jsx @@ -6,7 +6,7 @@ import { history } from '../../../index' export default function AdminPage(props) { - const { data, detailLink, target } = props + const { data, target } = props const { error } = data const results = data.data const tbKeys = [] @@ -51,7 +51,7 @@ export default function AdminPage(props) { if (key === 'id') { return ( - + {result[key]} @@ -82,7 +82,6 @@ export default function AdminPage(props) { )} - ) } diff --git a/mpwo_client/src/components/Admin/index.jsx b/mpwo_client/src/components/Admin/index.jsx index 515ae6c0..3fc55024 100644 --- a/mpwo_client/src/components/Admin/index.jsx +++ b/mpwo_client/src/components/Admin/index.jsx @@ -29,7 +29,10 @@ class Admin extends React.Component { exact path="/admin/sports/add" component={AdminSportsAdd} /> - + ) : ( diff --git a/mpwo_client/src/components/Dashboard/index.jsx b/mpwo_client/src/components/Dashboard/index.jsx index 665ebcdf..87fdd4fc 100644 --- a/mpwo_client/src/components/Dashboard/index.jsx +++ b/mpwo_client/src/components/Dashboard/index.jsx @@ -54,7 +54,6 @@ export default connect( dispatch => ({ loadActivities: () => { dispatch(getData('activities')) - dispatch(getData('sports')) }, }) )(DashBoard)