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 ? (