2019-09-05 15:36:11 +12:00
|
|
|
import React from 'react';
|
|
|
|
|
import { connect } from 'react-redux';
|
|
|
|
|
import { bindActionCreators } from 'redux';
|
2019-08-21 17:02:38 +12:00
|
|
|
|
2019-09-05 15:36:11 +12:00
|
|
|
import ErrorMessage from '../components/ErrorMessage';
|
|
|
|
|
import TrackList from '../components/TrackList';
|
|
|
|
|
import Thumbnail from '../components/Thumbnail';
|
2019-10-05 09:10:34 +13:00
|
|
|
import LinksSentence from '../components/LinksSentence';
|
2019-09-10 06:59:44 +12:00
|
|
|
import Loader from '../components/Loader';
|
2019-09-05 15:36:11 +12:00
|
|
|
import FollowButton from '../components/Fields/FollowButton';
|
2020-07-07 20:52:09 +12:00
|
|
|
import { nice_number } from '../components/NiceNumber';
|
|
|
|
|
import { Dater } from '../components/Dater';
|
2019-09-05 15:36:11 +12:00
|
|
|
import LazyLoadListener from '../components/LazyLoadListener';
|
|
|
|
|
import ContextMenuTrigger from '../components/ContextMenuTrigger';
|
|
|
|
|
import Icon from '../components/Icon';
|
2020-07-07 20:52:09 +12:00
|
|
|
import { i18n, I18n } from '../locale';
|
2019-09-05 15:36:11 +12:00
|
|
|
import * as coreActions from '../services/core/actions';
|
|
|
|
|
import * as uiActions from '../services/ui/actions';
|
|
|
|
|
import * as mopidyActions from '../services/mopidy/actions';
|
|
|
|
|
import * as spotifyActions from '../services/spotify/actions';
|
|
|
|
|
import * as lastfmActions from '../services/lastfm/actions';
|
2020-03-03 16:39:37 +13:00
|
|
|
import {
|
|
|
|
|
uriSource,
|
|
|
|
|
getFromUri,
|
|
|
|
|
isLoading,
|
|
|
|
|
sourceIcon,
|
|
|
|
|
} from '../util/helpers';
|
|
|
|
|
import { collate } from '../util/format';
|
2020-08-15 21:05:00 +12:00
|
|
|
import Button from '../components/Button';
|
2019-08-21 17:02:38 +12:00
|
|
|
|
|
|
|
|
export class Album extends React.Component {
|
2020-03-11 20:40:20 +13:00
|
|
|
componentDidMount = () => {
|
|
|
|
|
const {
|
|
|
|
|
uri,
|
|
|
|
|
album,
|
|
|
|
|
coreActions: {
|
|
|
|
|
loadAlbum,
|
|
|
|
|
},
|
|
|
|
|
lastfmActions: {
|
|
|
|
|
getAlbum,
|
|
|
|
|
},
|
|
|
|
|
} = this.props;
|
|
|
|
|
|
2019-08-21 17:02:38 +12:00
|
|
|
this.setWindowTitle();
|
2020-03-11 20:40:20 +13:00
|
|
|
loadAlbum(uri);
|
2019-08-21 17:02:38 +12:00
|
|
|
|
2020-03-11 20:40:20 +13:00
|
|
|
if (album) {
|
|
|
|
|
if (album.artists && album.wiki === undefined) {
|
|
|
|
|
getAlbum(album.uri, album.artists[0].name, album.name);
|
2019-08-21 17:02:38 +12:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-11 20:40:20 +13:00
|
|
|
handleContextMenu = (e) => {
|
|
|
|
|
const {
|
|
|
|
|
uri,
|
|
|
|
|
uiActions: {
|
|
|
|
|
showContextMenu,
|
|
|
|
|
},
|
|
|
|
|
} = this.props;
|
|
|
|
|
|
2019-08-21 17:02:38 +12:00
|
|
|
e.preventDefault();
|
2020-03-11 20:40:20 +13:00
|
|
|
const data = { uris: [uri] };
|
|
|
|
|
showContextMenu(e, data, 'album', 'click');
|
2019-08-21 17:02:38 +12:00
|
|
|
}
|
|
|
|
|
|
2020-03-11 20:40:20 +13:00
|
|
|
componentDidUpdate = ({
|
|
|
|
|
uri: prevUri,
|
|
|
|
|
album: prevAlbum,
|
|
|
|
|
}) => {
|
|
|
|
|
const {
|
|
|
|
|
uri,
|
|
|
|
|
album,
|
|
|
|
|
coreActions: {
|
|
|
|
|
loadAlbum,
|
|
|
|
|
},
|
|
|
|
|
lastfmActions: {
|
|
|
|
|
getAlbum,
|
|
|
|
|
},
|
|
|
|
|
} = this.props;
|
2019-08-21 17:02:38 +12:00
|
|
|
|
2020-03-11 20:40:20 +13:00
|
|
|
if (uri !== prevUri) {
|
|
|
|
|
loadAlbum(uri);
|
2019-08-21 17:02:38 +12:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// We have just received our full album or our album artists
|
2020-03-11 20:40:20 +13:00
|
|
|
if ((!prevAlbum && album) || (!prevAlbum.artists && album.artists)) {
|
2020-08-18 20:18:29 +12:00
|
|
|
if (album.artists && album.wiki === undefined) {
|
2020-03-11 20:40:20 +13:00
|
|
|
getAlbum(album.uri, album.artists[0].name, album.name);
|
2019-08-21 17:02:38 +12:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-11 20:40:20 +13:00
|
|
|
if (!prevAlbum && album) this.setWindowTitle(album);
|
2019-08-21 17:02:38 +12:00
|
|
|
}
|
|
|
|
|
|
2020-03-11 20:40:20 +13:00
|
|
|
setWindowTitle = (album = this.props.album) => {
|
2020-07-06 20:22:39 +12:00
|
|
|
const { uiActions: { setWindowTitle }, artists } = this.props;
|
2020-04-16 16:24:47 +12:00
|
|
|
|
2019-08-21 17:02:38 +12:00
|
|
|
if (album) {
|
2020-07-06 20:22:39 +12:00
|
|
|
let artistNames = [];
|
2020-03-11 20:40:20 +13:00
|
|
|
if (album.artists_uris && artists) {
|
2019-09-05 15:36:11 +12:00
|
|
|
for (let i = 0; i < album.artists_uris.length; i++) {
|
|
|
|
|
const uri = album.artists_uris[i];
|
2020-03-11 20:40:20 +13:00
|
|
|
if (artists.hasOwnProperty(uri)) {
|
2020-07-06 20:22:39 +12:00
|
|
|
artistNames.push(artists[uri].name);
|
2019-08-21 17:02:38 +12:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-07-07 20:52:09 +12:00
|
|
|
setWindowTitle(i18n('album.title_window', { name: album.name, artist: artistNames.join() }));
|
2019-08-21 17:02:38 +12:00
|
|
|
} else {
|
2020-07-07 20:52:09 +12:00
|
|
|
setWindowTitle(i18n('album.title'));
|
2019-08-21 17:02:38 +12:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-11 20:40:20 +13:00
|
|
|
handleContextMenu = (e) => {
|
|
|
|
|
const { album, uri, uiActions: { showContextMenu } } = this.props;
|
|
|
|
|
|
|
|
|
|
showContextMenu({
|
2019-09-05 15:36:11 +12:00
|
|
|
e,
|
|
|
|
|
context: 'album',
|
2020-03-11 20:40:20 +13:00
|
|
|
items: [album],
|
|
|
|
|
uris: [uri],
|
|
|
|
|
});
|
2019-08-21 17:02:38 +12:00
|
|
|
}
|
|
|
|
|
|
2020-03-11 20:40:20 +13:00
|
|
|
loadMore = () => {
|
|
|
|
|
const {
|
|
|
|
|
spotifyActions: {
|
|
|
|
|
getMore,
|
|
|
|
|
},
|
|
|
|
|
album: {
|
|
|
|
|
uri,
|
|
|
|
|
name,
|
|
|
|
|
tracks_more,
|
|
|
|
|
} = {},
|
|
|
|
|
} = this.props;
|
|
|
|
|
|
|
|
|
|
getMore(
|
|
|
|
|
tracks_more, {
|
2020-02-14 10:55:10 +13:00
|
|
|
parent_type: 'album',
|
2020-03-11 20:40:20 +13:00
|
|
|
parent_key: uri,
|
2020-02-14 10:55:10 +13:00
|
|
|
records_type: 'track',
|
|
|
|
|
},
|
|
|
|
|
null,
|
|
|
|
|
{
|
|
|
|
|
album: {
|
2020-03-11 20:40:20 +13:00
|
|
|
uri,
|
|
|
|
|
name,
|
2020-02-14 10:55:10 +13:00
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
);
|
2019-08-21 17:02:38 +12:00
|
|
|
}
|
|
|
|
|
|
2020-03-11 20:40:20 +13:00
|
|
|
play = () => {
|
2020-04-16 16:24:47 +12:00
|
|
|
const { uri, mopidyActions: { playURIs } } = this.props;
|
2020-03-11 20:40:20 +13:00
|
|
|
playURIs([uri], uri);
|
2019-08-21 17:02:38 +12:00
|
|
|
}
|
|
|
|
|
|
2020-03-11 20:40:20 +13:00
|
|
|
inLibrary = () => {
|
|
|
|
|
const { uri } = this.props;
|
|
|
|
|
const library = `${uriSource(uri)}_library_albums`;
|
|
|
|
|
return (this.props[library] && this.props[library].indexOf(this.props.uri) > -1);
|
2019-08-21 17:02:38 +12:00
|
|
|
}
|
|
|
|
|
|
2020-03-11 20:40:20 +13:00
|
|
|
render = () => {
|
|
|
|
|
const {
|
|
|
|
|
uri,
|
2020-09-02 08:12:18 +12:00
|
|
|
album,
|
2020-03-11 20:40:20 +13:00
|
|
|
load_queue,
|
2020-07-07 20:52:09 +12:00
|
|
|
slim_mode,
|
2020-03-11 20:40:20 +13:00
|
|
|
} = this.props;
|
|
|
|
|
|
2020-09-02 08:12:18 +12:00
|
|
|
if (!album) {
|
2019-08-21 17:02:38 +12:00
|
|
|
if (
|
2020-03-11 20:40:20 +13:00
|
|
|
isLoading(load_queue, [
|
|
|
|
|
`spotify_albums/${getFromUri('albumid', uri)}`,
|
2019-08-21 17:02:38 +12:00
|
|
|
])
|
|
|
|
|
) {
|
2019-09-10 06:59:44 +12:00
|
|
|
return <Loader body loading />;
|
2019-08-21 17:02:38 +12:00
|
|
|
}
|
2019-09-05 15:36:11 +12:00
|
|
|
return (
|
|
|
|
|
<ErrorMessage type="not-found" title="Not found">
|
|
|
|
|
<p>
|
2020-07-07 20:52:09 +12:00
|
|
|
{i18n('errors.uri_not_found', { uri: encodeURIComponent(uri) })}
|
2019-09-05 15:36:11 +12:00
|
|
|
</p>
|
|
|
|
|
</ErrorMessage>
|
2019-09-10 06:59:44 +12:00
|
|
|
);
|
2019-08-21 17:02:38 +12:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div className="view album-view content-wrapper preserve-3d">
|
|
|
|
|
<div className="thumbnail-wrapper">
|
2020-04-17 21:44:49 +12:00
|
|
|
<Thumbnail size="large" glow canZoom images={album.images} type="album" />
|
2019-08-21 17:02:38 +12:00
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div className="title">
|
|
|
|
|
<h1>{album.name}</h1>
|
|
|
|
|
|
|
|
|
|
<ul className="details">
|
2020-07-07 20:52:09 +12:00
|
|
|
{!slim_mode ? (
|
2019-08-21 17:02:38 +12:00
|
|
|
<li className="source">
|
2020-03-03 16:39:37 +13:00
|
|
|
<Icon type="fontawesome" name={sourceIcon(album.uri)} />
|
2019-08-21 17:02:38 +12:00
|
|
|
</li>
|
|
|
|
|
) : null}
|
|
|
|
|
{album.artists && album.artists.length > 0 ? (
|
|
|
|
|
<li>
|
2019-10-05 09:10:34 +13:00
|
|
|
<LinksSentence items={album.artists} />
|
2019-08-21 17:02:38 +12:00
|
|
|
</li>
|
|
|
|
|
) : null}
|
|
|
|
|
{album.release_date ? (
|
|
|
|
|
<li>
|
|
|
|
|
<Dater type="date" data={album.release_date} />
|
|
|
|
|
</li>
|
|
|
|
|
) : null}
|
2019-09-10 06:59:44 +12:00
|
|
|
{album.tracks ? (
|
|
|
|
|
<li>
|
2020-07-07 20:52:09 +12:00
|
|
|
{i18n(
|
2020-07-06 20:22:39 +12:00
|
|
|
'specs.tracks',
|
|
|
|
|
{ count: album.tracks_total || album.tracks.length },
|
|
|
|
|
)}
|
2019-09-10 06:59:44 +12:00
|
|
|
</li>
|
2019-09-05 15:36:11 +12:00
|
|
|
) : null}
|
2020-07-07 20:52:09 +12:00
|
|
|
{!slim_mode && album.tracks ? (
|
2019-08-21 17:02:38 +12:00
|
|
|
<li>
|
|
|
|
|
<Dater type="total-time" data={album.tracks} />
|
|
|
|
|
</li>
|
|
|
|
|
) : null}
|
2020-07-07 20:52:09 +12:00
|
|
|
{!slim_mode && album.play_count ? (
|
2019-08-21 17:02:38 +12:00
|
|
|
<li>
|
2020-07-07 20:52:09 +12:00
|
|
|
{i18n(
|
2020-07-06 20:22:39 +12:00
|
|
|
'specs.plays',
|
|
|
|
|
{ count: nice_number(album.play_count) },
|
|
|
|
|
)}
|
2019-08-21 17:02:38 +12:00
|
|
|
</li>
|
|
|
|
|
) : null}
|
2020-07-07 20:52:09 +12:00
|
|
|
{!slim_mode && album.listeners ? (
|
2019-08-21 17:02:38 +12:00
|
|
|
<li>
|
2020-07-07 20:52:09 +12:00
|
|
|
{i18n(
|
2020-07-06 20:22:39 +12:00
|
|
|
'specs.plays',
|
|
|
|
|
{ count: nice_number(album.listeners) },
|
|
|
|
|
)}
|
2019-08-21 17:02:38 +12:00
|
|
|
</li>
|
|
|
|
|
) : null}
|
|
|
|
|
</ul>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div className="actions">
|
2020-08-16 20:00:10 +12:00
|
|
|
<Button
|
|
|
|
|
type="primary"
|
|
|
|
|
onClick={this.play}
|
|
|
|
|
tracking={{ category: 'Album', action: 'Play' }}
|
|
|
|
|
>
|
2020-07-07 20:52:09 +12:00
|
|
|
<I18n path="actions.play" />
|
2020-08-15 21:05:00 +12:00
|
|
|
</Button>
|
2020-07-07 20:52:09 +12:00
|
|
|
{uriSource(uri) === 'spotify' && (
|
2019-08-21 17:02:38 +12:00
|
|
|
<FollowButton
|
2020-07-07 20:52:09 +12:00
|
|
|
uri={uri}
|
2019-08-21 17:02:38 +12:00
|
|
|
is_following={this.inLibrary()}
|
|
|
|
|
/>
|
2020-07-07 20:52:09 +12:00
|
|
|
)}
|
|
|
|
|
<ContextMenuTrigger onTrigger={this.handleContextMenu} />
|
2019-08-21 17:02:38 +12:00
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<section className="list-wrapper">
|
|
|
|
|
<TrackList
|
|
|
|
|
className="album-track-list"
|
|
|
|
|
tracks={album.tracks}
|
|
|
|
|
uri={album.uri}
|
|
|
|
|
/>
|
|
|
|
|
</section>
|
|
|
|
|
|
|
|
|
|
{album.wiki ? (
|
|
|
|
|
<section className="wiki">
|
2020-07-07 20:52:09 +12:00
|
|
|
<h4 className="wiki__title">{i18n('album.wiki.title')}</h4>
|
2019-08-21 17:02:38 +12:00
|
|
|
<div className="wiki__text">
|
|
|
|
|
<p>{album.wiki}</p>
|
|
|
|
|
<br />
|
|
|
|
|
<div className="mid_grey-text">
|
2020-07-07 20:52:09 +12:00
|
|
|
<I18n path="album.wiki.published" params={{ date: album.wiki_publish_date }} />
|
2019-08-21 17:02:38 +12:00
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</section>
|
|
|
|
|
) : null}
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
2016-10-03 14:44:27 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const mapStateToProps = (state, ownProps) => {
|
2019-09-05 15:36:11 +12:00
|
|
|
const uri = decodeURIComponent(ownProps.match.params.uri);
|
2019-08-21 17:02:38 +12:00
|
|
|
return {
|
2019-09-05 15:36:11 +12:00
|
|
|
uri,
|
2019-08-21 17:02:38 +12:00
|
|
|
slim_mode: state.ui.slim_mode,
|
|
|
|
|
theme: state.ui.theme,
|
|
|
|
|
load_queue: state.ui.load_queue,
|
|
|
|
|
tracks: state.core.tracks,
|
|
|
|
|
artists: state.core.artists,
|
|
|
|
|
album:
|
|
|
|
|
state.core.albums && state.core.albums[uri] !== undefined
|
|
|
|
|
? state.core.albums[uri]
|
|
|
|
|
: false,
|
|
|
|
|
albums: state.core.albums,
|
|
|
|
|
spotify_library_albums: state.spotify.library_albums,
|
|
|
|
|
local_library_albums: state.mopidy.library_albums,
|
|
|
|
|
spotify_authorized: state.spotify.authorization,
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
2019-09-05 15:36:11 +12:00
|
|
|
const mapDispatchToProps = (dispatch) => ({
|
|
|
|
|
coreActions: bindActionCreators(coreActions, dispatch),
|
|
|
|
|
uiActions: bindActionCreators(uiActions, dispatch),
|
|
|
|
|
mopidyActions: bindActionCreators(mopidyActions, dispatch),
|
|
|
|
|
spotifyActions: bindActionCreators(spotifyActions, dispatch),
|
|
|
|
|
lastfmActions: bindActionCreators(lastfmActions, dispatch),
|
|
|
|
|
});
|
2019-08-21 17:02:38 +12:00
|
|
|
|
|
|
|
|
export default connect(
|
|
|
|
|
mapStateToProps,
|
2019-09-05 15:36:11 +12:00
|
|
|
mapDispatchToProps,
|
2019-08-21 17:02:38 +12:00
|
|
|
)(Album);
|