diff --git a/ui/package-lock.json b/ui/package-lock.json index 0e05c0161..5840f29e2 100644 --- a/ui/package-lock.json +++ b/ui/package-lock.json @@ -10425,6 +10425,11 @@ "resolved": "https://registry.npmjs.org/lodash._reinterpolate/-/lodash._reinterpolate-3.0.0.tgz", "integrity": "sha1-DM8tiRZq8Ds2Y8eWU4t1rG4RTZ0=" }, + "lodash.get": { + "version": "4.4.2", + "resolved": "https://registry.npmjs.org/lodash.get/-/lodash.get-4.4.2.tgz", + "integrity": "sha1-LRd/ZS+jHpObRDjVNBSZ36OCXpk=" + }, "lodash.memoize": { "version": "4.1.2", "resolved": "https://registry.npmjs.org/lodash.memoize/-/lodash.memoize-4.1.2.tgz", diff --git a/ui/package.json b/ui/package.json index f4616ae24..fdb1a4003 100644 --- a/ui/package.json +++ b/ui/package.json @@ -6,6 +6,7 @@ "@material-ui/lab": "^4.0.0-alpha.54", "deepmerge": "^4.2.2", "jwt-decode": "^2.2.0", + "lodash.get": "^4.4.2", "lodash.throttle": "^4.1.1", "md5-hex": "^3.0.1", "prop-types": "^15.7.2", diff --git a/ui/src/album/AlbumGridView.js b/ui/src/album/AlbumGridView.js index 91d4c10af..e5fdc6d9d 100644 --- a/ui/src/album/AlbumGridView.js +++ b/ui/src/album/AlbumGridView.js @@ -1,5 +1,4 @@ import React, { useState } from 'react' -import { useLocation } from 'react-router-dom' import { GridList, GridListTile, @@ -9,7 +8,7 @@ import { import { makeStyles } from '@material-ui/core/styles' import withWidth from '@material-ui/core/withWidth' import { Link } from 'react-router-dom' -import { linkToRecord, Loading, useListParams } from 'react-admin' +import { linkToRecord, Loading } from 'react-admin' import { withContentRect } from 'react-measure' import subsonic from '../subsonic' import { ArtistLinkField } from '../common' @@ -112,16 +111,8 @@ const AlbumGridTile = ({ showArtist, record, basePath }) => { ) } -const LoadedAlbumGrid = ({ ids, data, basePath, width, resource }) => { +const LoadedAlbumGrid = ({ ids, data, basePath, width, isArtistView }) => { const classes = useStyles() - const location = useLocation() - - const [listParams] = useListParams({ - resource, - location, - }) - - const isArtistView = !!(listParams.filter && listParams.filter.artist_id) return (
diff --git a/ui/src/album/AlbumList.js b/ui/src/album/AlbumList.js index 29eee4603..bd43e985b 100644 --- a/ui/src/album/AlbumList.js +++ b/ui/src/album/AlbumList.js @@ -1,5 +1,6 @@ import React from 'react' import { useSelector } from 'react-redux' +import { useLocation } from 'react-router-dom' import { AutocompleteInput, Filter, @@ -9,8 +10,9 @@ import { SearchInput, Pagination, useTranslate, + useListParams, } from 'react-admin' -import { List } from '../common' +import { List, useAlbumsPerPage } from '../common' import { withWidth } from '@material-ui/core' import AlbumListActions from './AlbumListActions' import AlbumListView from './AlbumListView' @@ -38,25 +40,19 @@ const AlbumFilter = (props) => { ) } -const getPerPage = (width) => { - if (width === 'xs') return 12 - if (width === 'sm') return 12 - if (width === 'md') return 15 - if (width === 'lg') return 18 - return 21 -} - -const getPerPageOptions = (width) => { - const options = [3, 6, 12] - if (width === 'xs') return [12] - if (width === 'sm') return [12] - if (width === 'md') return options.map((v) => v * 4) - return options.map((v) => v * 6) -} - const AlbumList = (props) => { - const { width } = props + const { width, resource } = props const albumView = useSelector((state) => state.albumView) + const [perPage, perPageOptions] = useAlbumsPerPage(width) + const location = useLocation() + + const [query] = useListParams({ + resource, + location, + perPage, + }) + const isArtistView = !!(query.filter && query.filter.artist_id) + return ( <> { actions={} sort={{ field: 'created_at', order: 'DESC' }} filters={} - perPage={getPerPage(width)} - pagination={ - - } + perPage={perPage} + pagination={} > {albumView.mode === ALBUM_MODE_LIST ? ( ) : ( - + )} diff --git a/ui/src/artist/ArtistList.js b/ui/src/artist/ArtistList.js index c88811777..1b5ee4afb 100644 --- a/ui/src/artist/ArtistList.js +++ b/ui/src/artist/ArtistList.js @@ -6,7 +6,8 @@ import { SearchInput, TextField, } from 'react-admin' -import { artistLink, List } from '../common' +import { List, useGetHandleArtistClick } from '../common' +import { withWidth } from '@material-ui/core' const ArtistFilter = (props) => ( @@ -14,20 +15,23 @@ const ArtistFilter = (props) => ( ) -const ArtistList = (props) => ( - } - > - - - - - - -) +const ArtistList = ({ width, ...props }) => { + const handleArtistLink = useGetHandleArtistClick(width) + return ( + } + > + + + + + + + ) +} -export default ArtistList +export default withWidth()(ArtistList) diff --git a/ui/src/common/ArtistLinkField.js b/ui/src/common/ArtistLinkField.js index bdba17124..5f9d4e81e 100644 --- a/ui/src/common/ArtistLinkField.js +++ b/ui/src/common/ArtistLinkField.js @@ -1,12 +1,19 @@ import React from 'react' import PropTypes from 'prop-types' import { Link } from 'react-admin' +import { useAlbumsPerPage } from './index' +import { withWidth } from '@material-ui/core' -const artistLink = (id) => { - return `/album?filter={"artist_id":"${id}"}&order=ASC&sort=maxYear&displayedFilters={"compilation":true}` +const useGetHandleArtistClick = (width) => { + const [perPage] = useAlbumsPerPage(width) + + return (id) => { + return `/album?filter={"artist_id":"${id}"}&order=ASC&sort=maxYear&displayedFilters={"compilation":true}&perPage=${perPage}` + } } -const ArtistLinkField = ({ record, className }) => { +const ArtistLinkField = ({ record, className, width }) => { + const artistLink = useGetHandleArtistClick(width) return ( { + if (width === 'xs') return 12 + if (width === 'sm') return 12 + if (width === 'md') return 15 + if (width === 'lg') return 18 + return 21 +} + +const getPerPageOptions = (width) => { + const options = [3, 6, 12] + if (width === 'xs') return [12] + if (width === 'sm') return [12] + if (width === 'md') return options.map((v) => v * 4) + return options.map((v) => v * 6) +} + +const useAlbumPerPage = (width) => { + const perPage = + useSelector((state) => + get(state.admin.resources, ['album', 'list', 'params', 'perPage']) + ) || getPerPage(width) + + return [perPage, getPerPageOptions(width)] +} + +export default useAlbumPerPage