diff --git a/src/AnnotationCreation.js b/src/AnnotationCreation.js index daffdb0749bffbdeafc453db34e46c92b632c08e..ba428ddb855a4c5365fed643d1689966fbde63f5 100644 --- a/src/AnnotationCreation.js +++ b/src/AnnotationCreation.js @@ -1,7 +1,7 @@ import React, { Component } from 'react'; import PropTypes from 'prop-types'; import { - IconButton, Button, Paper, Grid, Popover, Divider, + Button, Paper, Grid, Popover, Divider, MenuList, MenuItem, ClickAwayListener, } from '@material-ui/core'; import { Alarm, LastPage } from '@material-ui/icons'; @@ -108,17 +108,20 @@ class AnnotationCreation extends Component { ...(props.config.annotation.defaults || {}), }; + const timeState = props.currentTime !== null + ? { tend: Math.floor(props.currentTime) + 10, tstart: Math.floor(props.currentTime) } + : { tend: null, tstart: null }; + this.state = { ...toolState, + ...timeState, annoBody: '', colorPopoverOpen: false, lineWeightPopoverOpen: false, popoverAnchorEl: null, popoverLineWeightAnchorEl: null, svg: null, - tend: Math.floor(props.currentTime) + 10, textEditorStateBustingKey: 0, - tstart: Math.floor(props.currentTime), xywh: null, ...annoState, }; @@ -242,12 +245,13 @@ class AnnotationCreation extends Component { const { annoBody, tags, xywh, svg, tstart, tend, textEditorStateBustingKey, } = this.state; + const t = (tstart && tend) ? `${tstart},${tend}` : null; canvases.forEach((canvas) => { const storageAdapter = config.annotation.adapter(canvas.id); const anno = new WebAnnotation({ - body: !annoBody.length ? `${secondsToHMS(tstart)} -> ${secondsToHMS(tend)}` : annoBody, + body: (!annoBody.length && t) ? `${secondsToHMS(tstart)} -> ${secondsToHMS(tend)}` : annoBody, canvasId: canvas.id, - fragsel: { t: `${tstart},${tend}`, xywh }, + fragsel: { t, xywh }, id: (annotation && annotation.id) || `${uuid()}`, manifestId: canvas.options.resource.id, svg, @@ -267,9 +271,9 @@ class AnnotationCreation extends Component { this.setState({ annoBody: '', svg: null, - tend: 0, + tend: null, textEditorStateBustingKey: textEditorStateBustingKey + 1, - tstart: 0, + tstart: null, xywh: null, }); } @@ -586,7 +590,7 @@ AnnotationCreation.propTypes = { ), }), }).isRequired, - currentTime: PropTypes.number, + currentTime: PropTypes.oneOfType([PropTypes.number, PropTypes.instanceOf(null)]), id: PropTypes.string.isRequired, paused: PropTypes.bool, receiveAnnotation: PropTypes.func.isRequired, @@ -599,7 +603,7 @@ AnnotationCreation.defaultProps = { annotation: null, canvases: [], closeCompanionWindow: () => {}, - currentTime: 0, + currentTime: null, paused: true, setCurrentTime: () => {}, setSeekTo: () => {}, diff --git a/src/WebAnnotation.js b/src/WebAnnotation.js index 281055edee98da07573e80af4880cd842cfbe389..78cd79f5068284f3a03e1d984080bd94d7885231 100644 --- a/src/WebAnnotation.js +++ b/src/WebAnnotation.js @@ -46,9 +46,10 @@ export default class WebAnnotation { return bodies; } - /** */ + /** Fill target object with selectors (if any), else returns target url */ target() { - if (!this.svg && !this.fragsel) { + if (!this.svg + && (!this.fragsel || !Object.values(this.fragsel).find((e) => e !== null))) { return this.canvasId; } const target = { source: this.source() }; diff --git a/src/plugins/annotationCreationCompanionWindow.js b/src/plugins/annotationCreationCompanionWindow.js index afe5bed4c5d67df92ac81225c52159f05344665d..4f8cf0303b228ccdef7e94467eb93e71e459c7a6 100644 --- a/src/plugins/annotationCreationCompanionWindow.js +++ b/src/plugins/annotationCreationCompanionWindow.js @@ -25,7 +25,7 @@ function mapStateToProps(state, { id: companionWindowId, windowId }) { const canvases = getVisibleCanvases(state, { windowId }); const annotation = getPresentAnnotationsOnSelectedCanvases(state, { windowId }) - .flatMap((annoPage) => annoPage.json.items) + .flatMap((annoPage) => annoPage.json.items || []) .find((annot) => annot.id === annotationid); return {