Skip to content
Snippets Groups Projects
Select Git revision
  • 013d029df94c6e38dbe2c2ebc6884f2379bcf31e
  • demo_ci_gitlab_pages default
  • demo_gitlab_ci
  • 5-images-in-annotations
  • 5-final-images
  • 5-chpk-images-in-annot
  • tetras-main protected
  • 5-rebase-images-in-annot
  • 5-wip-images-in-annot
  • tmp
  • 1-edit-annotations-on-videos
  • 5-old-images-in-annotations
  • old_demo_ci_gitlab_pages
  • images_annotations
  • wip
  • devsetup
  • wip-annot-video-ui
  • wip-annotations-on-videos
  • master
  • v0.4.0_react16
  • wip-debugging-annotations
21 results

AnnotationCreation.js

Blame
  • Forked from IIIF / Mirador / Mirador annotations
    485 commits behind the upstream repository.
    user avatar
    Jack Reed authored
    013d029d
    History
    AnnotationCreation.js 2.36 KiB
    import React, { Component } from 'react';
    import PropTypes from 'prop-types';
    import Button from '@material-ui/core/Button';
    import TextField from '@material-ui/core/TextField';
    import { v4 as uuid } from 'uuid';
    
    /** */
    class AnnotationCreation extends Component {
      /** */
      constructor(props) {
        super(props);
        this.state = { annoBody: '', xywh: '0,0,0,0' };
    
        this.submitForm = this.submitForm.bind(this);
        this.updateBody = this.updateBody.bind(this);
        this.updateXywh = this.updateXywh.bind(this);
      }
    
      /** */
      submitForm(e) {
        e.preventDefault();
        const { canvases, receiveAnnotation, config } = this.props;
        const { annoBody, xywh } = this.state;
    
        canvases.forEach((canvas) => {
          const localStorageAdapter = config.annotation.adapter(canvas.id);
          const anno = {
            body: {
              language: 'en',
              type: 'TextualBody',
              value: annoBody,
            },
            id: `https://example.org/iiif/book1/page/manifest/${uuid()}`,
            motivation: 'commenting',
            target: `${canvas.id}#xywh=${xywh}`,
            type: 'Annotation',
          };
          const newAnnoPage = localStorageAdapter.create(anno);
          receiveAnnotation(canvas.id, localStorageAdapter.annotationPageId, newAnnoPage);
        });
      }
    
      /** */
      updateBody(e) {
        this.setState({ annoBody: e.target.value });
      }
    
      /** */
      updateXywh(e) {
        this.setState({ xywh: e.target.value });
      }
    
      /** */
      render() {
        const { annoBody, xywh } = this.state;
    
        return (
          <div>
            <form onSubmit={this.submitForm}>
              <TextField
                value={xywh}
                onChange={this.updateXywh}
              />
              <TextField
                multiline
                rows={6}
                value={annoBody}
                onChange={this.updateBody}
              />
              <Button>
                Cancel
              </Button>
              <Button variant="contained" color="primary" type="submit">
                Save
              </Button>
            </form>
          </div>
        );
      }
    }
    
    AnnotationCreation.propTypes = {
      canvases: PropTypes.arrayOf(
        PropTypes.shape({ id: PropTypes.string, index: PropTypes.number }),
      ),
      config: PropTypes.shape({
        annotation: PropTypes.shape({
          adapter: PropTypes.func,
        }),
      }).isRequired,
      receiveAnnotation: PropTypes.func.isRequired,
    };
    
    AnnotationCreation.defaultProps = {
      canvases: [],
    };
    
    
    export default AnnotationCreation;