# All files / composer/components PinterestSelectedBoards.jsx

0% Statements 0/21
0% Branches 0/12
0% Functions 0/6
0% Lines 0/19

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

     import React from 'react';
    import PropTypes from 'prop-types';
    import styles from './css/PinterestSelectedBoards.css';

    class PinterestSelectedBoards extends React.Component {
      static propTypes = {
        profiles: PropTypes.array,
      };

      getSelectedBoard = () => {
        const selectedPinterestProfiles = this.props.profiles.filter((profile) => (
          profile.isSelected &&
          profile.service.name === 'pinterest'
        ));

        return selectedPinterestProfiles.reduce((reducedSelectedSubprofiles, profile) => {
          const doesProfileHaveSelectedSubprofile = profile.selectedSubprofileId !== null;
          if (!doesProfileHaveSelectedSubprofile) return reducedSelectedSubprofiles;

          const getSubProfile = (subprofile) => subprofile.id === profile.selectedSubprofileId;
          const selectedSubprofileForProfile = profile.subprofiles.find(getSubProfile);

          return reducedSelectedSubprofiles.concat(selectedSubprofileForProfile);
        }, []);
      };

      render() {
        const selectedBoards = this.getSelectedBoard();
        const firstBoard = selectedBoards[0];

        const hasMultipleBoardsSelected = selectedBoards.length > 1;

        const getAvatar = (avatar) => {
          const defaultAvatarToOverride = 'https://static.bufferapp.com/images/app/pin_2x.png';
          const defaultAvatar = 'https://static.bufferapp.com/images/app/img_pin@2x.png';
          if (avatar === defaultAvatarToOverride) {
            return defaultAvatar;
          }
          return avatar;
        };
        const firstBoardAvatar = firstBoard ? getAvatar(firstBoard.avatar) : null;

        return (
          <div className={styles.selectedBoardsContainer}>
            <div className={styles.selectedBoardsLabel}>Pinning to:</div>
            <img
              className={styles.selectedBoardThumbnail}
              src={firstBoardAvatar}
              role="presentation"
            />
            {firstBoard && <div className={styles.selectedBoardName}>{firstBoard.name}</div>}

            {hasMultipleBoardsSelected &&
            <div className={styles.additionalBoard}>+ {selectedBoards.length - 1} more</div>}
          </div>
        );
      }
    }

    export default PinterestSelectedBoards;