# All files / composer/components MediaAttachmentEditor.jsx

0% Statements 0/10
0% Branches 0/4
0% Functions 0/8
0% Lines 0/10

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
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84

     import React from 'react';
    import PropTypes from 'prop-types';
    import ImagesLoadEvents from '@bufferapp/react-images-loaded';
    import ComposerActionCreators from '../action-creators/ComposerActionCreators';
    import MediaAttachmentAvailableThumbnailButton
      from '../components/MediaAttachmentAvailableThumbnailButton';
    import Button from '../components/Button';
    import Input from '../components/Input';
    import { scrollIntoView } from '../utils/DOMUtils';
    import styles from './css/MediaAttachmentEditor.css';

    class MediaAttachmentEditor extends React.Component {
      static propTypes = {
        draft: PropTypes.object.isRequired,
        onMouseOut: PropTypes.func,
        onSubmit: PropTypes.func,
        className: PropTypes.string,
      };

      static defaultProps = {
        onMouseOut: () => {},
        onSubmit: () => {},
        className: '',
      };

      onAllThumbnailImagesLoadEvents = () => {
        if (this.selectedThumbnailEl) {
          scrollIntoView({
            el: this.selectedThumbnailEl,
            ref: this.scrollContainerEl,
            axis: 'horizontal',
            padding: 25,
          });
        }
      }

      onTitleChange = (draft, e) => {
        ComposerActionCreators.updateDraftVideoTitle(draft.id, e.target.value);
      };

      setSelectedThumbnailEl = (el) => {
        this.selectedThumbnailEl = el;
      }

      render() {
        const { draft, onMouseOut, onSubmit, className } = this.props;
        const { attachedMediaEditingPayload: video } = draft;

        const availableThumbnails = video.availableThumbnails || [video.thumbnail];

        return (
          <div className={`${styles.container} ${className}`} onMouseOut={onMouseOut}>
            <label className={styles.header} htmlFor="video-title-input">Title:</label>
            <Input
              type="text"
              value={video.name}
              onChange={this.onTitleChange.bind(this, draft)}
              id="video-title-input"
              className={styles.input}
            />
            <p className={styles.header}>Thumbnail:</p>
            <div
              className={styles.scrollContainer}
              ref={(ref) => { this.scrollContainerEl = ref; }}
            >
              <ImagesLoadEvents onAlways={this.onAllThumbnailImagesLoadEvents}>
                {availableThumbnails.map((thumbnail) => (
                  <MediaAttachmentAvailableThumbnailButton
                    video={video}
                    thumbnail={thumbnail}
                    setSelectedThumbnailEl={this.setSelectedThumbnailEl}
                    draftId={draft.id}
                    key={thumbnail}
                  />))}
              </ImagesLoadEvents>
            </div>
            <Button onClick={onSubmit} className={styles.submitButton}>Done</Button>
          </div>
        );
      }
    }

    export default MediaAttachmentEditor;