2016-10-17 10:39:11 +13:00
|
|
|
|
2019-09-05 15:36:11 +12:00
|
|
|
import React from 'react';
|
|
|
|
|
import { connect } from 'react-redux';
|
|
|
|
|
import { bindActionCreators } from 'redux';
|
2020-08-17 19:31:28 +12:00
|
|
|
import Button from '../../components/Button';
|
2019-09-05 15:36:11 +12:00
|
|
|
import PlaylistGrid from '../../components/PlaylistGrid';
|
|
|
|
|
import List from '../../components/List';
|
|
|
|
|
import DropdownField from '../../components/Fields/DropdownField';
|
|
|
|
|
import Header from '../../components/Header';
|
|
|
|
|
import FilterField from '../../components/Fields/FilterField';
|
|
|
|
|
import LazyLoadListener from '../../components/LazyLoadListener';
|
|
|
|
|
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 { applyFilter, removeDuplicates, sortItems } from '../../util/arrays';
|
2020-07-19 20:41:14 +12:00
|
|
|
import { I18n, i18n } from '../../locale';
|
2020-09-13 20:59:46 +12:00
|
|
|
import Loader from '../../components/Loader';
|
2020-10-23 23:11:24 +13:00
|
|
|
import {
|
|
|
|
|
makeLibrarySelector,
|
|
|
|
|
makeLoadingSelector,
|
|
|
|
|
makeProcessProgressSelector,
|
|
|
|
|
} from '../../util/selectors';
|
|
|
|
|
|
|
|
|
|
const processKeys = [
|
|
|
|
|
'MOPIDY_GET_LIBRARY_PLAYLISTS',
|
|
|
|
|
'SPOTIFY_GET_LIBRARY_PLAYLISTS',
|
|
|
|
|
];
|
2019-09-05 15:36:11 +12:00
|
|
|
|
2019-10-09 09:42:20 +13:00
|
|
|
class LibraryPlaylists extends React.Component {
|
2019-09-05 15:36:11 +12:00
|
|
|
constructor(props) {
|
|
|
|
|
super(props);
|
|
|
|
|
|
|
|
|
|
this.state = {
|
|
|
|
|
filter: '',
|
|
|
|
|
limit: 50,
|
|
|
|
|
per_page: 50,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-15 13:50:39 +13:00
|
|
|
componentDidMount() {
|
2020-09-07 21:04:28 +12:00
|
|
|
const {
|
|
|
|
|
location: {
|
|
|
|
|
state: {
|
|
|
|
|
limit,
|
|
|
|
|
} = {},
|
|
|
|
|
} = {},
|
|
|
|
|
uiActions: {
|
|
|
|
|
setWindowTitle,
|
|
|
|
|
},
|
|
|
|
|
} = this.props;
|
|
|
|
|
if (limit) {
|
2019-09-05 15:36:11 +12:00
|
|
|
this.setState({
|
2020-09-07 21:04:28 +12:00
|
|
|
limit,
|
2019-09-05 15:36:11 +12:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-07 21:04:28 +12:00
|
|
|
setWindowTitle(i18n('library.playlists.title'));
|
2019-09-05 15:36:11 +12:00
|
|
|
|
2020-08-12 08:06:24 +12:00
|
|
|
this.getMopidyLibrary();
|
|
|
|
|
this.getSpotifyLibrary();
|
2019-09-05 15:36:11 +12:00
|
|
|
}
|
|
|
|
|
|
2020-10-23 23:11:24 +13:00
|
|
|
refresh = () => {
|
2020-09-07 21:04:28 +12:00
|
|
|
const { uiActions: { hideContextMenu } } = this.props;
|
|
|
|
|
|
|
|
|
|
hideContextMenu();
|
|
|
|
|
this.getMopidyLibrary(true);
|
|
|
|
|
this.getSpotifyLibrary(true);
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-23 23:11:24 +13:00
|
|
|
cancelRefresh = () => {
|
|
|
|
|
const { uiActions: { hideContextMenu, cancelProcess } } = this.props;
|
|
|
|
|
|
|
|
|
|
hideContextMenu();
|
|
|
|
|
cancelProcess(processKeys);
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-07 21:04:28 +12:00
|
|
|
getMopidyLibrary = (forceRefetch = false) => {
|
2020-03-12 21:32:50 +13:00
|
|
|
const {
|
|
|
|
|
source,
|
2020-09-04 09:21:42 +12:00
|
|
|
coreActions: {
|
|
|
|
|
loadLibrary,
|
2020-08-12 08:06:24 +12:00
|
|
|
},
|
|
|
|
|
} = this.props;
|
|
|
|
|
|
|
|
|
|
if (source !== 'local' && source !== 'all') return;
|
|
|
|
|
|
2020-09-09 21:30:47 +12:00
|
|
|
loadLibrary('mopidy:library:playlists', { forceRefetch });
|
2020-08-12 08:06:24 +12:00
|
|
|
};
|
|
|
|
|
|
2020-09-07 21:04:28 +12:00
|
|
|
getSpotifyLibrary = (forceRefetch = false) => {
|
2020-08-12 08:06:24 +12:00
|
|
|
const {
|
|
|
|
|
source,
|
2020-08-24 21:15:25 +12:00
|
|
|
spotify_available,
|
2020-09-04 09:21:42 +12:00
|
|
|
coreActions: {
|
|
|
|
|
loadLibrary,
|
2020-08-12 08:06:24 +12:00
|
|
|
},
|
2020-03-12 21:32:50 +13:00
|
|
|
} = this.props;
|
|
|
|
|
|
2020-08-24 21:15:25 +12:00
|
|
|
if (!spotify_available) return;
|
2020-08-12 08:06:24 +12:00
|
|
|
if (source !== 'spotify' && source !== 'all') return;
|
2019-09-05 15:36:11 +12:00
|
|
|
|
2020-09-09 21:30:47 +12:00
|
|
|
loadLibrary('spotify:library:playlists', { forceRefetch });
|
2020-08-12 08:06:24 +12:00
|
|
|
};
|
2019-09-05 15:36:11 +12:00
|
|
|
|
2020-08-12 08:06:24 +12:00
|
|
|
componentDidUpdate = ({ source: prevSource }) => {
|
|
|
|
|
const { source } = this.props;
|
|
|
|
|
|
|
|
|
|
if (source !== prevSource) {
|
|
|
|
|
this.getMopidyLibrary();
|
|
|
|
|
this.getSpotifyLibrary();
|
2019-09-05 15:36:11 +12:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-07 21:04:28 +12:00
|
|
|
setSort(value) {
|
|
|
|
|
let reverse = false;
|
|
|
|
|
if (this.props.sort == value) reverse = !this.props.sort_reverse;
|
|
|
|
|
|
|
|
|
|
const data = {
|
|
|
|
|
library_playlists_sort_reverse: reverse,
|
|
|
|
|
library_playlists_sort: value,
|
|
|
|
|
};
|
|
|
|
|
this.props.uiActions.set(data);
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-05 15:36:11 +12:00
|
|
|
handleContextMenu(e, item) {
|
|
|
|
|
const data = {
|
|
|
|
|
e,
|
|
|
|
|
context: 'playlist',
|
|
|
|
|
uris: [item.uri],
|
|
|
|
|
items: [item],
|
|
|
|
|
};
|
|
|
|
|
this.props.uiActions.showContextMenu(data);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
loadMore() {
|
|
|
|
|
const new_limit = this.state.limit + this.state.per_page;
|
|
|
|
|
|
|
|
|
|
this.setState({ limit: new_limit });
|
|
|
|
|
|
|
|
|
|
// Set our pagination to location state
|
|
|
|
|
const state = (this.props.location && this.props.location.state ? this.props.location.state : {});
|
|
|
|
|
state.limit = new_limit;
|
|
|
|
|
this.props.history.replace({ state });
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-04 09:21:42 +12:00
|
|
|
renderView = () => {
|
|
|
|
|
const {
|
2020-09-05 11:49:28 +12:00
|
|
|
sort,
|
|
|
|
|
sort_reverse,
|
|
|
|
|
view,
|
2020-10-23 23:11:24 +13:00
|
|
|
loading_progress,
|
2020-09-30 21:03:38 +13:00
|
|
|
playlists: playlistsProp,
|
2020-09-04 09:21:42 +12:00
|
|
|
} = this.props;
|
2020-09-05 11:49:28 +12:00
|
|
|
const {
|
|
|
|
|
filter,
|
|
|
|
|
limit,
|
|
|
|
|
} = this.state;
|
2019-09-05 15:36:11 +12:00
|
|
|
|
2020-10-23 23:11:24 +13:00
|
|
|
if (loading_progress < 1) {
|
|
|
|
|
return <Loader body loading progress={loading_progress} />;
|
2020-09-13 20:59:46 +12:00
|
|
|
}
|
2020-09-30 21:03:38 +13:00
|
|
|
let playlists = [...playlistsProp];
|
2020-09-13 20:59:46 +12:00
|
|
|
|
2020-09-05 11:49:28 +12:00
|
|
|
if (sort) {
|
|
|
|
|
playlists = sortItems(playlists, sort, sort_reverse);
|
2019-09-05 15:36:11 +12:00
|
|
|
}
|
2020-03-03 16:39:37 +13:00
|
|
|
playlists = removeDuplicates(playlists);
|
2019-09-05 15:36:11 +12:00
|
|
|
|
2020-09-05 11:49:28 +12:00
|
|
|
if (filter !== '') {
|
|
|
|
|
playlists = applyFilter('name', filter, playlists);
|
2019-09-05 15:36:11 +12:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Apply our lazy-load-rendering
|
|
|
|
|
const total_playlists = playlists.length;
|
2020-09-05 11:49:28 +12:00
|
|
|
playlists = playlists.slice(0, limit);
|
2019-09-05 15:36:11 +12:00
|
|
|
|
2020-09-05 11:49:28 +12:00
|
|
|
if (view === 'list') {
|
2019-09-05 15:36:11 +12:00
|
|
|
return (
|
|
|
|
|
<section className="content-wrapper">
|
|
|
|
|
<List
|
|
|
|
|
handleContextMenu={(e, item) => this.handleContextMenu(e, item)}
|
|
|
|
|
rows={playlists}
|
|
|
|
|
thumbnail
|
2020-04-19 20:57:43 +12:00
|
|
|
details={['owner', 'tracks_total', 'last_modified']}
|
2019-09-05 15:36:11 +12:00
|
|
|
right_column={['source']}
|
|
|
|
|
className="playlists"
|
2019-10-09 09:42:20 +13:00
|
|
|
link_prefix="/playlist/"
|
2019-09-05 15:36:11 +12:00
|
|
|
/>
|
|
|
|
|
<LazyLoadListener
|
2020-09-05 11:49:28 +12:00
|
|
|
loadKey={total_playlists > limit ? limit : total_playlists}
|
|
|
|
|
loading={limit < total_playlists}
|
2019-10-09 09:42:20 +13:00
|
|
|
loadMore={() => this.loadMore()}
|
2019-09-05 15:36:11 +12:00
|
|
|
/>
|
|
|
|
|
</section>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
return (
|
|
|
|
|
<section className="content-wrapper">
|
|
|
|
|
<PlaylistGrid
|
|
|
|
|
handleContextMenu={(e, item) => this.handleContextMenu(e, item)}
|
2019-10-09 09:42:20 +13:00
|
|
|
playlists={playlists}
|
2019-09-05 15:36:11 +12:00
|
|
|
/>
|
|
|
|
|
<LazyLoadListener
|
2020-09-05 11:49:28 +12:00
|
|
|
loadKey={total_playlists > limit ? limit : total_playlists}
|
|
|
|
|
loading={limit < total_playlists}
|
2019-10-09 09:42:20 +13:00
|
|
|
loadMore={() => this.loadMore()}
|
2019-09-05 15:36:11 +12:00
|
|
|
/>
|
|
|
|
|
</section>
|
2019-10-09 09:42:20 +13:00
|
|
|
);
|
2019-09-05 15:36:11 +12:00
|
|
|
}
|
|
|
|
|
|
2020-09-25 06:54:19 +12:00
|
|
|
render = () => {
|
|
|
|
|
const {
|
|
|
|
|
uiActions,
|
|
|
|
|
spotify_available,
|
|
|
|
|
source,
|
|
|
|
|
sort,
|
|
|
|
|
sort_reverse,
|
|
|
|
|
view,
|
2020-10-23 23:11:24 +13:00
|
|
|
loading_progress,
|
2020-09-25 06:54:19 +12:00
|
|
|
} = this.props;
|
|
|
|
|
const {
|
|
|
|
|
filter,
|
|
|
|
|
} = this.state;
|
2020-10-23 23:11:24 +13:00
|
|
|
const loading = loading_progress < 1;
|
2020-09-25 06:54:19 +12:00
|
|
|
|
2019-09-05 15:36:11 +12:00
|
|
|
const source_options = [
|
|
|
|
|
{
|
|
|
|
|
value: 'all',
|
2020-07-19 20:41:14 +12:00
|
|
|
label: i18n('fields.filters.all'),
|
2019-09-05 15:36:11 +12:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
value: 'local',
|
2020-07-19 20:41:14 +12:00
|
|
|
label: i18n('services.mopidy.local'),
|
2019-09-05 15:36:11 +12:00
|
|
|
},
|
|
|
|
|
];
|
|
|
|
|
|
2020-09-25 06:54:19 +12:00
|
|
|
if (spotify_available) {
|
2019-09-05 15:36:11 +12:00
|
|
|
source_options.push({
|
|
|
|
|
value: 'spotify',
|
2020-07-19 20:41:14 +12:00
|
|
|
label: i18n('services.spotify.title'),
|
2019-09-05 15:36:11 +12:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const view_options = [
|
|
|
|
|
{
|
|
|
|
|
value: 'thumbnails',
|
2020-07-19 20:41:14 +12:00
|
|
|
label: i18n('fields.filters.thumbnails'),
|
2019-09-05 15:36:11 +12:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
value: 'list',
|
2020-07-19 20:41:14 +12:00
|
|
|
label: i18n('fields.filters.list'),
|
2019-09-05 15:36:11 +12:00
|
|
|
},
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
const sort_options = [
|
|
|
|
|
{
|
|
|
|
|
value: null,
|
2020-07-19 20:41:14 +12:00
|
|
|
label: i18n('fields.filters.as_loaded'),
|
2019-09-05 15:36:11 +12:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
value: 'name',
|
2020-07-19 20:41:14 +12:00
|
|
|
label: i18n('fields.filters.name'),
|
2019-09-05 15:36:11 +12:00
|
|
|
},
|
2020-04-19 20:57:43 +12:00
|
|
|
{
|
|
|
|
|
value: 'last_modified',
|
2020-07-19 20:41:14 +12:00
|
|
|
label: i18n('fields.filters.updated'),
|
2020-04-19 20:57:43 +12:00
|
|
|
},
|
2019-09-05 15:36:11 +12:00
|
|
|
{
|
|
|
|
|
value: 'can_edit',
|
2020-07-19 20:41:14 +12:00
|
|
|
label: i18n('fields.filters.editable'),
|
2019-09-05 15:36:11 +12:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
value: 'owner.id',
|
2020-07-19 20:41:14 +12:00
|
|
|
label: i18n('fields.filters.owner'),
|
2019-09-05 15:36:11 +12:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
value: 'tracks_total',
|
2020-07-19 20:41:14 +12:00
|
|
|
label: i18n('fields.filters.tracks'),
|
2019-09-05 15:36:11 +12:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
value: 'source',
|
2020-07-19 20:41:14 +12:00
|
|
|
label: i18n('fields.filters.source'),
|
2019-09-05 15:36:11 +12:00
|
|
|
},
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
const options = (
|
|
|
|
|
<span>
|
|
|
|
|
<FilterField
|
2020-09-25 06:54:19 +12:00
|
|
|
initialValue={filter}
|
2019-10-09 09:42:20 +13:00
|
|
|
handleChange={(value) => this.setState({ filter: value })}
|
2020-09-25 06:54:19 +12:00
|
|
|
onSubmit={() => uiActions.hideContextMenu()}
|
2019-09-05 15:36:11 +12:00
|
|
|
/>
|
|
|
|
|
<DropdownField
|
2019-10-13 09:29:41 +13:00
|
|
|
icon="swap_vert"
|
2020-07-19 20:41:14 +12:00
|
|
|
name={i18n('fields.sort')}
|
2020-09-25 06:54:19 +12:00
|
|
|
value={sort}
|
2019-10-13 09:29:41 +13:00
|
|
|
valueAsLabel
|
2019-09-05 15:36:11 +12:00
|
|
|
options={sort_options}
|
2020-09-25 06:54:19 +12:00
|
|
|
selected_icon={sort ? (sort_reverse ? 'keyboard_arrow_up' : 'keyboard_arrow_down') : null}
|
|
|
|
|
handleChange={(value) => { this.setSort(value); uiActions.hideContextMenu(); }}
|
2019-09-05 15:36:11 +12:00
|
|
|
/>
|
|
|
|
|
<DropdownField
|
|
|
|
|
icon="visibility"
|
2020-07-19 20:41:14 +12:00
|
|
|
name={i18n('fields.view')}
|
2019-10-13 09:29:41 +13:00
|
|
|
valueAsLabel
|
2020-09-25 06:54:19 +12:00
|
|
|
value={view}
|
2019-09-05 15:36:11 +12:00
|
|
|
options={view_options}
|
2020-09-25 06:54:19 +12:00
|
|
|
handleChange={(value) => { uiActions.set({ library_playlists_view: value }); uiActions.hideContextMenu(); }}
|
2019-09-05 15:36:11 +12:00
|
|
|
/>
|
|
|
|
|
<DropdownField
|
|
|
|
|
icon="cloud"
|
2020-07-19 20:41:14 +12:00
|
|
|
name={i18n('fields.source')}
|
2019-10-13 09:29:41 +13:00
|
|
|
valueAsLabel
|
2020-09-25 06:54:19 +12:00
|
|
|
value={source}
|
2019-09-05 15:36:11 +12:00
|
|
|
options={source_options}
|
2020-09-25 06:54:19 +12:00
|
|
|
handleChange={(value) => { uiActions.set({ library_playlists_source: value }); uiActions.hideContextMenu(); }}
|
2019-09-05 15:36:11 +12:00
|
|
|
/>
|
2020-08-16 20:00:10 +12:00
|
|
|
<Button
|
|
|
|
|
noHover
|
2020-08-17 19:31:28 +12:00
|
|
|
discrete
|
2020-10-23 23:11:24 +13:00
|
|
|
onClick={loading ? this.cancelRefresh : this.refresh}
|
2020-09-07 21:04:28 +12:00
|
|
|
tracking={{ category: 'LibraryAlbums', action: 'Refresh' }}
|
|
|
|
|
>
|
2020-10-23 23:11:24 +13:00
|
|
|
{loading ? <Icon name="close" /> : <Icon name="refresh" /> }
|
|
|
|
|
{loading ? <I18n path="actions.cancel" /> : <I18n path="actions.refresh" /> }
|
2020-09-07 21:04:28 +12:00
|
|
|
</Button>
|
2020-09-26 23:03:28 +12:00
|
|
|
<Button
|
|
|
|
|
to="/playlist/create"
|
|
|
|
|
noHover
|
|
|
|
|
discrete
|
|
|
|
|
tracking={{ category: 'Playlist', action: 'Create' }}
|
|
|
|
|
>
|
|
|
|
|
<Icon name="add_box" />
|
|
|
|
|
<I18n path="actions.add" />
|
|
|
|
|
</Button>
|
2019-09-05 15:36:11 +12:00
|
|
|
</span>
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div className="view library-playlists-view">
|
2020-09-25 06:54:19 +12:00
|
|
|
<Header options={options} uiActions={uiActions}>
|
2019-09-05 15:36:11 +12:00
|
|
|
<Icon name="queue_music" type="material" />
|
2020-07-19 20:41:14 +12:00
|
|
|
<I18n path="library.playlists.title" />
|
2019-09-05 15:36:11 +12:00
|
|
|
</Header>
|
|
|
|
|
{ this.renderView() }
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
2016-10-17 10:39:11 +13:00
|
|
|
}
|
|
|
|
|
|
2020-09-05 11:49:28 +12:00
|
|
|
const mapStateToProps = (state) => {
|
2020-09-25 06:54:19 +12:00
|
|
|
const source = state.ui.library_playlists_source || 'all';
|
|
|
|
|
|
2020-09-26 22:00:12 +12:00
|
|
|
const libraryUris = [];
|
|
|
|
|
if (source === 'all' || source === 'local') libraryUris.push('mopidy:library:playlists');
|
|
|
|
|
if (source === 'all' || source === 'spotify') libraryUris.push('spotify:library:playlists');
|
|
|
|
|
if (source === 'all' || source === 'google') libraryUris.push('google:library:playlists');
|
|
|
|
|
const librarySelector = makeLibrarySelector(libraryUris);
|
2020-10-23 23:11:24 +13:00
|
|
|
const processProgressSelector = makeProcessProgressSelector(processKeys);
|
2020-09-25 06:54:19 +12:00
|
|
|
|
2020-09-05 11:49:28 +12:00
|
|
|
return {
|
|
|
|
|
slim_mode: state.ui.slim_mode,
|
|
|
|
|
mopidy_uri_schemes: state.mopidy.uri_schemes,
|
|
|
|
|
spotify_available: state.spotify.access_token,
|
2020-09-26 22:00:12 +12:00
|
|
|
playlists: librarySelector(state),
|
2020-10-23 23:11:24 +13:00
|
|
|
loading_progress: processProgressSelector(state),
|
2020-09-25 06:54:19 +12:00
|
|
|
source,
|
2020-09-05 11:49:28 +12:00
|
|
|
me_id: (state.spotify.me ? state.spotify.me.id : false),
|
|
|
|
|
view: state.ui.library_playlists_view,
|
|
|
|
|
sort: (state.ui.library_playlists_sort ? state.ui.library_playlists_sort : null),
|
|
|
|
|
sort_reverse: (state.ui.library_playlists_sort_reverse ? state.ui.library_playlists_sort_reverse : false),
|
|
|
|
|
};
|
|
|
|
|
};
|
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-10-09 09:42:20 +13:00
|
|
|
export default connect(mapStateToProps, mapDispatchToProps)(LibraryPlaylists);
|