Skip to content
Snippets Groups Projects
Select Git revision
  • 22636838d95497b5bb84d9ba511fa561ae1d59fb
  • master default protected
  • 10-unl-ru
3 results

base.html

Blame
  • CanvasAnnotations.js 1.93 KiB
    import { compose } from 'redux';
    import { connect } from 'react-redux';
    import { withTranslation } from 'react-i18next';
    import { withPlugins } from '../extend/withPlugins';
    import * as actions from '../state/actions';
    import {
      getAnnotationResourcesByMotivationForCanvas,
      getCanvasLabel,
      getSelectedAnnotationId,
      getConfig,
      getWindow,
    } from '../state/selectors';
    import { CanvasAnnotations } from '../components/CanvasAnnotations';
    import { withRef } from '../extend/withRef';
    
    /**
     * @param {Array} resources
     * @return {Array} [{ id: 'abc123', content: 'Annotation Content' }, ...]
     */
    function getIdAndContentOfResources(resources) {
      return resources.map((resource, i) => ({
        content: resource.chars,
        id: resource.id,
        tags: resource.tags,
        targetId: resource.targetId,
      }));
    }
    
    /** For connect */
    const mapStateToProps = (state, { canvasId, windowId }) => ({
      annotations: getIdAndContentOfResources(
        getAnnotationResourcesByMotivationForCanvas(state, { canvasId, windowId }),
      ),
      autoScroll: getWindow(state, { windowId }).autoScrollAnnotationList,
      htmlSanitizationRuleSet: getConfig(state).annotations.htmlSanitizationRuleSet,
      label: getCanvasLabel(state, {
        canvasId,
        windowId,
      }),
      selectedAnnotationId: getSelectedAnnotationId(state, { windowId }),
    });
    
    /**
     * mapDispatchToProps - to hook up connect
     * @memberof WindowSideBarAnnotationsPanel
     * @private
     */
    const mapDispatchToProps = {
      deselectAnnotation: actions.deselectAnnotation,
      hoverAnnotation: actions.hoverAnnotation,
      selectAnnotation: actions.selectAnnotation,
    };
    
    // const enhance = compose(
    //   withRef(),
    //   withTranslation(),
    //   connect(mapStateToProps, mapDispatchToProps, null, { forwardRef: true }),
    //   withPlugins('CanvasAnnotations'),
    // );
    
    const enhance = compose(
      withRef(),
      withTranslation(),
      connect(mapStateToProps, mapDispatchToProps),
      withPlugins('CanvasAnnotations'),
    );
    
    export default enhance(CanvasAnnotations);