From b2af180e05ff559c0f5b5cadfe072d4f2a4f63b1 Mon Sep 17 00:00:00 2001 From: Sam Date: Sun, 25 Aug 2019 20:23:11 +0200 Subject: [PATCH] Client - display segments - #14 --- fittrackee_client/src/actions/activities.js | 32 ++++++++ .../ActivityDisplay/ActivityCardHeader.jsx | 75 +++++++++++++------ .../ActivityDisplay/ActivityCharts.jsx | 23 +++++- .../ActivityDisplay/ActivityDetails.jsx | 10 +-- .../Activity/ActivityDisplay/ActivityMap.jsx | 25 +++++-- .../ActivityDisplay/ActivityNotes.jsx | 14 ++-- .../ActivityDisplay/ActivitySegments.jsx | 33 ++++++++ .../Activity/ActivityDisplay/index.jsx | 27 ++++++- .../src/components/Activity/index.jsx | 4 + fittrackee_client/src/components/App.css | 2 +- 10 files changed, 199 insertions(+), 46 deletions(-) create mode 100644 fittrackee_client/src/components/Activity/ActivityDisplay/ActivitySegments.jsx diff --git a/fittrackee_client/src/actions/activities.js b/fittrackee_client/src/actions/activities.js index ac5ca75e..04e02b81 100644 --- a/fittrackee_client/src/actions/activities.js +++ b/fittrackee_client/src/actions/activities.js @@ -81,6 +81,22 @@ export const getActivityGpx = activityId => dispatch => { dispatch(setGpx(null)) } +export const getSegmentGpx = (activityId, segmentId) => dispatch => { + if (activityId) { + return FitTrackeeGenericApi + .getData(`activities/${activityId}/gpx/segment/${segmentId}`) + .then(ret => { + if (ret.status === 'success') { + dispatch(setGpx(ret.data.gpx)) + } else { + dispatch(setError(`activities: ${ret.message}`)) + } + }) + .catch(error => dispatch(setError(`activities: ${error}`))) + } + dispatch(setGpx(null)) +} + export const getActivityChartData = activityId => dispatch => { if (activityId) { @@ -98,6 +114,22 @@ export const getActivityChartData = activityId => dispatch => { dispatch(setChartData(null)) } +export const getSegmentChartData = (activityId, segmentId) => dispatch => { + if (activityId) { + return FitTrackeeGenericApi + .getData(`activities/${activityId}/chart_data/segment/${segmentId}`) + .then(ret => { + if (ret.status === 'success') { + dispatch(setChartData(formatChartData(ret.data.chart_data))) + } else { + dispatch(setError(`activities: ${ret.message}`)) + } + }) + .catch(error => dispatch(setError(`activities: ${error}`))) + } + dispatch(setChartData(null)) +} + export const deleteActivity = id => dispatch => FitTrackeeGenericApi .deleteData('activities', id) diff --git a/fittrackee_client/src/components/Activity/ActivityDisplay/ActivityCardHeader.jsx b/fittrackee_client/src/components/Activity/ActivityDisplay/ActivityCardHeader.jsx index c208b5d2..279b7778 100644 --- a/fittrackee_client/src/components/Activity/ActivityDisplay/ActivityCardHeader.jsx +++ b/fittrackee_client/src/components/Activity/ActivityDisplay/ActivityCardHeader.jsx @@ -6,32 +6,47 @@ import { formatActivityDate } from '../../../utils/activities' export default function ActivityCardHeader(props) { - const { activity, displayModal, sport, title, user } = props + const { + activity, dataType, displayModal, segmentId, sport, title, user + } = props const activityDate = activity ? formatActivityDate( getDateWithTZ(activity.activity_date, user.timezone) ) : null + + const previousUrl = dataType === 'segment' && segmentId !== 0 + ? `/activities/${activity.id}/segment/${segmentId - 1}` + : dataType === 'activity' && activity.previous_activity + ? `/activities/${activity.previous_activity}` + : null + const nextUrl = + dataType === 'segment' && segmentId < activity.segments.length - 1 + ? `/activities/${activity.id}/segment/${segmentId + 1}` + : dataType === 'activity' && activity.next_activity + ? `/activities/${activity.next_activity}` + : null + return (
- {activity.previous_activity ? ( + {previousUrl ? (