mirror of
https://github.com/navidrome/navidrome.git
synced 2025-04-14 11:17:19 +03:00
177 lines
4.4 KiB
JavaScript
177 lines
4.4 KiB
JavaScript
import React, { useMemo } from 'react'
|
|
import { useHistory } from 'react-router-dom'
|
|
import {
|
|
AutocompleteInput,
|
|
Datagrid,
|
|
DatagridBody,
|
|
DatagridRow,
|
|
Filter,
|
|
NumberField,
|
|
ReferenceInput,
|
|
SearchInput,
|
|
TextField,
|
|
useTranslate,
|
|
} from 'react-admin'
|
|
import { useMediaQuery, withWidth } from '@material-ui/core'
|
|
import FavoriteIcon from '@material-ui/icons/Favorite'
|
|
import FavoriteBorderIcon from '@material-ui/icons/FavoriteBorder'
|
|
import { makeStyles } from '@material-ui/core/styles'
|
|
import { useDrag } from 'react-dnd'
|
|
import { AddToPlaylistDialog } from '../dialogs'
|
|
import {
|
|
ArtistContextMenu,
|
|
List,
|
|
QuickFilter,
|
|
useGetHandleArtistClick,
|
|
ArtistSimpleList,
|
|
RatingField,
|
|
useSelectedFields,
|
|
useResourceRefresh,
|
|
} from '../common'
|
|
import config from '../config'
|
|
import ArtistListActions from './ArtistListActions'
|
|
|
|
const useStyles = makeStyles({
|
|
contextHeader: {
|
|
marginLeft: '3px',
|
|
marginTop: '-2px',
|
|
verticalAlign: 'text-top',
|
|
},
|
|
row: {
|
|
'&:hover': {
|
|
'& $contextMenu': {
|
|
visibility: 'visible',
|
|
},
|
|
'& $ratingField': {
|
|
visibility: 'visible',
|
|
},
|
|
},
|
|
},
|
|
contextMenu: {
|
|
visibility: 'hidden',
|
|
},
|
|
ratingField: {
|
|
visibility: 'hidden',
|
|
},
|
|
})
|
|
|
|
const ArtistFilter = (props) => {
|
|
const translate = useTranslate()
|
|
return (
|
|
<Filter {...props} variant={'outlined'}>
|
|
<SearchInput source="name" alwaysOn />
|
|
<ReferenceInput
|
|
label={translate('resources.artist.fields.genre')}
|
|
source="genre_id"
|
|
reference="genre"
|
|
perPage={0}
|
|
sort={{ field: 'name', order: 'ASC' }}
|
|
filterToQuery={(searchText) => ({ name: [searchText] })}
|
|
>
|
|
<AutocompleteInput emptyText="-- None --" />
|
|
</ReferenceInput>
|
|
{config.enableFavourites && (
|
|
<QuickFilter
|
|
source="starred"
|
|
label={<FavoriteIcon fontSize={'small'} />}
|
|
defaultValue={true}
|
|
/>
|
|
)}
|
|
</Filter>
|
|
)
|
|
}
|
|
|
|
const ArtistDatagridRow = (props) => {
|
|
const { record } = props
|
|
const [, dragArtistRef] = useDrag(() => ({
|
|
type: 'artist',
|
|
item: { artistIds: [record.id] },
|
|
options: { dropEffect: 'copy' },
|
|
}))
|
|
return <DatagridRow ref={dragArtistRef} {...props} />
|
|
}
|
|
|
|
const ArtistDatagridBody = (props) => (
|
|
<DatagridBody {...props} row={<ArtistDatagridRow />} />
|
|
)
|
|
|
|
const ArtistDatagrid = (props) => (
|
|
<Datagrid {...props} body={<ArtistDatagridBody />} />
|
|
)
|
|
|
|
const ArtistListView = ({ hasShow, hasEdit, hasList, width, ...rest }) => {
|
|
const classes = useStyles()
|
|
const handleArtistLink = useGetHandleArtistClick(width)
|
|
const history = useHistory()
|
|
const isXsmall = useMediaQuery((theme) => theme.breakpoints.down('xs'))
|
|
useResourceRefresh('artist')
|
|
|
|
const toggleableFields = useMemo(() => {
|
|
return {
|
|
albumCount: <NumberField source="albumCount" sortByOrder={'DESC'} />,
|
|
songCount: <NumberField source="songCount" sortByOrder={'DESC'} />,
|
|
playCount: <NumberField source="playCount" sortByOrder={'DESC'} />,
|
|
rating: config.enableStarRating && (
|
|
<RatingField
|
|
source="rating"
|
|
sortByOrder={'DESC'}
|
|
resource={'artist'}
|
|
className={classes.ratingField}
|
|
/>
|
|
),
|
|
}
|
|
}, [classes.ratingField])
|
|
|
|
const columns = useSelectedFields({
|
|
resource: 'artist',
|
|
columns: toggleableFields,
|
|
})
|
|
|
|
return isXsmall ? (
|
|
<ArtistSimpleList
|
|
linkType={(id) => history.push(handleArtistLink(id))}
|
|
{...rest}
|
|
/>
|
|
) : (
|
|
<ArtistDatagrid rowClick={handleArtistLink} classes={{ row: classes.row }}>
|
|
<TextField source="name" />
|
|
{columns}
|
|
<ArtistContextMenu
|
|
source={'starred'}
|
|
sortBy={'starred ASC, starredAt ASC'}
|
|
sortByOrder={'DESC'}
|
|
sortable={config.enableFavourites}
|
|
className={classes.contextMenu}
|
|
label={
|
|
config.enableFavourites && (
|
|
<FavoriteBorderIcon
|
|
fontSize={'small'}
|
|
className={classes.contextHeader}
|
|
/>
|
|
)
|
|
}
|
|
/>
|
|
</ArtistDatagrid>
|
|
)
|
|
}
|
|
|
|
const ArtistList = (props) => {
|
|
return (
|
|
<>
|
|
<List
|
|
{...props}
|
|
sort={{ field: 'name', order: 'ASC' }}
|
|
exporter={false}
|
|
bulkActionButtons={false}
|
|
filters={<ArtistFilter />}
|
|
actions={<ArtistListActions />}
|
|
>
|
|
<ArtistListView {...props} />
|
|
</List>
|
|
<AddToPlaylistDialog />
|
|
</>
|
|
)
|
|
}
|
|
|
|
export default withWidth()(ArtistList)
|