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

257 lines
7.6 KiB
JavaScript
Raw Normal View History

'use client'
import {useEffect} from 'react'
import PropTypes from 'prop-types'
import Box from '@mui/material/Box'
import Grid from '@mui/material/Grid'
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'
2026-06-08 01:19:30 +04:00
import Image from 'next/image'
2022-05-22 00:17:28 +04:00
import {formatJsonString, getAlias} from '../../lib/utils/format'
2026-06-08 01:19:30 +04:00
import {formatKuveti} from '../../lib/kuveti'
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'
2026-06-08 01:19:30 +04:00
const IMAGE_URL = process.env.NEXT_PUBLIC_API_URL_ROOT || 'http://localhost:1337'
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',
},
}))
2026-06-12 14:14:29 +04:00
const LANG_NAMES = {fr: 'Français', en: 'English', es: 'Español', de: 'Deutsch', it: 'Italiano'}
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
2022-05-20 02:15:56 +04:00
if (anglais) {
2026-06-12 14:14:29 +04:00
langArray.push({title: 'English', lang: anglais})
}
2026-06-11 17:56:01 +04:00
if (francais) {
2026-06-12 14:14:29 +04:00
langArray.push({title: 'Français', lang: francais})
2026-06-11 17:56:01 +04:00
}
if (espagnol) {
2026-06-12 14:14:29 +04:00
langArray.push({title: 'Español', lang: espagnol})
}
2022-05-20 02:15:56 +04:00
if (allemand) {
2026-06-12 14:14:29 +04:00
langArray.push({title: 'Deutsch', lang: allemand})
}
2022-05-20 02:15:56 +04:00
if (italien) {
2026-06-12 14:14:29 +04:00
langArray.push({title: 'Italiano', 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)
2026-06-08 01:19:30 +04:00
const coverFmt = formatKuveti(parole.couverture)
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}>
<Box sx={{textAlign: 'center', marginTop: 12}}>
<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>
<Box display='flex' justifycontent='center' alignitems='center'>
2024-04-14 07:13:51 +04:00
<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-06-08 01:19:30 +04:00
{coverFmt?.url && (
<Box sx={{display: 'flex', justifyContent: 'center', mb: 2}}>
<Image
src={new URL(coverFmt.url, IMAGE_URL).toString()}
alt={parole.titre}
width={coverFmt.width || 300}
height={coverFmt.height || 300}
style={{maxWidth: '100%', maxHeight: 320, width: 'auto', height: 'auto', borderRadius: 8}}
/>
</Box>
)}
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'}}>
2026-06-12 14:14:29 +04:00
<LicenseModal license={parole.creativeCommons.toLowerCase()} sourceOriginale={parole.sourceOriginale ?? null} remixes={parole.remixes?.length ? parole.remixes : null} />
2024-04-14 07:08:24 +04:00
</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>
<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
2026-06-12 14:14:29 +04:00
{parole.langueSource && parole.langueSource !== 'ka' && (
<Typography component='span' variant='body2' color='text.secondary' sx={{ml: 1}}>
({LANG_NAMES[parole.langueSource]})
</Typography>
)}
</Typography>
<Typography paragraph='true' 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>
2026-06-12 14:14:29 +04:00
{langArray.map(({title, 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'>
2026-06-12 14:14:29 +04:00
{title}
</Typography>
<Typography paragraph='true' 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,
}