import React from 'react'; import { connect } from 'react-redux'; import { bindActionCreators } from 'redux'; import { Route, Switch } from 'react-router-dom'; import ErrorMessage from '../components/ErrorMessage'; import Link from '../components/Link'; import LazyLoadListener from '../components/LazyLoadListener'; import TrackList from '../components/TrackList'; import AlbumGrid from '../components/AlbumGrid'; import Thumbnail from '../components/Thumbnail'; import Parallax from '../components/Parallax'; import ArtistGrid from '../components/ArtistGrid'; import RelatedArtists from '../components/RelatedArtists'; import FollowButton from '../components/Fields/FollowButton'; import ContextMenuTrigger from '../components/ContextMenuTrigger'; import DropdownField from '../components/Fields/DropdownField'; import Icon from '../components/Icon'; import Loader from '../components/Loader'; import * as coreActions from '../services/core/actions'; import * as uiActions from '../services/ui/actions'; import * as mopidyActions from '../services/mopidy/actions'; import * as pusherActions from '../services/pusher/actions'; import * as lastfmActions from '../services/lastfm/actions'; import * as spotifyActions from '../services/spotify/actions'; import { uriSource, getFromUri, isLoading, sourceIcon, titleCase, } from '../util/helpers'; import { collate } from '../util/format'; import { sortItems, applyFilter } from '../util/arrays'; import { i18n, I18n } from '../locale'; import Button from '../components/Button'; import { trackEvent } from '../components/Trackable'; class Artist extends React.Component { componentDidMount() { this.setWindowTitle(); this.props.coreActions.loadArtist(this.props.uri); } componentDidUpdate = ({ uri: prevUri, artist: prevArtist, }) => { const { uri, artist, coreActions: { loadArtist, }, } = this.props; if (uri !== prevUri) { loadArtist(uri); } if (!prevArtist && artist) this.setWindowTitle(artist); if (prevUri !== uri && artist) this.setWindowTitle(artist); } onResetFilters = () => { this.onChangeFilter(null); this.onChangeSort(null); trackEvent({ category: 'Artist', action: 'FilterAlbums', label: 'Reset' }); } onChangeFilter = (value) => { const { uiActions: { set, hideContextMenu } } = this.props; set({ artist_albums_filter: value }); hideContextMenu(); trackEvent({ category: 'Artist', action: 'FilterAlbums', label: value }); } onChangeSort = (value) => { const { sort, sort_reverse, uiActions: { set, hideContextMenu, }, } = this.props; let reverse = false; if (value !== null && sort === value) { reverse = !sort_reverse; } set({ artist_albums_sort_reverse: reverse, artist_albums_sort: value, }); hideContextMenu(); trackEvent({ category: 'Artist', action: 'SortAlbums', label: `${value} ${reverse ? 'DESC' : 'ASC'}` }); } onPlay = () => { const { artist: { uri, tracks_uris, albums_uris, }, mopidyActions: { playURIs }, } = this.props; playURIs(tracks_uris || albums_uris, uri); } setWindowTitle = (artist = this.props.artist) => { const { uiActions: { setWindowTitle } } = this.props; if (artist) { setWindowTitle(i18n('artist.title_window', { name: artist.name })); } else { setWindowTitle(i18n('artist.title')); } } handleContextMenu = (e) => { const { artist, uri, uiActions: { showContextMenu }, } = this.props; showContextMenu({ e, context: 'artist', items: [artist], uris: [uri], }); } inLibrary = () => { const { uri } = this.props; const libraryName = `${uriSource(uri)}_library_artists`; const { [libraryName]: { items_uris } } = this.props; return items_uris.indexOf(uri) > -1; } renderOverview = () => { const { uri, uiActions, artist, items, sort, sort_reverse, filter, } = this.props; let { tracks, related_artists, albums, } = collate(artist, { albums: items }); if (sort && albums) { albums = sortItems(albums, sort, sort_reverse); } if (filter && albums) { albums = applyFilter('type', filter, albums); } const sort_options = [ { value: null, label: i18n('artist.albums.sort.default'), }, { value: 'name', label: i18n('artist.albums.sort.name'), }, { value: 'release_date', label: i18n('artist.albums.sort.release_date'), }, { value: 'tracks_uris.length', label: i18n('artist.albums.sort.track_count'), }, ]; const filter_options = [ { value: null, label: i18n('artist.albums.filter.all'), }, { value: 'album', label: i18n('artist.albums.filter.albums'), }, { value: 'single', label: i18n('artist.albums.filter.singles'), }, { value: 'compilation', label: i18n('artist.albums.filter.compilations'), }, ]; return (