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 ? (
) : (
)}
@@ -43,23 +58,37 @@ export default function ActivityCardHeader(props) {
/>
- {title}{' '}
-
+ {dataType === 'activity' ? (
+ <>
+ {title}{' '}
+
+
+
displayModal(true)}
+ title="Delete activity"
/>
-
- displayModal(true)}
- title="Delete activity"
- />
+ >
+ ) : (
+ <>
+
+ {title}
+ {' '}
+ - segment {segmentId + 1}
+ >
+ )}
+
{activityDate && (
{`${activityDate.activity_date} - ${activityDate.activity_time}`}
@@ -67,22 +96,22 @@ export default function ActivityCardHeader(props) {
)}
- {activity.next_activity ? (
+ {nextUrl ? (
) : (
)}
diff --git a/fittrackee_client/src/components/Activity/ActivityDisplay/ActivityCharts.jsx b/fittrackee_client/src/components/Activity/ActivityDisplay/ActivityCharts.jsx
index f5307914..15e1d531 100644
--- a/fittrackee_client/src/components/Activity/ActivityDisplay/ActivityCharts.jsx
+++ b/fittrackee_client/src/components/Activity/ActivityDisplay/ActivityCharts.jsx
@@ -5,7 +5,9 @@ import {
Area, ComposedChart, Line, ResponsiveContainer, Tooltip, XAxis, YAxis
} from 'recharts'
-import { getActivityChartData } from '../../../actions/activities'
+import {
+ getActivityChartData, getSegmentChartData
+} from '../../../actions/activities'
class ActivityCharts extends React.Component {
@@ -18,14 +20,24 @@ class ActivityCharts extends React.Component {
}
componentDidMount() {
- this.props.loadActivityData(this.props.activity.id)
+ if (this.props.dataType === 'activity') {
+ this.props.loadActivityData(this.props.activity.id)
+ } else {
+ this.props.loadSegmentData(this.props.activity.id, this.props.segmentId)
+ }
}
componentDidUpdate(prevProps) {
- if (prevProps.activity.id !==
- this.props.activity.id) {
+ if (this.props.dataType === 'activity' && (
+ prevProps.activity.id !== this.props.activity.id)
+ ) {
this.props.loadActivityData(this.props.activity.id)
}
+ if (this.props.dataType === 'segment' && (
+ prevProps.segmentId !== this.props.segmentId)
+ ) {
+ this.props.loadSegmentData(this.props.activity.id, this.props.segmentId)
+ }
}
componentWillUnmount() {
@@ -196,5 +208,8 @@ export default connect(
loadActivityData: activityId => {
dispatch(getActivityChartData(activityId))
},
+ loadSegmentData: (activityId, segmentId) => {
+ dispatch(getSegmentChartData(activityId, segmentId))
+ },
})
)(ActivityCharts)
diff --git a/fittrackee_client/src/components/Activity/ActivityDisplay/ActivityDetails.jsx b/fittrackee_client/src/components/Activity/ActivityDisplay/ActivityDetails.jsx
index f619b60d..9a5341a6 100644
--- a/fittrackee_client/src/components/Activity/ActivityDisplay/ActivityDetails.jsx
+++ b/fittrackee_client/src/components/Activity/ActivityDisplay/ActivityDetails.jsx
@@ -5,7 +5,6 @@ import ActivityWeather from './ActivityWeather'
export default function ActivityDetails(props) {
const { activity } = props
const withPauses = activity.pauses !== '0:00:00' && activity.pauses !== null
- const recordLDexists = activity.records.find(r => r.record_type === 'LD')
return (
@@ -14,7 +13,8 @@ export default function ActivityDetails(props) {
aria-hidden="true"
/>
Duration: {activity.moving}
- {recordLDexists && (
+ {activity.records && activity.records.find(r => r.record_type === 'LD'
+ ) && (
Distance: {activity.distance} km
- {activity.records.find(r => r.record_type === 'FD'
+ {activity.records && activity.records.find(r => r.record_type === 'FD'
) && (
Average speed: {activity.ave_speed} km/h
- {activity.records.find(r => r.record_type === 'AS'
+ {activity.records && activity.records.find(r => r.record_type === 'AS'
) && (
Max speed : {activity.max_speed} km/h
- {activity.records.find(r => r.record_type === 'MS'
+ {activity.records && activity.records.find(r => r.record_type === 'MS'
) && (
{
dispatch(getActivityGpx(activityId))
},
+ loadSegmentGpx: (activityId, segmentId) => {
+ dispatch(getSegmentGpx(activityId, segmentId))
+ },
})
)(ActivityMap)
diff --git a/fittrackee_client/src/components/Activity/ActivityDisplay/ActivityNotes.jsx b/fittrackee_client/src/components/Activity/ActivityDisplay/ActivityNotes.jsx
index dcd629dc..f3851334 100644
--- a/fittrackee_client/src/components/Activity/ActivityDisplay/ActivityNotes.jsx
+++ b/fittrackee_client/src/components/Activity/ActivityDisplay/ActivityNotes.jsx
@@ -3,11 +3,15 @@ import React from 'react'
export default function ActivityNotes(props) {
const { notes } = props
return (
-
-
- Notes
-
- {notes ? notes : 'No notes'}
+
+
+
+
+ Notes
+
+ {notes ? notes : 'No notes'}
+
+
diff --git a/fittrackee_client/src/components/Activity/ActivityDisplay/ActivitySegments.jsx b/fittrackee_client/src/components/Activity/ActivityDisplay/ActivitySegments.jsx
new file mode 100644
index 00000000..e1164445
--- /dev/null
+++ b/fittrackee_client/src/components/Activity/ActivityDisplay/ActivitySegments.jsx
@@ -0,0 +1,33 @@
+import React from 'react'
+import { Link } from 'react-router-dom'
+
+export default function ActivitySegments(props) {
+ const { segments } = props
+ return (
+
+
+
+
+ Segments
+
+
+ {segments.map((segment, index) => (
+ // eslint-disable-next-line react/no-array-index-key
+ -
+
+ segment {index + 1}
+ {' '}
+ ({segment.distance} km, duration: {segment.duration})
+
+ ))}
+
+
+
+
+
+
+ )
+}
diff --git a/fittrackee_client/src/components/Activity/ActivityDisplay/index.jsx b/fittrackee_client/src/components/Activity/ActivityDisplay/index.jsx
index 4308f777..4ec62edc 100644
--- a/fittrackee_client/src/components/Activity/ActivityDisplay/index.jsx
+++ b/fittrackee_client/src/components/Activity/ActivityDisplay/index.jsx
@@ -8,6 +8,7 @@ import ActivityDetails from './ActivityDetails'
import ActivityMap from './ActivityMap'
import ActivityNoMap from './ActivityNoMap'
import ActivityNotes from './ActivityNotes'
+import ActivitySegments from './ActivitySegments'
import CustomModal from '../../Common/CustomModal'
import { getOrUpdateData } from '../../../actions'
import { deleteActivity } from '../../../actions/activities'
@@ -66,7 +67,10 @@ class ActivityDisplay extends React.Component {
const [sport] = activity
? sports.filter(s => s.id === activity.sport_id)
: []
-
+ const segmentId = parseInt(this.props.match.params.segmentId)
+ const dataType = segmentId >= 0
+ ? 'segment'
+ : 'activity'
return (
@@ -94,6 +98,8 @@ class ActivityDisplay extends React.Component {
@@ -130,6 +142,8 @@ class ActivityDisplay extends React.Component {
Chart
this.updateCoordinates(e)
}
@@ -141,7 +155,14 @@ class ActivityDisplay extends React.Component {
)}
-
+ {dataType === 'activity' && (
+ <>
+
+ {activity.segments.length > 1 && (
+
+ )}
+ >
+ )}
)}
diff --git a/fittrackee_client/src/components/Activity/index.jsx b/fittrackee_client/src/components/Activity/index.jsx
index 0727844f..9af71836 100644
--- a/fittrackee_client/src/components/Activity/index.jsx
+++ b/fittrackee_client/src/components/Activity/index.jsx
@@ -26,6 +26,10 @@ function Activity () {
exact path="/activities/:activityId/edit"
component={ActivityEdit}
/>
+