Skip to content

Commit

Permalink
Add album cover lightbox
Browse files Browse the repository at this point in the history
  • Loading branch information
deluan committed Aug 21, 2020
1 parent a45c08f commit 073e40d
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 1 deletion.
25 changes: 25 additions & 0 deletions ui/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"react-dom": "^16.13.1",
"react-drag-listview": "^0.1.7",
"react-ga": "^3.1.2",
"react-image-lightbox": "^5.1.1",
"react-jinke-music-player": "^4.16.5",
"react-measure": "^2.3.0",
"react-redux": "^7.2.1",
Expand Down
24 changes: 23 additions & 1 deletion ui/src/album/AlbumDetails.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import React from 'react'
import { Card, CardContent, CardMedia, Typography } from '@material-ui/core'
import { useTranslate } from 'react-admin'
import Lightbox from 'react-image-lightbox'
import 'react-image-lightbox/style.css'
import subsonic from '../subsonic'
import { DurationField, formatRange } from '../common'
import { ArtistLinkField } from '../common'

const AlbumDetails = ({ classes, record }) => {
const [isLightboxOpen, setLightboxOpen] = React.useState(false)
const translate = useTranslate()
const genreYear = (record) => {
let genreDateLine = []
Expand All @@ -19,11 +22,20 @@ const AlbumDetails = ({ classes, record }) => {
return genreDateLine.join(' · ')
}

const imageUrl = subsonic.url('getCoverArt', record.coverArtId || 'not_found')

const handleOpenLightbox = React.useCallback(() => setLightboxOpen(true), [])
const handleCloseLightbox = React.useCallback(
() => setLightboxOpen(false),
[]
)

return (
<Card className={classes.container}>
<CardMedia
image={subsonic.url('getCoverArt', record.coverArtId || 'not_found')}
image={imageUrl}
className={classes.albumCover}
onClick={handleOpenLightbox}
/>
<CardContent className={classes.albumDetails}>
<Typography variant="h5" className={classes.albumTitle}>
Expand All @@ -39,6 +51,16 @@ const AlbumDetails = ({ classes, record }) => {
· <DurationField record={record} source={'duration'} />
</Typography>
</CardContent>

{isLightboxOpen && (
<Lightbox
imagePadding={50}
animationDuration={200}
imageTitle={record.name}
mainSrc={imageUrl}
onCloseRequest={handleCloseLightbox}
/>
)}
</Card>
)
}
Expand Down
1 change: 1 addition & 0 deletions ui/src/album/styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export const useStyles = makeStyles((theme) => ({
},
albumCover: {
display: 'inline-block',
cursor: 'pointer',
[theme.breakpoints.down('xs')]: {
height: '8em',
width: '8em',
Expand Down

0 comments on commit 073e40d

Please sign in to comment.