2019-02-10 19:51:33 +13:00
|
|
|
import React from 'react';
|
2018-10-17 21:33:54 +13:00
|
|
|
import { connect } from 'react-redux';
|
|
|
|
|
import { bindActionCreators } from 'redux';
|
|
|
|
|
import Header from '../../components/Header';
|
|
|
|
|
import DropdownField from '../../components/Fields/DropdownField';
|
|
|
|
|
import FilterField from '../../components/Fields/FilterField';
|
2021-02-27 21:45:00 +13:00
|
|
|
import { Grid } from '../../components/Grid';
|
2021-03-01 21:31:22 +13:00
|
|
|
import { List } from '../../components/List';
|
2018-10-17 21:33:54 +13:00
|
|
|
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 googleActions from '../../services/google/actions';
|
|
|
|
|
import * as spotifyActions from '../../services/spotify/actions';
|
2020-03-03 16:39:37 +13:00
|
|
|
import { sortItems, applyFilter } from '../../util/arrays';
|
2020-09-07 21:04:28 +12:00
|
|
|
import Button from '../../components/Button';
|
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-09-22 06:59:15 +12:00
|
|
|
import {
|
|
|
|
|
makeLibrarySelector,
|
2020-10-20 21:34:43 +13:00
|
|
|
makeProcessProgressSelector,
|
2020-09-22 06:59:15 +12:00
|
|
|
} from '../../util/selectors';
|
2016-10-20 21:38:01 +13:00
|
|
|
|
2020-10-23 23:11:24 +13:00
|
|
|
const processKeys = [
|
|
|
|
|
'MOPIDY_GET_LIBRARY_ALBUMS',
|
|
|
|
|
'SPOTIFY_GET_LIBRARY_ALBUMS',
|
|
|
|
|
'GOOGLE_GET_LIBRARY_ALBUMS',
|
|
|
|
|
];
|
|
|
|
|
|
2019-10-09 09:42:20 +13:00
|
|
|
class LibraryAlbums extends React.Component {
|
2019-09-05 15:36:11 +12:00
|
|
|
constructor(props) {
|
|
|
|
|
super(props);
|
|
|
|
|
|
|
|
|
|
this.state = {
|
|
|
|
|
filter: '',
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-15 13:50:39 +13:00
|
|
|
componentDidMount() {
|
2020-07-19 20:41:14 +12:00
|
|
|
const {
|
|
|
|
|
uiActions: {
|
|
|
|
|
setWindowTitle,
|
|
|
|
|
},
|
|
|
|
|
} = this.props;
|
|
|
|
|
|
|
|
|
|
setWindowTitle(i18n('library.albums.title'));
|
2020-08-12 08:06:24 +12:00
|
|
|
this.getMopidyLibrary();
|
|
|
|
|
this.getGoogleLibrary();
|
|
|
|
|
this.getSpotifyLibrary();
|
|
|
|
|
}
|
2019-09-05 15:36:11 +12:00
|
|
|
|
2020-08-12 08:06:24 +12:00
|
|
|
componentDidUpdate = ({ source: prevSource }) => {
|
|
|
|
|
const { source } = this.props;
|
2019-09-05 15:36:11 +12:00
|
|
|
|
2020-08-12 08:06:24 +12:00
|
|
|
if (source !== prevSource) {
|
|
|
|
|
this.getMopidyLibrary();
|
|
|
|
|
this.getGoogleLibrary();
|
|
|
|
|
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.getGoogleLibrary(true);
|
|
|
|
|
this.getSpotifyLibrary(true);
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-23 23:11:24 +13:00
|
|
|
cancelRefresh = () => {
|
|
|
|
|
const { uiActions: { hideContextMenu, cancelProcess } } = this.props;
|
|
|
|
|
|
|
|
|
|
hideContextMenu();
|
|
|
|
|
cancelProcess(processKeys);
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-11 22:13:06 +12:00
|
|
|
getMopidyLibrary = (forceRefetch = false) => {
|
2020-03-12 08:31:32 +13:00
|
|
|
const {
|
|
|
|
|
source,
|
2020-09-05 11:49:28 +12:00
|
|
|
coreActions: {
|
|
|
|
|
loadLibrary,
|
2020-08-12 08:06:24 +12:00
|
|
|
},
|
|
|
|
|
} = this.props;
|
|
|
|
|
|
|
|
|
|
if (source !== 'local' && source !== 'all') return;
|
|
|
|
|
|
2020-09-11 22:13:06 +12:00
|
|
|
loadLibrary('mopidy:library:albums', { forceRefetch });
|
2020-08-12 08:06:24 +12:00
|
|
|
};
|
|
|
|
|
|
2020-09-11 22:13:06 +12:00
|
|
|
getGoogleLibrary = (forceRefetch = false) => {
|
2020-08-12 08:06:24 +12:00
|
|
|
const {
|
|
|
|
|
source,
|
|
|
|
|
google_available,
|
2020-09-05 11:49:28 +12:00
|
|
|
coreActions: {
|
|
|
|
|
loadLibrary,
|
2020-08-12 08:06:24 +12:00
|
|
|
},
|
2020-03-12 08:31:32 +13:00
|
|
|
} = this.props;
|
|
|
|
|
|
2020-08-12 08:06:24 +12:00
|
|
|
if (!google_available) return;
|
|
|
|
|
if (source !== 'google' && source !== 'all') return;
|
2019-09-05 15:36:11 +12:00
|
|
|
|
2020-09-11 22:13:06 +12:00
|
|
|
loadLibrary('google:library:albums', { forceRefetch });
|
2020-08-12 08:06:24 +12:00
|
|
|
};
|
2019-09-05 15:36:11 +12:00
|
|
|
|
2020-09-11 22:13:06 +12:00
|
|
|
getSpotifyLibrary = (forceRefetch = false) => {
|
2020-08-12 08:06:24 +12:00
|
|
|
const {
|
|
|
|
|
source,
|
|
|
|
|
spotify_available,
|
2020-09-05 11:49:28 +12:00
|
|
|
coreActions: {
|
|
|
|
|
loadLibrary,
|
2020-08-12 08:06:24 +12:00
|
|
|
},
|
|
|
|
|
} = this.props;
|
|
|
|
|
|
|
|
|
|
if (!spotify_available) return;
|
|
|
|
|
if (source !== 'spotify' && source !== 'all') return;
|
|
|
|
|
|
2020-09-11 22:13:06 +12:00
|
|
|
loadLibrary('spotify:library:albums', { forceRefetch });
|
2020-08-12 08:06:24 +12:00
|
|
|
};
|
2019-09-05 15:36:11 +12:00
|
|
|
|
2020-07-19 20:41:14 +12:00
|
|
|
handleContextMenu = (e, item) => {
|
|
|
|
|
const {
|
|
|
|
|
uiActions: {
|
|
|
|
|
showContextMenu,
|
|
|
|
|
},
|
|
|
|
|
} = this.props;
|
|
|
|
|
|
|
|
|
|
showContextMenu({
|
2019-09-05 15:36:11 +12:00
|
|
|
e,
|
|
|
|
|
context: 'album',
|
|
|
|
|
uris: [item.uri],
|
|
|
|
|
items: [item],
|
2020-07-19 20:41:14 +12:00
|
|
|
});
|
2019-09-05 15:36:11 +12:00
|
|
|
}
|
|
|
|
|
|
2020-07-19 20:41:14 +12:00
|
|
|
setSort = (value) => {
|
|
|
|
|
const {
|
|
|
|
|
sort,
|
|
|
|
|
sort_reverse,
|
|
|
|
|
uiActions: {
|
|
|
|
|
set,
|
|
|
|
|
},
|
|
|
|
|
} = this.props;
|
|
|
|
|
|
2019-09-05 15:36:11 +12:00
|
|
|
let reverse = false;
|
2020-07-19 20:41:14 +12:00
|
|
|
if (sort === value) reverse = !sort_reverse;
|
2019-09-05 15:36:11 +12:00
|
|
|
|
2020-07-19 20:41:14 +12:00
|
|
|
set({
|
2019-09-05 15:36:11 +12:00
|
|
|
library_albums_sort_reverse: reverse,
|
|
|
|
|
library_albums_sort: value,
|
2020-07-19 20:41:14 +12:00
|
|
|
});
|
2019-09-05 15:36:11 +12:00
|
|
|
}
|
|
|
|
|
|
2020-07-19 20:41:14 +12:00
|
|
|
renderView = () => {
|
2020-09-05 11:49:28 +12:00
|
|
|
const {
|
|
|
|
|
sort,
|
|
|
|
|
sort_reverse,
|
|
|
|
|
view,
|
2020-10-20 21:34:43 +13:00
|
|
|
loading_progress,
|
2020-09-05 11:49:28 +12:00
|
|
|
} = this.props;
|
|
|
|
|
const {
|
|
|
|
|
filter,
|
|
|
|
|
} = this.state;
|
2020-09-20 21:04:40 +12:00
|
|
|
let { albums } = this.props;
|
2019-09-05 15:36:11 +12:00
|
|
|
|
2020-12-05 21:41:30 +13:00
|
|
|
if (loading_progress) {
|
2020-10-23 23:11:24 +13:00
|
|
|
return <Loader body loading progress={loading_progress} />;
|
2020-09-13 20:59:46 +12:00
|
|
|
}
|
|
|
|
|
|
2020-09-05 11:49:28 +12:00
|
|
|
if (sort) {
|
|
|
|
|
albums = sortItems(albums, sort, sort_reverse);
|
2019-09-05 15:36:11 +12:00
|
|
|
}
|
|
|
|
|
|
2020-09-05 11:49:28 +12:00
|
|
|
if (filter && filter !== '') {
|
|
|
|
|
albums = applyFilter('name', filter, albums);
|
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
|
2021-03-01 21:31:22 +13:00
|
|
|
items={albums}
|
2021-03-04 06:43:53 +13:00
|
|
|
details={['artists', 'followers', 'listeners']}
|
|
|
|
|
right_column={['tracks']}
|
2019-09-05 15:36:11 +12:00
|
|
|
thumbnail
|
|
|
|
|
/>
|
|
|
|
|
</section>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
return (
|
|
|
|
|
<section className="content-wrapper">
|
2021-02-27 21:45:00 +13:00
|
|
|
<Grid items={albums} />
|
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-05 11:49:28 +12:00
|
|
|
render = () => {
|
|
|
|
|
const {
|
|
|
|
|
spotify_available,
|
|
|
|
|
google_available,
|
|
|
|
|
sort,
|
|
|
|
|
view,
|
|
|
|
|
source,
|
|
|
|
|
sort_reverse,
|
2020-09-07 21:04:28 +12:00
|
|
|
uiActions,
|
2020-10-23 23:11:24 +13:00
|
|
|
loading_progress,
|
2020-09-05 11:49:28 +12:00
|
|
|
} = this.props;
|
|
|
|
|
const {
|
|
|
|
|
filter,
|
|
|
|
|
per_page,
|
|
|
|
|
} = this.state;
|
|
|
|
|
|
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-08-01 21:15:17 +12:00
|
|
|
label: i18n('services.mopidy.local'),
|
2019-09-05 15:36:11 +12:00
|
|
|
},
|
|
|
|
|
];
|
|
|
|
|
|
2020-09-05 11:49:28 +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
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-05 11:49:28 +12:00
|
|
|
if (google_available) {
|
2019-09-05 15:36:11 +12:00
|
|
|
source_options.push({
|
|
|
|
|
value: 'google',
|
2020-07-19 20:41:14 +12:00
|
|
|
label: i18n('services.google.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-11-08 20:49:48 +13:00
|
|
|
value: 'artist',
|
2020-07-19 20:41:14 +12:00
|
|
|
label: i18n('fields.filters.artist'),
|
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'),
|
2019-09-05 15:36:11 +12:00
|
|
|
},
|
|
|
|
|
{
|
2020-11-08 20:49:48 +13:00
|
|
|
value: 'tracks',
|
2020-07-19 20:41:14 +12:00
|
|
|
label: i18n('fields.filters.tracks'),
|
2019-09-05 15:36:11 +12:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
value: 'uri',
|
2020-07-19 20:41:14 +12:00
|
|
|
label: i18n('fields.filters.source'),
|
2019-09-05 15:36:11 +12:00
|
|
|
},
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
const options = (
|
2020-11-08 20:49:48 +13:00
|
|
|
<>
|
2019-09-05 15:36:11 +12:00
|
|
|
<FilterField
|
2020-09-05 11:49:28 +12:00
|
|
|
initialValue={filter}
|
|
|
|
|
handleChange={(value) => this.setState({ filter: value, limit: per_page })}
|
2020-09-07 21:04:28 +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-05 11:49:28 +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-05 11:49:28 +12:00
|
|
|
selected_icon={sort ? (sort_reverse ? 'keyboard_arrow_up' : 'keyboard_arrow_down') : null}
|
2020-09-07 21:04:28 +12:00
|
|
|
handleChange={(val) => { this.setSort(val); 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')}
|
2020-09-05 11:49:28 +12:00
|
|
|
value={view}
|
2019-10-13 09:29:41 +13:00
|
|
|
valueAsLabel
|
2019-09-05 15:36:11 +12:00
|
|
|
options={view_options}
|
2020-09-07 21:04:28 +12:00
|
|
|
handleChange={(val) => { uiActions.set({ library_albums_view: val }); 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')}
|
2020-09-05 11:49:28 +12:00
|
|
|
value={source}
|
2019-10-13 09:29:41 +13:00
|
|
|
valueAsLabel
|
2019-09-05 15:36:11 +12:00
|
|
|
options={source_options}
|
2020-09-07 21:04:28 +12:00
|
|
|
handleChange={(val) => { uiActions.set({ library_albums_source: val }); uiActions.hideContextMenu(); }}
|
2019-09-05 15:36:11 +12:00
|
|
|
/>
|
2020-09-07 21:04:28 +12:00
|
|
|
<Button
|
|
|
|
|
noHover
|
2020-09-26 23:03:28 +12:00
|
|
|
discrete
|
2020-12-05 21:41:30 +13:00
|
|
|
onClick={loading_progress ? this.cancelRefresh : this.refresh}
|
2020-09-07 21:04:28 +12:00
|
|
|
tracking={{ category: 'LibraryAlbums', action: 'Refresh' }}
|
|
|
|
|
>
|
2020-12-05 21:41:30 +13:00
|
|
|
{loading_progress ? <Icon name="close" /> : <Icon name="refresh" /> }
|
|
|
|
|
{loading_progress ? <I18n path="actions.cancel" /> : <I18n path="actions.refresh" /> }
|
2020-09-07 21:04:28 +12:00
|
|
|
</Button>
|
2020-11-08 20:49:48 +13:00
|
|
|
</>
|
2019-09-05 15:36:11 +12:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div className="view library-albums-view">
|
2020-09-07 21:04:28 +12:00
|
|
|
<Header options={options} uiActions={uiActions}>
|
2019-09-05 15:36:11 +12:00
|
|
|
<Icon name="album" type="material" />
|
2020-07-19 20:41:14 +12:00
|
|
|
<I18n path="library.albums.title" />
|
2019-09-05 15:36:11 +12:00
|
|
|
</Header>
|
|
|
|
|
{this.renderView()}
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
2016-10-20 21:38:01 +13:00
|
|
|
}
|
|
|
|
|
|
2020-09-20 21:04:40 +12:00
|
|
|
const mapStateToProps = (state) => {
|
|
|
|
|
const source = state.ui.library_albums_source ? state.ui.library_albums_source : 'all';
|
|
|
|
|
|
2020-09-26 22:00:12 +12:00
|
|
|
const libraryUris = [];
|
|
|
|
|
if (source === 'all' || source === 'local') libraryUris.push('mopidy:library:albums');
|
|
|
|
|
if (source === 'all' || source === 'spotify') libraryUris.push('spotify:library:albums');
|
|
|
|
|
if (source === 'all' || source === 'google') libraryUris.push('google:library:albums');
|
|
|
|
|
const librarySelector = makeLibrarySelector(libraryUris);
|
2020-10-23 23:11:24 +13:00
|
|
|
const processProgressSelector = makeProcessProgressSelector(processKeys);
|
2020-09-20 21:04:40 +12:00
|
|
|
|
|
|
|
|
return {
|
2020-10-20 21:34:43 +13:00
|
|
|
loading_progress: processProgressSelector(state),
|
2020-09-25 06:54:19 +12:00
|
|
|
mopidy_uri_schemes: state.mopidy.uri_schemes,
|
2020-09-26 22:00:12 +12:00
|
|
|
albums: librarySelector(state),
|
2020-09-20 21:04:40 +12:00
|
|
|
google_available: (state.mopidy.uri_schemes && state.mopidy.uri_schemes.includes('gmusic:')),
|
|
|
|
|
spotify_available: state.spotify.access_token,
|
|
|
|
|
view: state.ui.library_albums_view,
|
|
|
|
|
source,
|
2020-09-25 06:54:19 +12:00
|
|
|
sort: state.ui.library_albums_sort,
|
|
|
|
|
sort_reverse: state.ui.library_albums_sort_reverse,
|
2020-09-20 21:04:40 +12:00
|
|
|
};
|
|
|
|
|
};
|
2019-09-05 15:36:11 +12:00
|
|
|
|
|
|
|
|
const mapDispatchToProps = (dispatch) => ({
|
|
|
|
|
coreActions: bindActionCreators(coreActions, dispatch),
|
|
|
|
|
uiActions: bindActionCreators(uiActions, dispatch),
|
|
|
|
|
mopidyActions: bindActionCreators(mopidyActions, dispatch),
|
|
|
|
|
googleActions: bindActionCreators(googleActions, dispatch),
|
|
|
|
|
spotifyActions: bindActionCreators(spotifyActions, dispatch),
|
|
|
|
|
});
|
|
|
|
|
|
2019-10-09 09:42:20 +13:00
|
|
|
export default connect(mapStateToProps, mapDispatchToProps)(LibraryAlbums);
|