Persist APoint updates to server

pull/10616/head
Luke Morris 2018-02-20 15:43:47 -08:00
parent 76de1f9a1d
commit 25cb1d2858
4 changed files with 27 additions and 7 deletions

View File

@ -72,3 +72,8 @@ export const deleteAnnotationAsync = annotation => async dispatch => {
await api.deleteAnnotation(annotation)
dispatch(deleteAnnotation(annotation))
}
export const updateAnnotationAsync = annotation => async dispatch => {
await api.updateAnnotation(annotation)
dispatch(updateAnnotation(annotation))
}

View File

@ -13,8 +13,8 @@ const annoToRFC = anno => ({
endTime: msToRFC(anno.endTime),
})
export const createAnnotation = async (url, newAnno) => {
const data = annoToRFC(newAnno)
export const createAnnotation = async (url, annotation) => {
const data = annoToRFC(annotation)
const response = await AJAX({method: 'POST', url, data})
return annoToMillisecond(response.data)
}
@ -32,3 +32,9 @@ export const deleteAnnotation = async annotation => {
const url = annotation.links.self
await AJAX({method: 'DELETE', url})
}
export const updateAnnotation = async annotation => {
const url = annotation.links.self
const data = annoToRFC(annotation)
await AJAX({method: 'PATCH', url, data})
}

View File

@ -15,7 +15,6 @@ class Annotation extends Component {
? <AnnotationPoint
annotation={annotation}
mode={mode}
onUpdateAnnotation={onUpdateAnnotation}
dygraph={dygraph}
/>
: <AnnotationSpan

View File

@ -1,8 +1,10 @@
import React, {PropTypes} from 'react'
import {connect} from 'react-redux'
import {EDITING} from 'shared/annotations/helpers'
import * as schema from 'shared/schemas'
import * as style from 'shared/annotations/styles'
import * as actions from 'shared/actions/annotations'
import AnnotationTooltip from 'shared/components/AnnotationTooltip'
class AnnotationPoint extends React.Component {
@ -29,6 +31,8 @@ class AnnotationPoint extends React.Component {
}
handleDragStop = () => {
const {annotation, updateAnnotationAsync} = this.props
updateAnnotationAsync(annotation)
this.setState({isDragging: false})
}
@ -38,7 +42,7 @@ class AnnotationPoint extends React.Component {
}
const {pageX} = e
const {annotation, dygraph, onUpdateAnnotation} = this.props
const {annotation, dygraph, updateAnnotation} = this.props
if (pageX === 0) {
return
@ -72,7 +76,7 @@ class AnnotationPoint extends React.Component {
newTime = startX
}
onUpdateAnnotation({
updateAnnotation({
...annotation,
startTime: `${newTime}`,
endTime: `${newTime}`,
@ -126,7 +130,13 @@ AnnotationPoint.propTypes = {
annotation: schema.annotation.isRequired,
mode: PropTypes.string.isRequired,
dygraph: PropTypes.shape({}).isRequired,
onUpdateAnnotation: PropTypes.func.isRequired,
updateAnnotation: PropTypes.func.isRequired,
updateAnnotationAsync: PropTypes.func.isRequired,
}
export default AnnotationPoint
const mdtp = {
updateAnnotationAsync: actions.updateAnnotationAsync,
updateAnnotation: actions.updateAnnotation,
}
export default connect(null, mdtp)(AnnotationPoint)