diff --git a/mpwo_client/src/actions/activities.js b/mpwo_client/src/actions/activities.js index 2e3b3a4c..0479fc4b 100644 --- a/mpwo_client/src/actions/activities.js +++ b/mpwo_client/src/actions/activities.js @@ -5,6 +5,7 @@ import mpwoApi from '../mwpoApi/activities' import { history } from '../index' import { formatChartData } from '../utils' import { setError, setLoading } from './index' +import { loadProfile } from './user' export const pushActivities = activities => ({ type: 'PUSH_ACTIVITIES', @@ -33,8 +34,10 @@ export const addActivity = form => dispatch => mpwoApi if (ret.data.activities.length === 0) { dispatch(setError('activities: no correct file')) } else if (ret.data.activities.length === 1) { + dispatch(loadProfile()) history.push(`/activities/${ret.data.activities[0].id}`) } else { // ret.data.activities.length > 1 + dispatch(loadProfile()) history.push('/') } } else { @@ -49,6 +52,7 @@ export const addActivityWithoutGpx = form => dispatch => mpwoApi .addActivityWithoutGpx(form) .then(ret => { if (ret.status === 'created') { + dispatch(loadProfile()) history.push(`/activities/${ret.data.activities[0].id}`) } else { dispatch(setError(`activities: ${ret.message}`)) @@ -95,6 +99,7 @@ export const deleteActivity = id => dispatch => mpwoGenericApi .deleteData('activities', id) .then(ret => { if (ret.status === 204) { + dispatch(loadProfile()) history.push('/') } else { dispatch(setError(`activities: ${ret.status}`)) @@ -107,6 +112,7 @@ export const editActivity = form => dispatch => mpwoGenericApi .updateData('activities', form) .then(ret => { if (ret.status === 'success') { + dispatch(loadProfile()) history.push(`/activities/${ret.data.activities[0].id}`) } else { dispatch(setError(`activities: ${ret.message}`)) diff --git a/mpwo_client/src/components/App.css b/mpwo_client/src/components/App.css index 47ed1f3b..36ce15a3 100644 --- a/mpwo_client/src/components/App.css +++ b/mpwo_client/src/components/App.css @@ -94,6 +94,10 @@ input, textarea { color: goldenrod; } +.fa-color { + color: #405976; +} + .leaflet-container { height: 400px; } @@ -161,6 +165,10 @@ input, textarea { max-height: 35px; } +.huge { + font-size: 25px; +} + .inactive-link { color: lightgrey; } diff --git a/mpwo_client/src/components/Dashboard/UserStatistics.jsx b/mpwo_client/src/components/Dashboard/UserStatistics.jsx new file mode 100644 index 00000000..80a9f87a --- /dev/null +++ b/mpwo_client/src/components/Dashboard/UserStatistics.jsx @@ -0,0 +1,64 @@ +import React from 'react' + + +export default function UserStatistics (props) { + const { user } = props + return ( +
+
+
+
+
+ +
+
+
{user.nbActivities}
+
{user.nbActivities === 1 ? 'activity' : 'activities'}
+
+
+
+
+
+
+
+
+ +
+
+
+ {Math.round(user.totalDistance * 100) / 100} +
+
km
+
+
+
+
+
+
+
+
+ +
+
+
{user.totalDuration}
+
total duration
+
+
+
+
+
+
+
+
+ +
+
+
{user.nbSports}
+
{`sport${user.nbSports === 1 ? '' : 's'}`}
+
+
+
+
+
+ ) +} diff --git a/mpwo_client/src/components/Dashboard/index.jsx b/mpwo_client/src/components/Dashboard/index.jsx index 47c2ec45..ab7e882d 100644 --- a/mpwo_client/src/components/Dashboard/index.jsx +++ b/mpwo_client/src/components/Dashboard/index.jsx @@ -6,6 +6,7 @@ import ActivityCard from './ActivityCard' import Calendar from './../Others/Calendar' import Records from './Records' import Statistics from './Statistics' +import UserStatistics from './UserStatistics' import { getData } from '../../actions' import { getMoreActivities } from '../../actions/activities' @@ -23,7 +24,7 @@ class DashBoard extends React.Component { render() { const { - activities, loadMoreActivities, message, records, sports + activities, loadMoreActivities, message, records, sports, user } = this.props const paginationEnd = activities.length > 0 ? activities[activities.length - 1].previous_activity === null @@ -39,6 +40,7 @@ class DashBoard extends React.Component { ) : ( (activities && sports.length > 0) && (
+
@@ -83,6 +85,7 @@ export default connect( message: state.message, records: state.records.data, sports: state.sports.data, + user: state.user, }), dispatch => ({ loadActivities: () => { diff --git a/mpwo_client/src/reducers/index.js b/mpwo_client/src/reducers/index.js index 08c1aa51..6a574d5a 100644 --- a/mpwo_client/src/reducers/index.js +++ b/mpwo_client/src/reducers/index.js @@ -185,6 +185,10 @@ const user = (state = initial.user, action) => { picture: action.message.data.picture === true ? action.message.data.picture : false, + nbActivities: action.message.data.nb_activities, + nbSports: action.message.data.nb_sports, + totalDistance: action.message.data.total_distance, + totalDuration: action.message.data.total_duration, } default: return state