Skip to content

Commit

Permalink
Add Links to external sites
Browse files Browse the repository at this point in the history
  • Loading branch information
deluan committed Jul 20, 2021
1 parent 21cd50d commit 58ee4c6
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 5 deletions.
69 changes: 65 additions & 4 deletions ui/src/album/AlbumDetails.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
CardContent,
CardMedia,
Collapse,
IconButton,
makeStyles,
Typography,
useMediaQuery,
Expand All @@ -29,6 +30,9 @@ import {
} from '../common'
import config from '../config'
import { intersperse } from '../utils'
import Link from '@material-ui/core/Link'
import MusicBrainz from '../icons/MusicBrainz'
import { ImLastfm2 } from 'react-icons/im'

const useStyles = makeStyles(
(theme) => ({
Expand Down Expand Up @@ -93,7 +97,10 @@ const useStyles = makeStyles(
recordArtist: {},
recordMeta: {},
genreList: {
marginTop: theme.spacing(1),
marginTop: theme.spacing(0.5),
},
links: {
marginTop: theme.spacing(1.5),
},
}),
{
Expand Down Expand Up @@ -174,6 +181,51 @@ const Details = (props) => {
return <>{intersperse(details, ' · ')}</>
}

const Links = (props) => {
const classes = useStyles()
const translate = useTranslate()
const record = useRecordContext(props)
let links = []
const addLink = (obj) => {
const id = links.length
links.push(<span key={`link-${record.id}-${id}`}>{obj}</span>)
}

addLink(
<Link
href={`https://last.fm/music/${
encodeURIComponent(record.albumArtist) +
'/' +
encodeURIComponent(record.name)
}`}
target="_blank"
rel="noopener noreferrer"
>
<IconButton size={'small'} title={translate('message.openIn.lastfm')}>
<ImLastfm2 />
</IconButton>
</Link>
)

record.mbzAlbumId &&
addLink(
<Link
href={`https://musicbrainz.org/release/${record.mbzAlbumId}`}
target="_blank"
rel="noopener noreferrer"
>
<IconButton
size={'small'}
title={translate('message.openIn.musicbrainz')}
>
<MusicBrainz />
</IconButton>
</Link>
)

return <div className={classes.links}>{intersperse(links, ' ')}</div>
}

const AlbumDetails = (props) => {
const record = useRecordContext(props)
const isDesktop = useMediaQuery((theme) => theme.breakpoints.up('lg'))
Expand Down Expand Up @@ -220,10 +272,10 @@ const AlbumDetails = (props) => {
/>
)}
</Typography>
<Typography component="h6" className={classes.recordArtist}>
<Typography component={'h6'} className={classes.recordArtist}>
<ArtistLinkField record={record} />
</Typography>
<Typography component="p" className={classes.recordMeta}>
<Typography component={'p'} className={classes.recordMeta}>
<Details />
</Typography>
{config.enableStarRating && (
Expand All @@ -235,7 +287,16 @@ const AlbumDetails = (props) => {
/>
</div>
)}
<GenreList />
{isDesktop ? (
<GenreList />
) : (
<Typography component={'p'}>{record.genre}</Typography>
)}
{isDesktop && (
<Typography component={'p'} className={classes.recordMeta}>
<Links />
</Typography>
)}
{isDesktop && record['comment'] && <AlbumComment record={record} />}
</CardContent>
</div>
Expand Down
6 changes: 5 additions & 1 deletion ui/src/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,11 @@
"lastfmLinkSuccess": "Last.fm successfully linked and scrobbling enabled",
"lastfmLinkFailure": "Last.fm could not be linked",
"lastfmUnlinkSuccess": "Last.fm unlinked and scrobbling disabled",
"lastfmUnlinkFailure": "Last.fm could not unlinked"
"lastfmUnlinkFailure": "Last.fm could not unlinked",
"openIn": {
"lastfm": "Open in Last.fm",
"musicbrainz": "Open in MusicBrainz"
}
},
"menu": {
"library": "Library",
Expand Down
12 changes: 12 additions & 0 deletions ui/src/icons/MusicBrainz.js

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

0 comments on commit 58ee4c6

Please sign in to comment.