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 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,
|
2021-03-05 23:10:41 +13:00
|
|
|
getLibrarySource,
|
2021-04-22 21:16:21 +12:00
|
|
|
makeProvidersSelector,
|
2021-08-08 14:21:28 +12:00
|
|
|
getSortSelector,
|
2020-09-22 06:59:15 +12:00
|
|
|
} from '../../util/selectors';
|
2021-12-01 20:49:50 +13:00
|
|
|
import { formatSimpleObject } from '../../util/format';
|
2016-10-20 21:38:01 +13:00
|
|
|
|
2021-08-08 14:21:28 +12:00
|
|
|
const SORT_KEY = 'library_albums';
|
2020-10-23 23:11:24 +13:00
|
|
|
const processKeys = [
|
|
|
|
|
'MOPIDY_GET_LIBRARY_ALBUMS',
|
|
|
|
|
'SPOTIFY_GET_LIBRARY_ALBUMS',
|
|
|
|
|
];
|
|
|
|
|
|
2021-11-28 19:52:12 +13:00
|
|
|
class Albums 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'));
|
2021-04-17 22:08:49 +12:00
|
|
|
this.getLibraries();
|
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;
|
2019-09-05 15:36:11 +12:00
|
|
|
|
2020-08-12 08:06:24 +12:00
|
|
|
if (source !== prevSource) {
|
2021-04-17 22:08:49 +12:00
|
|
|
this.getLibraries();
|
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();
|
2021-04-17 22:08:49 +12:00
|
|
|
this.getLibraries(true);
|
2020-09-07 21:04:28 +12:00
|
|
|
}
|
|
|
|
|
|
2020-10-23 23:11:24 +13:00
|
|
|
cancelRefresh = () => {
|
|
|
|
|
const { uiActions: { hideContextMenu, cancelProcess } } = this.props;
|
|
|
|
|
|
|
|
|
|
hideContextMenu();
|
|
|
|
|
cancelProcess(processKeys);
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-17 22:08:49 +12:00
|
|
|
getLibraries = (forceRefetch = false) => {
|
2020-03-12 08:31:32 +13:00
|
|
|
const {
|
|
|
|
|
source,
|
2021-04-22 21:16:21 +12:00
|
|
|
providers,
|
2020-09-05 11:49:28 +12:00
|
|
|
coreActions: {
|
|
|
|
|
loadLibrary,
|
2020-08-12 08:06:24 +12:00
|
|
|
},
|
|
|
|
|
} = this.props;
|
|
|
|
|
|
2021-04-17 22:08:49 +12:00
|
|
|
let uris = [];
|
|
|
|
|
if (source === 'all') {
|
2021-04-22 21:16:21 +12:00
|
|
|
uris = providers.map((p) => p.uri);
|
2021-04-17 22:08:49 +12:00
|
|
|
} else {
|
|
|
|
|
uris.push(source);
|
|
|
|
|
}
|
|
|
|
|
uris.forEach((uri) => loadLibrary(uri, 'albums', { forceRefetch }));
|
2020-08-12 08:06:24 +12:00
|
|
|
};
|
2019-09-05 15:36:11 +12:00
|
|
|
|
2021-08-08 14:21:28 +12:00
|
|
|
onSortChange = (field) => {
|
2020-07-19 20:41:14 +12:00
|
|
|
const {
|
2021-08-08 14:21:28 +12:00
|
|
|
sortField,
|
|
|
|
|
sortReverse,
|
2020-07-19 20:41:14 +12:00
|
|
|
uiActions: {
|
2021-08-08 14:21:28 +12:00
|
|
|
setSort,
|
|
|
|
|
hideContextMenu,
|
2020-07-19 20:41:14 +12:00
|
|
|
},
|
|
|
|
|
} = this.props;
|
|
|
|
|
|
2019-09-05 15:36:11 +12:00
|
|
|
let reverse = false;
|
2021-08-08 14:21:28 +12:00
|
|
|
if (field !== null && sortField === field) {
|
|
|
|
|
reverse = !sortReverse;
|
|
|
|
|
}
|
2019-09-05 15:36:11 +12:00
|
|
|
|
2021-08-08 14:21:28 +12:00
|
|
|
setSort(SORT_KEY, field, reverse);
|
|
|
|
|
hideContextMenu();
|
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 {
|
2021-08-08 14:21:28 +12:00
|
|
|
sortField,
|
|
|
|
|
sortReverse,
|
2020-09-05 11:49:28 +12:00
|
|
|
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
|
|
|
}
|
|
|
|
|
|
2021-08-08 14:21:28 +12:00
|
|
|
if (sortField) {
|
|
|
|
|
albums = sortItems(albums, sortField, sortReverse);
|
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-09 20:31:01 +13:00
|
|
|
details={['artists', 'tracks', 'followers']}
|
|
|
|
|
right_column={['source']}
|
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
|
|
|
}
|
|
|
|
|
|
2021-04-17 22:08:49 +12:00
|
|
|
render = () => {
|
|
|
|
|
const {
|
|
|
|
|
view,
|
|
|
|
|
source,
|
2021-04-22 21:16:21 +12:00
|
|
|
providers,
|
2021-08-08 14:21:28 +12:00
|
|
|
sortField,
|
|
|
|
|
sortReverse,
|
2021-04-17 22:08:49 +12:00
|
|
|
uiActions,
|
|
|
|
|
loading_progress,
|
|
|
|
|
} = this.props;
|
|
|
|
|
const {
|
|
|
|
|
filter,
|
|
|
|
|
per_page,
|
|
|
|
|
} = this.state;
|
|
|
|
|
|
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
|
|
|
},
|
2026-06-29 12:23:10 -04:00
|
|
|
{
|
|
|
|
|
value: 'release_date',
|
|
|
|
|
label: i18n('fields.filters.date'),
|
|
|
|
|
},
|
2026-06-29 14:54:38 -04:00
|
|
|
{
|
|
|
|
|
value: 'added_at',
|
|
|
|
|
label: i18n('fields.filters.added'),
|
|
|
|
|
},
|
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')}
|
2021-08-08 14:21:28 +12:00
|
|
|
value={sortField}
|
2019-10-13 09:29:41 +13:00
|
|
|
valueAsLabel
|
2019-09-05 15:36:11 +12:00
|
|
|
options={sort_options}
|
2021-08-08 14:21:28 +12:00
|
|
|
selected_icon={sortField ? (sortReverse ? 'keyboard_arrow_up' : 'keyboard_arrow_down') : null}
|
|
|
|
|
handleChange={this.onSortChange}
|
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
|
2021-04-22 21:16:21 +12:00
|
|
|
options={[
|
|
|
|
|
{
|
|
|
|
|
value: 'all',
|
|
|
|
|
label: i18n('fields.filters.all'),
|
|
|
|
|
},
|
|
|
|
|
...providers.map((p) => ({ value: p.uri, label: p.title })),
|
|
|
|
|
]}
|
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
|
|
|
}
|
|
|
|
|
|
2021-03-05 23:10:41 +13:00
|
|
|
const librarySelector = makeLibrarySelector('albums');
|
|
|
|
|
const processProgressSelector = makeProcessProgressSelector(processKeys);
|
2021-04-22 21:16:21 +12:00
|
|
|
const providersSelector = makeProvidersSelector('albums');
|
2021-08-08 14:21:28 +12:00
|
|
|
const mapStateToProps = (state) => {
|
|
|
|
|
const [sortField, sortReverse] = getSortSelector(state, SORT_KEY, null);
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
loading_progress: processProgressSelector(state),
|
|
|
|
|
uri_schemes: state.mopidy.uri_schemes,
|
|
|
|
|
albums: librarySelector(state, 'albums'),
|
|
|
|
|
providers: providersSelector(state),
|
|
|
|
|
view: state.ui.library_albums_view,
|
|
|
|
|
source: getLibrarySource(state, 'albums'),
|
|
|
|
|
sortField,
|
|
|
|
|
sortReverse,
|
|
|
|
|
};
|
|
|
|
|
};
|
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),
|
|
|
|
|
});
|
|
|
|
|
|
2021-11-28 19:52:12 +13:00
|
|
|
export default connect(mapStateToProps, mapDispatchToProps)(Albums);
|