Files
pawol.nu/components/teks/teks-kat.js
T

118 lines
3.8 KiB
JavaScript
Raw Normal View History

'use client'
2020-12-17 09:05:40 +01:00
import PropTypes from 'prop-types'
import {useRouter} from 'next/navigation'
2024-04-14 07:07:49 +04:00
import Image from 'next/image'
2020-12-17 09:05:40 +01:00
import {format} from 'date-fns'
import {fr} from 'date-fns/locale'
import Card from '@mui/material/Card'
import CardActionArea from '@mui/material/CardActionArea'
import CardContent from '@mui/material/CardContent'
import CardMedia from '@mui/material/CardMedia'
import Typography from '@mui/material/Typography'
import Box from '@mui/material/Box'
2024-10-21 09:55:57 +04:00
import Grid from '@mui/material/Grid2'
2022-01-19 07:06:26 +04:00
import ExplicitIcon from '@mui/icons-material/Explicit'
import {styled} from '@mui/material/styles'
2020-12-17 09:05:40 +01:00
2022-05-22 00:17:28 +04:00
import {getAlias} from '../../lib/utils/format'
2022-01-19 06:35:04 +04:00
const PREFIX = 'teks-kat'
2022-05-17 09:01:31 +04:00
const IMAGE_URL = process.env.NEXT_PUBLIC_API_URL_ROOT || 'http://localhost:1337'
2022-01-19 06:35:04 +04:00
const classes = {
root: `${PREFIX}-root`,
media: `${PREFIX}-media`
}
const StyledGrid = styled(Grid)({
[`& .${classes.root}`]: {
2020-12-17 09:05:40 +01:00
maxWidth: 345
},
2022-01-19 06:35:04 +04:00
[`& .${classes.media}`]: {
2020-12-17 09:05:40 +01:00
height: 240,
objectFit: 'contain'
}
})
2022-05-20 02:15:56 +04:00
const noImageUrl = 'https://place-hold.it/140x140?text=Indisponible'
2022-05-17 09:01:31 +04:00
2022-05-20 02:15:56 +04:00
export default function TeksKat({parole}) {
2020-12-17 09:05:40 +01:00
const router = useRouter()
2022-05-20 02:15:56 +04:00
const {attributes} = parole
2022-05-17 09:01:31 +04:00
const {titre, artistes, annee, couverture, publishedAt, slug} = attributes
const datPiblikasyon = format(new Date(publishedAt), 'P', {locale: fr})
2022-05-22 00:17:28 +04:00
const aliases = getAlias(artistes, attributes.prioriteArtistes)
2020-12-17 09:05:40 +01:00
const handleClick = slug => {
router.push(`/paroles/${slug}`)?.then(() => window.scrollTo(0, 0))
2020-12-17 09:05:40 +01:00
}
return (
<StyledGrid xs={12} sm={6} md={4}>
2020-12-17 09:05:40 +01:00
<Card className={classes.root}>
<CardActionArea onClick={() => handleClick(slug)}>
<CardMedia
className={classes.media}
component='img'
2022-05-17 09:01:31 +04:00
alt={titre}
2022-05-20 02:15:56 +04:00
image={couverture?.data?.attributes?.url ? `${IMAGE_URL}${couverture.data.attributes.url}` : noImageUrl}
2022-05-17 09:01:31 +04:00
title={titre}
2020-12-17 09:05:40 +01:00
/>
<CardContent>
<Box sx={{display: 'flex', alignItems: 'center'}}>
<Typography display='inline' style={{marginRight: 5}} variant='h6' component='h2'>
{titre}
</Typography>
2024-04-14 07:07:49 +04:00
{attributes.creativeCommons && (
<Box marginInline={1}>
<Image
width={24}
height={24}
title='Creative Commons'
alt='ccheart_red'
src='/images/cc/icons/ccheart_red.svg'
/>
</Box>
)}
{attributes.explicitLyrics && (
2023-07-26 08:06:27 +04:00
<ExplicitIcon style={{marginRight: 5}} color='error' fontSize='small' />
)}
</Box>
<Box sx={{textAlign: 'start'}}>
<Typography variant='body2' color='textSecondary' component='p'>
{aliases}
</Typography>
<Typography variant='body2' color='textSecondary' component='p'>
{annee}
</Typography>
<Typography sx={{fontStyle: 'italic'}} variant='caption'>
{attributes.user && (
<>
(<i>parole soumise par {attributes.user.username}</i>)
</>
)}
{attributes.userAdmin && !attributes.user && (
<>
(<i>parole soumise par {attributes.userAdmin}</i>)
</>
)}
</Typography>
<Typography align='center' style={{marginTop: '0.5em'}} variant='body1' color='textSecondary' component='p'>
Publiée le : {datPiblikasyon}
</Typography>
</Box>
2020-12-17 09:05:40 +01:00
</CardContent>
</CardActionArea>
</Card>
2022-01-19 06:35:04 +04:00
</StyledGrid>
2020-12-17 09:05:40 +01:00
)
}
TeksKat.propTypes = {
2022-05-20 02:15:56 +04:00
parole: PropTypes.object.isRequired
2020-12-17 09:05:40 +01:00
}