2020-02-07 12:38:01 -09:00
|
|
|
import React from 'react'
|
2020-02-07 08:36:26 -09:00
|
|
|
import { Loading, useGetOne } from 'react-admin'
|
|
|
|
|
import { Card, CardContent, CardMedia, Typography } from '@material-ui/core'
|
|
|
|
|
import { subsonicUrl } from '../subsonic'
|
|
|
|
|
|
2020-02-07 11:04:45 -09:00
|
|
|
const AlbumDetails = ({ id, classes }) => {
|
2020-02-07 08:36:26 -09:00
|
|
|
const { data, loading, error } = useGetOne('album', id)
|
|
|
|
|
|
|
|
|
|
if (loading) {
|
|
|
|
|
return <Loading />
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
|
return <p>ERROR: {error}</p>
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const genreYear = (data) => {
|
|
|
|
|
let genreDateLine = []
|
|
|
|
|
if (data.genre) {
|
|
|
|
|
genreDateLine.push(data.genre)
|
|
|
|
|
}
|
|
|
|
|
if (data.year) {
|
|
|
|
|
genreDateLine.push(data.year)
|
|
|
|
|
}
|
|
|
|
|
return genreDateLine.join(' - ')
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<Card className={classes.container}>
|
|
|
|
|
<CardMedia
|
2020-02-07 12:51:14 -09:00
|
|
|
image={subsonicUrl(
|
|
|
|
|
'getCoverArt',
|
|
|
|
|
data.coverArtId || 'not_found',
|
|
|
|
|
'size=500'
|
|
|
|
|
)}
|
2020-02-07 08:36:26 -09:00
|
|
|
className={classes.albumCover}
|
|
|
|
|
/>
|
|
|
|
|
<CardContent className={classes.albumDetails}>
|
|
|
|
|
<Typography variant="h5" className={classes.albumTitle}>
|
|
|
|
|
{data.name}
|
|
|
|
|
</Typography>
|
|
|
|
|
<Typography component="h6">
|
|
|
|
|
{data.albumArtist || data.artist}
|
|
|
|
|
</Typography>
|
2020-02-07 11:04:45 -09:00
|
|
|
<Typography component="p">{genreYear(data)}</Typography>
|
2020-02-07 08:36:26 -09:00
|
|
|
</CardContent>
|
|
|
|
|
</Card>
|
|
|
|
|
)
|
|
|
|
|
}
|
2020-02-07 11:04:45 -09:00
|
|
|
|
|
|
|
|
export default AlbumDetails
|