Skip to content
Snippets Groups Projects
Select Git revision
  • a2ee3f605d68a9b6224623f59e2482d0542f4f1a
  • 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

AnnotationDownloadDialog.js

Blame
  • Forked from IIIF / Mirador / Mirador annotations
    Source project has a limited visibility.
    AnnotationDownloadDialog.js 3.70 KiB
    import React, { Component } from 'react';
    import Dialog from '@material-ui/core/Dialog';
    import DialogContent from '@material-ui/core/DialogContent';
    import DialogTitle from '@material-ui/core/DialogTitle';
    import GetAppIcon from '@material-ui/icons/GetApp';
    import List from '@material-ui/core/List';
    import ListItem from '@material-ui/core/ListItem';
    import ListItemIcon from '@material-ui/core/ListItemIcon';
    import ListItemText from '@material-ui/core/ListItemText';
    import Typography from '@material-ui/core/Typography';
    import PropTypes, { bool } from 'prop-types';
    
    /** */
    class AnnotationDownloadDialog extends Component {
      /** */
      constructor(props) {
        super(props);
        this.state = {
          downloadLinks: [],
        };
        this.closeDialog = this.closeDialog.bind(this);
      }
    
      /** */
      componentDidUpdate(prevProps) {
        const { canvases, config, open } = this.props;
        const { open: prevOpen } = prevProps || {};
        if (prevOpen !== open && open) {
          /** */
          const reducer = async (acc, canvas) => {
            const store = config.annotation.adapter(canvas.id);
            const resolvedAcc = await acc;
            const content = await store.all();
            if (content) {
              // eslint-disable-next-line no-underscore-dangle
              const label = canvas.__jsonld.label || canvas.id;
              const data = new Blob([JSON.stringify(content)], { type: 'application/json' });
              const url = window.URL.createObjectURL(data);
              return [...resolvedAcc, {
                canvasId: canvas.id,
                id: content.id || content['@id'],
                label,
                url,
              }];
            }
            return resolvedAcc;
          };
          if (canvases && canvases.length > 0) {
            canvases.reduce(reducer, []).then((downloadLinks) => {
              this.setState({ downloadLinks });
            });
          }
        }
      }
    
      /** */
      closeDialog() {
        const { handleClose } = this.props;
        this.setState({ downloadLinks: [] });
        handleClose();
      }
    
      /** */
      render() {
        const { handleClose, open } = this.props;
        const { downloadLinks } = this.state;
        return (
          <Dialog
            aria-labelledby="annotation-download-dialog-title"
            id="annotation-download-dialog"