quintodrome/ui/src/artist/ArtistList.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

108 lines
2.6 KiB
JavaScript
Raw Normal View History

2020-11-18 19:33:34 -09:00
import React from 'react'
import { useHistory } from 'react-router-dom'
import {
Datagrid,
Filter,
NumberField,
SearchInput,
TextField,
} from 'react-admin'
2020-08-14 08:27:49 -08:00
import { useMediaQuery, withWidth } from '@material-ui/core'
import FavoriteIcon from '@material-ui/icons/Favorite'
import FavoriteBorderIcon from '@material-ui/icons/FavoriteBorder'
2021-02-03 15:08:03 -09:00
import { AddToPlaylistDialog } from '../dialogs'
2020-08-14 08:27:49 -08:00
import {
ArtistContextMenu,
List,
2020-08-14 09:19:32 -08:00
QuickFilter,
2020-08-14 08:27:49 -08:00
useGetHandleArtistClick,
ArtistSimpleList,
2020-08-14 08:27:49 -08:00
} from '../common'
import { makeStyles } from '@material-ui/core/styles'
import config from '../config'
const useStyles = makeStyles({
contextHeader: {
marginLeft: '3px',
marginTop: '-2px',
verticalAlign: 'text-top',
},
2020-11-18 19:33:34 -09:00
row: {
'&:hover': {
'& $contextMenu': {
visibility: 'visible',
},
},
},
contextMenu: {
visibility: 'hidden',
},
})
const ArtistFilter = (props) => (
<Filter {...props} variant={'outlined'}>
<SearchInput source="name" alwaysOn />
{config.enableFavourites && (
<QuickFilter
source="starred"
label={<FavoriteIcon fontSize={'small'} />}
defaultValue={true}
/>
)}
</Filter>
)
const ArtistListView = ({ hasShow, hasEdit, hasList, width, ...rest }) => {
const classes = useStyles()
2020-08-14 08:27:49 -08:00
const handleArtistLink = useGetHandleArtistClick(width)
const history = useHistory()
2020-08-14 08:27:49 -08:00
const isXsmall = useMediaQuery((theme) => theme.breakpoints.down('xs'))
return isXsmall ? (
<ArtistSimpleList
linkType={(id) => history.push(handleArtistLink(id))}
{...rest}
/>
) : (
2020-11-18 19:33:34 -09:00
<Datagrid rowClick={handleArtistLink} classes={{ row: classes.row }}>
<TextField source="name" />
<NumberField source="albumCount" sortByOrder={'DESC'} />
<NumberField source="songCount" sortByOrder={'DESC'} />
<NumberField source="playCount" sortByOrder={'DESC'} />
<ArtistContextMenu
source={'starred'}
sortBy={'starred ASC, starredAt ASC'}
sortByOrder={'DESC'}
sortable={config.enableFavourites}
2020-11-18 19:33:34 -09:00
className={classes.contextMenu}
label={
config.enableFavourites && (
<FavoriteBorderIcon
fontSize={'small'}
className={classes.contextHeader}
/>
)
}
/>
2020-11-18 19:33:34 -09:00
</Datagrid>
)
}
const ArtistList = (props) => {
2020-08-14 08:27:49 -08:00
return (
<>
<List
{...props}
2020-08-14 08:27:49 -08:00
sort={{ field: 'name', order: 'ASC' }}
exporter={false}
bulkActionButtons={false}
filters={<ArtistFilter />}
>
<ArtistListView {...props} />
2020-08-14 08:27:49 -08:00
</List>
<AddToPlaylistDialog />
</>
)
}
export default withWidth()(ArtistList)