From 699e809568f9ead9be23f59cf1944523b3c7a4c9 Mon Sep 17 00:00:00 2001 From: James Barnsley Date: Fri, 19 Nov 2021 17:21:18 +1300 Subject: [PATCH] Using album_type for filtering type, fixes #788 --- src/js/views/Artist/Overview.js | 160 ++++++++++++++++++++++++++++++++ 1 file changed, 160 insertions(+) create mode 100644 src/js/views/Artist/Overview.js diff --git a/src/js/views/Artist/Overview.js b/src/js/views/Artist/Overview.js new file mode 100644 index 000000000..54196bb7b --- /dev/null +++ b/src/js/views/Artist/Overview.js @@ -0,0 +1,160 @@ +import React, { useState } from 'react'; +import { useDispatch, useSelector } from 'react-redux'; +import TrackList from '../../components/TrackList'; +import FilterField from '../../components/Fields/FilterField'; +import DropdownField from '../../components/Fields/DropdownField'; +import { Grid } from '../../components/Grid'; +import Button from '../../components/Button'; +import RelatedArtists from '../../components/RelatedArtists'; +import { i18n, I18n } from '../../locale'; +import { sortItems, applyFilter } from '../../util/arrays'; +import { encodeUri } from '../../util/format'; +import { getSortSelector } from '../../util/selectors'; +import { + hideContextMenu, + setSort, +} from '../../services/ui/actions'; + +const SORT_KEY = 'artist_albums'; + +export default ({ + artist, + albums: albumsProp, +}) => { + const dispatch = useDispatch(); + const [search, setSearch] = useState(''); + const [type, setType] = useState(''); + const [sortField, sortReverse] = useSelector( + (state) => getSortSelector(state, SORT_KEY, null), + ); + const { + uri, + tracks, + related_artists, + } = artist; + let albums = albumsProp; + + const onSortChange = (field) => { + let reverse = false; + if (field !== null && sortField === field) { + reverse = !sortReverse; + } + + dispatch(setSort(SORT_KEY, field, reverse)); + dispatch(hideContextMenu()); + } + + const onSubmit = () => { + dispatch(hideContextMenu()); + }; + + if (sortField && albums) { + albums = sortItems(albums, sortField, sortReverse); + } + + if (type && albums) { + albums = applyFilter('album_type', type, albums); + } + + if (search && search !== '') { + albums = applyFilter('name', search, albums); + } + + const sort_options = [ + { + value: null, + label: i18n('artist.albums.sort.default'), + }, + { + value: 'name', + label: i18n('artist.albums.sort.name'), + }, + { + value: 'release_date', + label: i18n('artist.albums.sort.release_date'), + }, + { + value: 'tracks', + label: i18n('artist.albums.sort.track_count'), + }, + ]; + + const filter_type_options = [ + { + value: null, + label: i18n('artist.albums.filter.all'), + }, + { + value: 'album', + label: i18n('artist.albums.filter.albums'), + }, + { + value: 'single', + label: i18n('artist.albums.filter.singles'), + }, + ]; + + return ( +
+
0 ? '70' : '100'}`}> + {tracks &&

} +
+ +
+
+ +
+ + {related_artists && related_artists.length > 0 && ( +
+

+
+ +
+ +
+ )} + +
+ +
+

+ +
+ + + +
+

+ +
+ +
+
+
+ ); +}