diff --git a/mpwo_api/mpwo_api/activities/models.py b/mpwo_api/mpwo_api/activities/models.py index 94370745..a2d44e45 100644 --- a/mpwo_api/mpwo_api/activities/models.py +++ b/mpwo_api/mpwo_api/activities/models.py @@ -160,6 +160,20 @@ class Activity(db.Model): self.duration = duration def serialize(self): + previous_activity = Activity.query.filter( + Activity.id != self.id, + Activity.user_id == self.user_id, + Activity.activity_date <= self.activity_date + ).order_by( + Activity.activity_date.desc() + ).first() + next_activity = Activity.query.filter( + Activity.id != self.id, + Activity.user_id == self.user_id, + Activity.activity_date >= self.activity_date + ).order_by( + Activity.activity_date.asc() + ).first() return { "id": self.id, "user_id": self.user_id, @@ -180,6 +194,8 @@ class Activity(db.Model): "ave_speed": float(self.ave_speed) if self.ave_speed else None, "with_gpx": self.gpx is not None, "bounds": [float(bound) for bound in self.bounds] if self.bounds else [], # noqa + "previous_activity": previous_activity.id if previous_activity else None, # noqa + "next_activity": next_activity.id if next_activity else None, "segments": [segment.serialize() for segment in self.segments], "records": [record.serialize() for record in self.records] } diff --git a/mpwo_client/src/actions/activities.js b/mpwo_client/src/actions/activities.js index 9609d3cb..2875c403 100644 --- a/mpwo_client/src/actions/activities.js +++ b/mpwo_client/src/actions/activities.js @@ -3,11 +3,6 @@ import mpwoApi from '../mwpoApi/activities' import { history } from '../index' import { setError } from './index' -export const endPagination = status => ({ - type: 'END_PAGINATION', - status, -}) - export const pushActivities = activities => ({ type: 'PUSH_ACTIVITIES', activities, @@ -90,9 +85,6 @@ export const getMoreActivities = page => dispatch => mpwoGenericApi if (ret.data.activities.length > 0) { dispatch(pushActivities(ret.data.activities)) } - if (ret.data.activities.length < 5) { - dispatch(endPagination(true)) - } } else { dispatch(setError(`activities: ${ret.message}`)) } diff --git a/mpwo_client/src/components/Activities/ActivityDisplay.jsx b/mpwo_client/src/components/Activities/ActivityDisplay.jsx index 20923ea4..c807edbd 100644 --- a/mpwo_client/src/components/Activities/ActivityDisplay.jsx +++ b/mpwo_client/src/components/Activities/ActivityDisplay.jsx @@ -51,7 +51,7 @@ class ActivityDisplay extends React.Component { }} close={() => this.setState({ displayModal: false })} />} - {activity && sport && ( + {activity && sport && activities.length === 1 && (