2016-10-20 21:38:01 +13:00
|
|
|
|
2019-02-10 19:51:33 +13:00
|
|
|
import React from 'react';
|
2019-01-14 16:50:21 +13:00
|
|
|
import { connect } from 'react-redux';
|
|
|
|
|
import { bindActionCreators } from 'redux';
|
|
|
|
|
import ReactGA from 'react-ga';
|
2019-01-22 21:46:56 +13:00
|
|
|
import ErrorMessage from '../components/ErrorMessage';
|
2018-10-28 21:14:54 +13:00
|
|
|
import Link from '../components/Link';
|
2019-09-05 15:36:11 +12:00
|
|
|
import TrackList from '../components/TrackList';
|
|
|
|
|
import Thumbnail from '../components/Thumbnail';
|
|
|
|
|
import Parallax from '../components/Parallax';
|
2020-07-08 20:15:14 +12:00
|
|
|
import NiceNumber, { nice_number } from '../components/NiceNumber';
|
|
|
|
|
import { Dater, dater } from '../components/Dater';
|
2019-09-05 15:36:11 +12:00
|
|
|
import LazyLoadListener from '../components/LazyLoadListener';
|
|
|
|
|
import FollowButton from '../components/Fields/FollowButton';
|
2019-09-10 06:59:44 +12:00
|
|
|
import Loader from '../components/Loader';
|
2019-09-05 15:36:11 +12:00
|
|
|
import ContextMenuTrigger from '../components/ContextMenuTrigger';
|
|
|
|
|
import URILink from '../components/URILink';
|
|
|
|
|
import Icon from '../components/Icon';
|
|
|
|
|
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';
|
2020-03-03 16:39:37 +13:00
|
|
|
import {
|
|
|
|
|
uriSource,
|
|
|
|
|
getFromUri,
|
|
|
|
|
isLoading,
|
|
|
|
|
sourceIcon,
|
2020-05-12 20:32:48 +12:00
|
|
|
decodeMopidyUri,
|
2020-03-03 16:39:37 +13:00
|
|
|
} from '../util/helpers';
|
|
|
|
|
import { collate } from '../util/format';
|
2020-07-08 20:15:14 +12:00
|
|
|
import { i18n, I18n } from '../locale';
|
2019-09-05 15:36:11 +12:00
|
|
|
|
2019-09-10 06:59:44 +12:00
|
|
|
class Playlist extends React.Component {
|
2019-09-05 15:36:11 +12:00
|
|
|
constructor(props) {
|
|
|
|
|
super(props);
|
|
|
|
|
|
2019-11-15 13:50:39 +13:00
|
|
|
let { uri } = props;
|
2019-09-05 15:36:11 +12:00
|
|
|
|
|
|
|
|
// Spotify upgraded their playlists URI to remove user component (Sept 2018)
|
|
|
|
|
// We accept the old format, and redirect to the new one
|
|
|
|
|
if (uri.includes('spotify:user:')) {
|
|
|
|
|
uri = uri.replace(/spotify:user:([^:]*?):/i, 'spotify:');
|
2019-11-15 13:50:39 +13:00
|
|
|
props.history.push(`/playlist/${encodeURIComponent(uri)}`);
|
2019-09-05 15:36:11 +12:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
componentDidMount() {
|
2020-05-25 20:50:25 +12:00
|
|
|
const { coreActions: { loadPlaylist }, uri } = this.props;
|
2019-09-05 15:36:11 +12:00
|
|
|
this.setWindowTitle();
|
2020-05-25 20:50:25 +12:00
|
|
|
loadPlaylist(uri);
|
2019-09-05 15:36:11 +12:00
|
|
|
}
|
|
|
|
|
|
2020-03-11 20:40:20 +13:00
|
|
|
componentDidUpdate = ({
|
|
|
|
|
uri: prevUri,
|
|
|
|
|
playlist: prevPlaylist,
|
|
|
|
|
mopidy_connected: prev_mopidy_connected,
|
|
|
|
|
}) => {
|
|
|
|
|
const {
|
|
|
|
|
uri,
|
|
|
|
|
playlist,
|
|
|
|
|
mopidy_connected,
|
|
|
|
|
coreActions: {
|
|
|
|
|
loadPlaylist,
|
|
|
|
|
},
|
|
|
|
|
history: {
|
|
|
|
|
push,
|
|
|
|
|
},
|
|
|
|
|
} = this.props;
|
2020-04-16 16:24:47 +12:00
|
|
|
|
2020-03-11 20:40:20 +13:00
|
|
|
if (prevPlaylist && playlist && prevPlaylist.moved_to !== playlist.moved_to) {
|
|
|
|
|
push(`/playlist/${encodeURIComponent(playlist.moved_to)}`);
|
2019-09-05 15:36:11 +12:00
|
|
|
}
|
|
|
|
|
|
2020-03-11 20:40:20 +13:00
|
|
|
if (uri !== prevUri) {
|
|
|
|
|
loadPlaylist(uri);
|
|
|
|
|
} else if (!prev_mopidy_connected && mopidy_connected) {
|
|
|
|
|
if (uriSource(uri) !== 'spotify') {
|
2020-05-03 13:54:34 +12:00
|
|
|
loadPlaylist(uri);
|
2019-09-05 15:36:11 +12:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-11 20:40:20 +13:00
|
|
|
if (!prevPlaylist && playlist) this.setWindowTitle(playlist);
|
|
|
|
|
if (prevUri !== uri && playlist) this.setWindowTitle(playlist);
|
2019-09-05 15:36:11 +12:00
|
|
|
}
|
|
|
|
|
|
2020-07-08 20:15:14 +12:00
|
|
|
setWindowTitle = (playlist = this.props.playlist) => {
|
|
|
|
|
const { uiActions: { setWindowTitle } } = this.props;
|
|
|
|
|
setWindowTitle(
|
|
|
|
|
playlist ? i18n('playlist.title_window', { name: playlist.name }) : i18n('playlist.title')
|
|
|
|
|
);
|
2019-09-05 15:36:11 +12:00
|
|
|
}
|
|
|
|
|
|
2020-07-08 20:15:14 +12:00
|
|
|
loadMore = () => {
|
|
|
|
|
const {
|
|
|
|
|
spotifyActions: {
|
|
|
|
|
getMore,
|
|
|
|
|
},
|
|
|
|
|
playlist: {
|
|
|
|
|
uri,
|
|
|
|
|
tracks_more,
|
|
|
|
|
},
|
|
|
|
|
} = this.props;
|
|
|
|
|
|
|
|
|
|
getMore(
|
|
|
|
|
tracks_more,
|
2019-09-05 15:36:11 +12:00
|
|
|
{
|
|
|
|
|
parent_type: 'playlist',
|
2020-07-08 20:15:14 +12:00
|
|
|
parent_key: uri,
|
2019-09-05 15:36:11 +12:00
|
|
|
records_type: 'track',
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-08 20:15:14 +12:00
|
|
|
handleContextMenu = (e) => {
|
|
|
|
|
const {
|
|
|
|
|
uiActions: {
|
|
|
|
|
showContextMenu,
|
|
|
|
|
},
|
|
|
|
|
playlist,
|
|
|
|
|
uri,
|
|
|
|
|
} = this.props;
|
|
|
|
|
|
|
|
|
|
showContextMenu({
|
2019-09-05 15:36:11 +12:00
|
|
|
e,
|
|
|
|
|
context: 'playlist',
|
2020-07-08 20:15:14 +12:00
|
|
|
items: [playlist],
|
|
|
|
|
uris: [uri],
|
|
|
|
|
});
|
2019-09-05 15:36:11 +12:00
|
|
|
}
|
|
|
|
|
|
2020-07-08 20:15:14 +12:00
|
|
|
play = () => {
|
|
|
|
|
const {
|
|
|
|
|
mopidyActions: {
|
|
|
|
|
playPlaylist,
|
|
|
|
|
},
|
|
|
|
|
playlist: {
|
|
|
|
|
uri,
|
|
|
|
|
},
|
|
|
|
|
} = this.props;
|
2016-11-11 09:33:35 +13:00
|
|
|
|
2020-07-08 20:15:14 +12:00
|
|
|
playPlaylist(uri);
|
2019-09-05 15:36:11 +12:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TODO: Once deletion occurs, remove playlist from global playlists list
|
2020-07-08 20:15:14 +12:00
|
|
|
delete = () => {
|
|
|
|
|
const {
|
|
|
|
|
mopidyActions: {
|
|
|
|
|
deletePlaylist,
|
|
|
|
|
},
|
|
|
|
|
playlist: {
|
|
|
|
|
uri,
|
|
|
|
|
},
|
|
|
|
|
} = this.props;
|
|
|
|
|
|
|
|
|
|
deletePlaylist(uri);
|
2019-09-05 15:36:11 +12:00
|
|
|
}
|
|
|
|
|
|
2020-07-08 20:15:14 +12:00
|
|
|
reorderTracks = (indexes, index) => {
|
|
|
|
|
const {
|
|
|
|
|
coreActions: {
|
|
|
|
|
reorderPlaylistTracks,
|
|
|
|
|
},
|
|
|
|
|
playlist: {
|
|
|
|
|
uri,
|
|
|
|
|
snapshot_id,
|
|
|
|
|
},
|
|
|
|
|
} = this.props;
|
|
|
|
|
|
|
|
|
|
reorderPlaylistTracks(uri, indexes, index, snapshot_id);
|
2019-09-05 15:36:11 +12:00
|
|
|
}
|
|
|
|
|
|
2020-07-08 20:15:14 +12:00
|
|
|
removeTracks = (tracks_indexes) => {
|
2019-09-05 15:36:11 +12:00
|
|
|
this.props.coreActions.removeTracksFromPlaylist(this.props.playlist.uri, tracks_indexes);
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-08 20:15:14 +12:00
|
|
|
inLibrary = () => {
|
|
|
|
|
const { uri } = this.props;
|
|
|
|
|
const libraryName = `${uriSource(uri)}_library_playlists`;
|
2020-07-23 21:07:08 +12:00
|
|
|
const { [libraryName]: library } = this.props;
|
|
|
|
|
|
|
|
|
|
if (!library) return false;
|
|
|
|
|
|
2020-07-08 20:15:14 +12:00
|
|
|
return library.indexOf(uri) > -1;
|
2019-09-05 15:36:11 +12:00
|
|
|
}
|
|
|
|
|
|
2020-07-08 20:15:14 +12:00
|
|
|
renderActions = () => {
|
|
|
|
|
const {
|
|
|
|
|
uri,
|
|
|
|
|
playlist: {
|
|
|
|
|
can_edit,
|
|
|
|
|
},
|
|
|
|
|
} = this.props;
|
|
|
|
|
|
2020-03-03 16:39:37 +13:00
|
|
|
switch (uriSource(this.props.uri)) {
|
2019-09-05 15:36:11 +12:00
|
|
|
case 'm3u':
|
|
|
|
|
return (
|
|
|
|
|
<div className="actions">
|
2020-07-08 20:15:14 +12:00
|
|
|
<button className="button button--primary" onClick={this.play}>
|
|
|
|
|
<I18n path="actions.play" />
|
|
|
|
|
</button>
|
|
|
|
|
<Link
|
|
|
|
|
className="button button--default"
|
|
|
|
|
to={`/playlist/${encodeURIComponent(uri)}/edit`}
|
|
|
|
|
>
|
|
|
|
|
<I18n path="actions.edit" />
|
|
|
|
|
</Link>
|
|
|
|
|
<ContextMenuTrigger onTrigger={this.handleContextMenu} />
|
2019-09-05 15:36:11 +12:00
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
case 'spotify':
|
2020-07-08 20:15:14 +12:00
|
|
|
if (can_edit) {
|
2019-09-05 15:36:11 +12:00
|
|
|
return (
|
|
|
|
|
<div className="actions">
|
2020-07-08 20:15:14 +12:00
|
|
|
<button className="button button--primary" onClick={this.play}>
|
|
|
|
|
<I18n path="actions.play" />
|
|
|
|
|
</button>
|
|
|
|
|
<Link
|
|
|
|
|
className="button button--default"
|
|
|
|
|
to={`/playlist/${encodeURIComponent(uri)}/edit`}
|
|
|
|
|
>
|
|
|
|
|
<I18n path="actions.edit" />
|
|
|
|
|
</Link>
|
|
|
|
|
<ContextMenuTrigger onTrigger={this.handleContextMenu} />
|
2019-09-05 15:36:11 +12:00
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
return (
|
|
|
|
|
<div className="actions">
|
2020-07-08 20:15:14 +12:00
|
|
|
<button className="button button--primary" onClick={this.play}>
|
|
|
|
|
<I18n path="actions.play" />
|
|
|
|
|
</button>
|
|
|
|
|
<FollowButton
|
|
|
|
|
uri={uri}
|
|
|
|
|
is_following={this.inLibrary()}
|
|
|
|
|
/>
|
|
|
|
|
<ContextMenuTrigger onTrigger={this.handleContextMenu} />
|
2019-09-05 15:36:11 +12:00
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
return (
|
|
|
|
|
<div className="actions">
|
2020-07-08 20:15:14 +12:00
|
|
|
<button
|
|
|
|
|
className="button button--primary"
|
|
|
|
|
onClick={this.play}
|
|
|
|
|
>
|
|
|
|
|
<I18n path="actions.play" />
|
|
|
|
|
</button>
|
|
|
|
|
<ContextMenuTrigger onTrigger={this.handleContextMenu} />
|
2019-09-05 15:36:11 +12:00
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-08 20:15:14 +12:00
|
|
|
render = () => {
|
|
|
|
|
const {
|
|
|
|
|
uri,
|
|
|
|
|
playlist: playlistProp,
|
|
|
|
|
load_queue,
|
|
|
|
|
tracks,
|
|
|
|
|
users,
|
|
|
|
|
slim_mode,
|
|
|
|
|
} = this.props;
|
|
|
|
|
|
|
|
|
|
const playlist_id = getFromUri('playlistid', uri);
|
2019-09-05 15:36:11 +12:00
|
|
|
|
2020-07-08 20:15:14 +12:00
|
|
|
if (!playlistProp) {
|
|
|
|
|
if (isLoading(load_queue, [`spotify_playlists/${playlist_id}?`])) {
|
2019-09-10 06:59:44 +12:00
|
|
|
return <Loader body loading />
|
2019-09-05 15:36:11 +12:00
|
|
|
}
|
|
|
|
|
return (
|
|
|
|
|
<ErrorMessage type="not-found" title="Not found">
|
2019-09-10 06:59:44 +12:00
|
|
|
<p>
|
2020-07-08 20:15:14 +12:00
|
|
|
<I18n path="errors.uri_not_found" uri={uri} />
|
2019-09-05 15:36:11 +12:00
|
|
|
</p>
|
|
|
|
|
</ErrorMessage>
|
2019-09-10 06:59:44 +12:00
|
|
|
);
|
2019-09-05 15:36:11 +12:00
|
|
|
}
|
|
|
|
|
|
2020-07-08 20:15:14 +12:00
|
|
|
const playlist = collate(playlistProp, { tracks, users });
|
2019-09-05 15:36:11 +12:00
|
|
|
|
|
|
|
|
let context = 'playlist';
|
|
|
|
|
if (playlist.can_edit) {
|
|
|
|
|
context = 'editable-playlist';
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-08 20:15:14 +12:00
|
|
|
const is_loading_tracks = (
|
|
|
|
|
playlist.tracks_total !== 0
|
|
|
|
|
&& (
|
|
|
|
|
!playlist.tracks_uris
|
|
|
|
|
|| (playlist.tracks_uris && !playlist.tracks)
|
|
|
|
|
|| (playlist.tracks_uris.length !== playlist.tracks.length)
|
|
|
|
|
)
|
|
|
|
|
);
|
2019-09-05 15:36:11 +12:00
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div className="view playlist-view content-wrapper preserve-3d">
|
|
|
|
|
|
|
|
|
|
<div className="thumbnail-wrapper">
|
2020-04-17 21:44:49 +12:00
|
|
|
<Thumbnail size="large" glow canZoom images={playlist.images} type="playlist" />
|
2019-09-05 15:36:11 +12:00
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div className="title">
|
|
|
|
|
<h1>{playlist.name}</h1>
|
2020-07-08 20:15:14 +12:00
|
|
|
{playlist.description && (
|
|
|
|
|
<h2
|
|
|
|
|
className="description"
|
|
|
|
|
dangerouslySetInnerHTML={{ __html: playlist.description }}
|
|
|
|
|
/>
|
|
|
|
|
)}
|
2019-09-05 15:36:11 +12:00
|
|
|
|
|
|
|
|
<ul className="details">
|
2020-07-08 20:15:14 +12:00
|
|
|
{!slim_mode && (
|
|
|
|
|
<li className="source">
|
|
|
|
|
<Icon type="fontawesome" name={sourceIcon(playlist.uri)} />
|
|
|
|
|
</li>
|
|
|
|
|
)}
|
|
|
|
|
{playlist.user_uri && (
|
|
|
|
|
<li>
|
|
|
|
|
<URILink
|
|
|
|
|
type="user"
|
|
|
|
|
uri={playlist.user_uri}
|
|
|
|
|
>
|
|
|
|
|
{playlist.user ? playlist.user.name : getFromUri('userid', playlist.user_uri)}
|
|
|
|
|
</URILink>
|
|
|
|
|
</li>
|
|
|
|
|
)}
|
2019-09-10 06:59:44 +12:00
|
|
|
<li>
|
2020-07-08 20:15:14 +12:00
|
|
|
<I18n path="specs.tracks" count={playlist.tracks_total || 0} />
|
2019-09-05 15:36:11 +12:00
|
|
|
</li>
|
2020-07-08 20:15:14 +12:00
|
|
|
{!slim_mode && playlist.tracks && playlist.tracks_total > 0 && (
|
|
|
|
|
<li><Dater type="total-time" data={playlist.tracks} /></li>
|
|
|
|
|
)}
|
|
|
|
|
{!slim_mode && playlist.followers !== undefined && (
|
2019-09-10 06:59:44 +12:00
|
|
|
<li>
|
2020-07-08 20:15:14 +12:00
|
|
|
<I18n path="specs.followers" count={nice_number(playlist.followers)} />
|
2019-09-10 06:59:44 +12:00
|
|
|
</li>
|
2020-07-08 20:15:14 +12:00
|
|
|
)}
|
|
|
|
|
{!slim_mode && playlist.last_modified_date && (
|
2019-09-10 06:59:44 +12:00
|
|
|
<li>
|
2020-07-08 20:15:14 +12:00
|
|
|
<I18n path="specs.edited" date={dater('ago', playlist.last_modified_date)} />
|
2019-09-10 06:59:44 +12:00
|
|
|
</li>
|
2020-07-08 20:15:14 +12:00
|
|
|
)}
|
2019-09-05 15:36:11 +12:00
|
|
|
</ul>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
{this.renderActions()}
|
|
|
|
|
|
|
|
|
|
<section className="list-wrapper">
|
|
|
|
|
<TrackList
|
|
|
|
|
uri={playlist.uri}
|
|
|
|
|
className="playlist-track-list"
|
|
|
|
|
track_context={context}
|
|
|
|
|
tracks={playlist.tracks}
|
2020-07-08 20:15:14 +12:00
|
|
|
removeTracks={this.removeTracks}
|
|
|
|
|
reorderTracks={this.reorderTracks}
|
2019-09-05 15:36:11 +12:00
|
|
|
/>
|
|
|
|
|
<LazyLoadListener
|
|
|
|
|
loadKey={playlist.tracks_more}
|
|
|
|
|
showLoader={is_loading_tracks || playlist.tracks_more}
|
2020-07-08 20:15:14 +12:00
|
|
|
loadMore={this.loadMore}
|
2019-09-05 15:36:11 +12:00
|
|
|
/>
|
|
|
|
|
</section>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
2016-10-20 21:38:01 +13:00
|
|
|
}
|
|
|
|
|
|
2019-09-10 06:59:44 +12:00
|
|
|
const mapStateToProps = (state, ownProps) => {
|
2020-05-03 13:54:34 +12:00
|
|
|
const {
|
|
|
|
|
ui: {
|
|
|
|
|
allow_reporting,
|
|
|
|
|
slim_mode,
|
|
|
|
|
theme,
|
|
|
|
|
load_queue,
|
|
|
|
|
} = {},
|
|
|
|
|
core: {
|
|
|
|
|
users,
|
|
|
|
|
tracks,
|
|
|
|
|
playlists,
|
|
|
|
|
} = {},
|
|
|
|
|
spotify: {
|
|
|
|
|
library_playlists: spotify_library_playlists,
|
|
|
|
|
authorization: spotify_authorized,
|
2020-05-12 20:32:48 +12:00
|
|
|
me = {},
|
2020-05-03 13:54:34 +12:00
|
|
|
} = {},
|
|
|
|
|
mopidy: {
|
|
|
|
|
connected: mopidy_connected,
|
|
|
|
|
library_playlists: local_library_playlists,
|
|
|
|
|
} = {},
|
|
|
|
|
} = state;
|
|
|
|
|
|
2020-05-12 20:32:48 +12:00
|
|
|
const uri = decodeMopidyUri(ownProps.match.params.uri);
|
2019-09-05 15:36:11 +12:00
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
uri,
|
2020-05-03 13:54:34 +12:00
|
|
|
allow_reporting,
|
|
|
|
|
slim_mode,
|
|
|
|
|
theme,
|
|
|
|
|
load_queue,
|
|
|
|
|
users,
|
|
|
|
|
tracks,
|
|
|
|
|
playlist: (playlists[uri] !== undefined ? playlists[uri] : false),
|
|
|
|
|
spotify_library_playlists,
|
|
|
|
|
local_library_playlists,
|
|
|
|
|
mopidy_connected,
|
|
|
|
|
spotify_authorized,
|
2020-05-12 20:32:48 +12:00
|
|
|
spotify_userid: (me && me.id) || null,
|
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),
|
|
|
|
|
});
|
|
|
|
|
|
2019-09-10 06:59:44 +12:00
|
|
|
export default connect(mapStateToProps, mapDispatchToProps)(Playlist);
|