import React from 'react'; import PropTypes from 'prop-types'; import { LinksContext } from '../../utils/contexts/'; import { PlaylistViewStore } from '../../utils/stores/'; import { PositiveIntegerOrZero } from '../../utils/helpers/'; import { PageActions, PlaylistViewActions } from '../../utils/actions/'; import { CircleIconButton } from '../_shared/'; import { PlaylistPlaybackMedia } from './PlaylistPlaybackMedia'; import './PlaylistView.scss'; export default class PlaylistView extends React.PureComponent { constructor(props) { super(props); this.state = { expanded: true, loopRepeat: PlaylistViewStore.get('enabled-loop'), shuffle: PlaylistViewStore.get('enabled-shuffle'), savedPlaylist: PlaylistViewStore.get('saved-playlist-loop'), title: props.playlistData.title, link: props.playlistData.url, authorName: props.playlistData.user, authorLink: LinksContext._currentValue.home + '/user/' + props.playlistData.user, activeItem: props.activeItem, totalMedia: props.playlistData.media_count, items: props.playlistData.playlist_media, }; this.onHeaderClick = this.onHeaderClick.bind(this); this.onLoopClick = this.onLoopClick.bind(this); this.onShuffleClick = this.onShuffleClick.bind(this); this.onSaveClick = this.onSaveClick.bind(this); this.onLoopRepeatUpdate = this.onLoopRepeatUpdate.bind(this); this.onShuffleUpdate = this.onShuffleUpdate.bind(this); this.onPlaylistSaveUpdate = this.onPlaylistSaveUpdate.bind(this); PlaylistViewStore.on('loop-repeat-updated', this.onLoopRepeatUpdate); PlaylistViewStore.on('shuffle-updated', this.onShuffleUpdate); PlaylistViewStore.on('saved-updated', this.onPlaylistSaveUpdate); } onHeaderClick(ev) { this.setState({ expanded: !this.state.expanded }); } onLoopClick() { PlaylistViewActions.toggleLoop(); } onShuffleClick() { PlaylistViewActions.toggleShuffle(); } onSaveClick() { PlaylistViewActions.toggleSave(); } onShuffleUpdate() { this.setState( { shuffle: PlaylistViewStore.get('enabled-shuffle'), }, () => { if (this.state.shuffle) { PageActions.addNotification('Playlist shuffle is on', 'shuffle-on'); } else { PageActions.addNotification('Playlist shuffle is off', 'shuffle-off'); } } ); } onLoopRepeatUpdate() { this.setState( { loopRepeat: PlaylistViewStore.get('enabled-loop'), }, () => { if (this.state.loopRepeat) { PageActions.addNotification('Playlist loop is on', 'loop-on'); } else { PageActions.addNotification('Playlist loop is off', 'loop-off'); } } ); } onPlaylistSaveUpdate() { this.setState( { savedPlaylist: PlaylistViewStore.get('saved-playlist'), }, () => { if (this.state.savedPlaylist) { PageActions.addNotification('Added to playlists library', 'added-to-playlists-lib'); } else { PageActions.addNotification('Removed from playlists library', 'removed-from-playlists-lib'); } } ); } render() { return (