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

257 lines
7.2 KiB
JavaScript
Raw Normal View History

'use client'
import {useEffect} from 'react'
import PropTypes from 'prop-types'
import Box from '@mui/material/Box'
2024-10-21 09:55:57 +04:00
import Grid from '@mui/material/Grid2'
import Typography from '@mui/material/Typography'
import Tooltip from '@mui/material/Tooltip'
import {useMediaQuery} from '@mui/material'
2023-07-30 00:26:54 +04:00
import Link from 'next/link'
import slugify from 'slugify'
import {styled} from '@mui/material/styles'
import ExplicitIcon from '@mui/icons-material/Explicit'
2022-05-22 00:17:28 +04:00
import {formatJsonString, getAlias} from '../../lib/utils/format'
2024-04-14 07:06:31 +04:00
import LicenseModal from '../cc/license-modal'
2024-04-17 06:58:50 +04:00
import FilesDialog from '../files/files-dialog'
import EntegreMizik from './entegre-mizik'
import OkiMizik from './oki-mizik'
2022-12-12 22:31:05 +04:00
import DiferansDialog from './diferans-dialog'
const PREFIX = 'teks'
const classes = {
2023-07-22 13:56:18 +04:00
container: `${PREFIX}-container`,
tooltip: `${PREFIX}-tooltip`,
text: `${PREFIX}-text`,
gridText: `${PREFIX}-gridText`,
grid: `${PREFIX}-grid`,
koute: `${PREFIX}-koute`,
vwe: `${PREFIX}-vwe`,
2023-07-30 00:26:54 +04:00
pataje: `${PREFIX}-pataje`,
separation: `${PREFIX}-separation`
}
2023-07-30 00:26:54 +04:00
const Root = styled('div')((
{
theme
}
) => ({
2023-07-22 13:56:18 +04:00
[`&.${classes.container}`]: {
marginTop: '3em',
},
[`& .${classes.gridText}`]: {
border: '2px solid grey',
borderRadius: '5px',
marginTop: '2em',
padding: '1em'
},
[`& .${classes.pataje}`]: {
2023-07-22 13:56:18 +04:00
position: 'absolute',
zIndex: 9999
2023-07-22 23:39:16 +04:00
},
2023-07-30 00:26:54 +04:00
[`& .${classes.separation}`]: {
color: 'black',
2024-10-21 15:22:39 +04:00
...theme.applyStyles('dark', {
2023-07-30 00:26:54 +04:00
color: 'white'
2024-10-21 15:22:39 +04:00
})
2023-07-30 00:26:54 +04:00
},
2023-07-22 23:39:16 +04:00
'@media (max-width: 600px)': {
marginLeft: '0',
},
'@media (min-width: 600px)': {
marginLeft: '240px',
},
}))
2022-05-20 02:15:56 +04:00
const langToArray = parole => {
const langArray = []
2022-05-20 02:15:56 +04:00
if (parole && parole.traductions) {
const {francais, anglais, espagnol, allemand, italien} = parole.traductions
if (francais) {
langArray.push({title: 'Traduction', flag: 'fr', lang: francais})
}
2022-05-20 02:15:56 +04:00
if (anglais) {
langArray.push({title: 'Translation', flag: 'en', lang: anglais})
}
if (espagnol) {
langArray.push({title: 'Traducción', flag: 'es', lang: espagnol})
}
2022-05-20 02:15:56 +04:00
if (allemand) {
langArray.push({title: 'Übersetzung', flag: 'de', lang: allemand})
}
2022-05-20 02:15:56 +04:00
if (italien) {
langArray.push({title: 'Traduzione', flag: 'it', lang: italien})
}
}
return langArray
}
const alignTeks = (langArray, isMobile) => {
if (langArray.length > 0 && !isMobile) {
return 'justify'
}
if (langArray.length > 0 && isMobile) {
return 'justify'
}
if (langArray.length === 0 && isMobile) {
return 'justify'
}
if (langArray.length === 0 && !isMobile) {
return 'center'
}
}
const ExplicitTooltip = Tooltip
2023-07-22 13:56:18 +04:00
export default function Teks({parole}) {
const isMobile = useMediaQuery('(max-width:600px)')
2022-05-20 02:15:56 +04:00
const langArray = langToArray(parole)
2023-07-30 00:26:54 +04:00
const enhancedAliases = getAlias(parole.artistes, parole.prioriteArtistes, true)
2023-07-22 13:56:18 +04:00
useEffect(() => {
const isBrowser = () => typeof window !== 'undefined'
if (!isBrowser()) {
return
}
window.scrollTo({top: 0, behavior: 'smooth'})
}, [])
return (
2023-07-22 23:39:16 +04:00
<Root className={classes.container}>
2023-07-22 13:56:18 +04:00
<Box sx={{textAlign: 'center', marginTop: 1}}>
2022-12-12 23:17:59 +04:00
<Typography variant='h4' component='div' display='block' marginBottom={2}>
2023-07-30 00:26:54 +04:00
<Typography gutterBottom color='primary' variant='h6' component='div'>
{enhancedAliases.map(({type, value}) => {
if (type === 'element') {
return (
2024-01-23 04:38:02 +04:00
<Link key={value} style={{textDecoration: 'none', color: 'inherit'}} href={`/awtis/${slugify(value, {lower: true, remove: /[*#+~.()'"!:@]/g})}`}>{value}</Link>
2023-07-30 00:26:54 +04:00
)
}
return <span key={value} className={classes.separation}>{value}</span>
})}
</Typography>
2024-04-14 07:13:51 +04:00
<Box display='flex' justifyContent='center' alignItems='center'>
<Typography variant='h5' component='div'>
{parole.titre} <small>({parole?.annee})</small>
</Typography>
{parole.explicitLyrics && (
<ExplicitTooltip
title='Explicit Lyrics'
placement='bottom'
classes={{
tooltip: classes.tooltip
}}
>
2024-04-14 07:13:51 +04:00
<ExplicitIcon style={{marginLeft: 10}} color='error' />
</ExplicitTooltip>
)}
2024-04-14 07:13:51 +04:00
</Box>
</Typography>
2022-12-12 23:17:59 +04:00
2026-04-21 19:16:11 +04:00
{parole?.user && (
<Typography style={{marginBottom: '1.5em'}} display='block' variant='caption'>
2026-04-21 19:16:11 +04:00
<i>parole soumise par {parole.user.username}</i>
</Typography>
)}
2026-04-21 19:16:11 +04:00
{parole?.userAdmin&& !parole.user && (
2022-05-08 05:26:23 +04:00
<Typography style={{marginBottom: '1.5em'}} display='block' variant='caption'>
2026-04-21 19:16:11 +04:00
<i>parole soumise par {parole.userAdmin.firstname}</i>
2022-05-08 05:26:23 +04:00
</Typography>
)}
2024-04-14 07:08:24 +04:00
{parole.creativeCommons && (
<Box sx={{maxWidth: 220, margin: '0 auto', textAlign: 'center'}}>
<LicenseModal license={parole.creativeCommons.toLowerCase()} />
</Box>
)}
2026-04-21 19:16:11 +04:00
{parole?.files && (
<FilesDialog files={parole.files} />
2024-04-17 06:58:50 +04:00
)}
2023-03-09 10:39:44 +04:00
{(parole.okiMizikID || parole.streamAudio.length > 0 || parole.gadeEmbed) && (
2022-12-12 23:17:59 +04:00
<Box sx={{textAlign: 'center'}}>
<EntegreMizik parole={parole} isMobile={isMobile} />
</Box>
)}
{parole.okiMizikID && (
<OkiMizik id={parole.okiMizikID} parole={parole} />
)}
{parole?.difference?.length > 0 && (
<DiferansDialog difference={parole.difference} />
)}
</Box>
2023-07-22 23:39:16 +04:00
<Grid container justifyContent='center' spacing={1}>
2024-10-21 10:06:16 +04:00
<Grid size={{xs: 12, md: langArray.length > 0 ? 6 : null}}>
2023-07-22 13:56:18 +04:00
<Box className={classes.gridText}>
<Typography align='center' sx={{marginBottom: '0.5em'}} variant='h4'>
Transcription
</Typography>
<Typography paragraph align={alignTeks(langArray, isMobile)} component='span'>
2022-05-20 02:15:56 +04:00
{formatJsonString(parole.transcription)}
</Typography>
2023-07-22 13:56:18 +04:00
</Box>
</Grid>
{langArray.map(({title, flag, lang}) => (
2024-10-21 10:06:16 +04:00
<Grid key={title} size={{xs: 12, md: 6}}>
2023-07-22 13:56:18 +04:00
<Box className={classes.gridText}>
<Typography align='center' sx={{marginBottom: '0.5em'}} variant='h4'>
{flag === 'fr' && (
<span>
🇫🇷
</span>
)}
{flag === 'en' && (
<span>
🇬🇧
</span>
)}
{flag === 'es' && (
<span>
🇪🇸
</span>
2022-03-22 07:12:41 +04:00
)}
{flag === 'de' && (
<span>
🇩🇪
</span>
)}
{flag === 'it' && (
<span>
🇮🇹
</span>
)} {title}
</Typography>
<Typography paragraph align='justify' component='span'>
{formatJsonString(lang)}
</Typography>
2023-07-22 13:56:18 +04:00
</Box>
</Grid>
))}
</Grid>
</Root>
)
}
Teks.propTypes = {
2022-05-20 02:15:56 +04:00
parole: PropTypes.object.isRequired,
}