# All files / composer/components MediaAttachmentAvailableThumbnailButton.jsx

0% Statements 0/6
0% Branches 0/4
0% Functions 0/3
0% Lines 0/5

Press n or j to go to the next uncovered block, b, p or k for the previous block.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44

     import React from 'react';
    import PropTypes from 'prop-types';
    import ComposerActionCreators from '../action-creators/ComposerActionCreators';
    import Button from '../components/Button';
    import styles from './css/MediaAttachmentEditor.css';

    class MediaAttachmentAvailableThumbnailButton extends React.Component {
      static propTypes = {
        video: PropTypes.object.isRequired,
        thumbnail: PropTypes.string.isRequired,
        setSelectedThumbnailEl: PropTypes.func.isRequired,
        draftId: PropTypes.string.isRequired,
      };

      onSuggestedThumbnailClick = () => {
        ComposerActionCreators.updateDraftVideoThumbnail(this.props.draftId, this.props.thumbnail);
      };

      render() {
        const { video, thumbnail, setSelectedThumbnailEl } = this.props;

        const className = thumbnail === video.thumbnail ?
          `${styles.selectedThumbnailContainer} bi bi-checkmark` :
          styles.thumbnailContainer;

        return (
          <Button
            className={className}
            onClick={this.onSuggestedThumbnailClick}
            key={thumbnail}
          >
            <img
              src={thumbnail}
              className={styles.thumbnail}
              alt="Suggested thumbnail for video"
              ref={(ref) => { if (thumbnail === video.thumbnail) setSelectedThumbnailEl(ref); }}
            />
          </Button>
        );
      }
    }

    export default MediaAttachmentAvailableThumbnailButton;