import {FormattedMessage, intlShape, defineMessages} from 'react-intl'; import PropTypes from 'prop-types'; import React from 'react'; import Box from '../box/box.jsx'; import PlayButton from '../../containers/play-button.jsx'; import styles from './library-item.css'; import classNames from 'classnames'; import bluetoothIconURL from './bluetooth.svg'; import internetConnectionIconURL from './internet-connection.svg'; import favoritedFilledUrl from './favorite/filled.svg'; import favoritedOutlineUrl from './favorite/outline.svg'; import deleteFilledUrl from './delete/filled.svg'; import downloadFilled from './download/filled.svg'; const getURLOrigin = (url) => { let urlObj; try { urlObj = new URL(url); } catch { // not a valid URL return String(url); } return urlObj.origin; }; const getMSFormatted = (ms) => { return (ms / 1000).toFixed(2); }; /* eslint-disable react/prefer-stateless-function */ class LibraryItemComponent extends React.PureComponent { render() { return this.props.featured ? (
{this.props.disabled ? (
) : null}
{(this.props.insetIconURL && !this.props.customInsetColor) ? (
) : null} {(this.props.insetIconURL && this.props.customInsetColor) ? (
) : null} {(this.props.favoritable && !this.props.deletable) ? ( ) : null} {this.props.deletable && ( )}
{this.props.name}
{this.props.description} {this.props.custom && ( <>
{this.props.extensionId.startsWith("data:") ? ( {this.props._unsandboxed ? ( ) : ( )} ) : ( )} {this.props.extensionId.startsWith("data:") ? ( ) : ( {getURLOrigin(this.props.extensionId)} )} )}
{ this.props.bluetoothRequired || this.props.internetConnectionRequired || this.props.collaborator || this.props.extDeveloper || this.props.twDeveloper || this.props.eventSubmittor || this.props.credits ? (
{this.props.bluetoothRequired || this.props.internetConnectionRequired ? (
{this.props.bluetoothRequired ? ( ) : null} {this.props.internetConnectionRequired ? ( ) : null}
) : null}
{this.props.collaborator ? (
{this.props.collaborator}
) : null} {this.props.twDeveloper ? (
Originally for TurboWarp by
{this.props.twDeveloper}
) : null} {this.props.extDeveloper ? (
Created by
{this.props.extDeveloper}
) : null} {this.props.eventSubmittor ? (
Event Submission by
{this.props.eventSubmittor}
) : null} {this.props.credits ? (
Credits
{this.props.credits}
) : null}
) : null}
) : ( {this.props.isNew && (
NEW
)} {/* Layers of wrapping is to prevent layout thrashing on animation */} {this.props.overlayURL && ( )} {this.props.styleForSound ? (
{this.props.name} {this.props.soundType}, {getMSFormatted(this.props.soundLength)}
) : ( {this.props.name} )} {this.props.showPlayButton ? ( ) : null}
); } } /* eslint-enable react/prefer-stateless-function */ LibraryItemComponent.propTypes = { intl: intlShape, bluetoothRequired: PropTypes.bool, collaborator: PropTypes.string, credits: PropTypes.string, twDeveloper: PropTypes.string, extDeveloper: PropTypes.string, eventSubmittor: PropTypes.string, description: PropTypes.oneOfType([ PropTypes.string, PropTypes.node ]), disabled: PropTypes.bool, extensionId: PropTypes.string, featured: PropTypes.bool, isNew: PropTypes.bool, hidden: PropTypes.bool, iconURL: PropTypes.string, overlayURL: PropTypes.string, insetIconURL: PropTypes.string, styleForSound: PropTypes.bool, soundType: PropTypes.string, soundLength: PropTypes.number, customInsetColor: PropTypes.string, internetConnectionRequired: PropTypes.bool, isPlaying: PropTypes.bool, name: PropTypes.oneOfType([ PropTypes.string, PropTypes.node ]), onBlur: PropTypes.func.isRequired, onClick: PropTypes.func.isRequired, onFocus: PropTypes.func.isRequired, onKeyPress: PropTypes.func.isRequired, onMouseEnter: PropTypes.func.isRequired, onMouseLeave: PropTypes.func.isRequired, onPlay: PropTypes.func.isRequired, onStop: PropTypes.func.isRequired, showPlayButton: PropTypes.bool, favoritable: PropTypes.bool, favorited: PropTypes.bool, deletable: PropTypes.bool, custom: PropTypes.bool, onFavoriteClick: PropTypes.func, onDeleteClick: PropTypes.func, _id: PropTypes.string, _unsandboxed: PropTypes.bool }; LibraryItemComponent.defaultProps = { disabled: false, showPlayButton: false }; export default LibraryItemComponent;