2018-05-01 19:29:21 +02:00
|
|
|
import mpwoApi from '../mwpoApi/activities'
|
|
|
|
import { history } from '../index'
|
|
|
|
import { setError } from './index'
|
|
|
|
|
2018-05-03 21:42:54 +02:00
|
|
|
export const setGpx = gpxContent => ({
|
|
|
|
type: 'SET_GPX',
|
|
|
|
gpxContent,
|
|
|
|
})
|
2018-05-01 19:29:21 +02:00
|
|
|
|
2018-05-04 23:04:44 +02:00
|
|
|
export const addActivity = form => dispatch => mpwoApi
|
|
|
|
.addActivity(form)
|
|
|
|
.then(ret => {
|
|
|
|
if (ret.status === 'created') {
|
|
|
|
history.push('/')
|
|
|
|
} else {
|
|
|
|
dispatch(setError(`activities: ${ret.message}`))
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.catch(error => dispatch(setError(`activities: ${error}`)))
|
2018-05-03 21:42:54 +02:00
|
|
|
|
2018-05-04 23:04:44 +02:00
|
|
|
|
2018-05-08 18:20:41 +02:00
|
|
|
export const addActivityWithoutGpx = form => dispatch => mpwoApi
|
|
|
|
.addActivityWithoutGpx(form)
|
|
|
|
.then(ret => {
|
|
|
|
if (ret.status === 'created') {
|
|
|
|
history.push('/')
|
|
|
|
} else {
|
|
|
|
dispatch(setError(`activities: ${ret.message}`))
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.catch(error => dispatch(setError(`activities: ${error}`)))
|
|
|
|
|
|
|
|
|
2018-05-04 23:04:44 +02:00
|
|
|
export const getActivityGpx = activityId => dispatch => {
|
2018-05-04 22:30:11 +02:00
|
|
|
if (activityId) {
|
2018-05-03 21:42:54 +02:00
|
|
|
return mpwoApi
|
|
|
|
.getActivityGpx(activityId)
|
|
|
|
.then(ret => {
|
|
|
|
if (ret.status === 'success') {
|
|
|
|
dispatch(setGpx(ret.data.gpx))
|
|
|
|
} else {
|
|
|
|
dispatch(setError(`activities: ${ret.message}`))
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.catch(error => dispatch(setError(`activities: ${error}`)))
|
|
|
|
}
|
2018-05-04 23:04:44 +02:00
|
|
|
dispatch(setGpx(null))
|
2018-05-03 21:42:54 +02:00
|
|
|
}
|