From 054a45246eb6c02fc4b5a63cd46bce21fc23b060 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20FAMIBELLE-PRONZOLA?= Date: Fri, 3 Jul 2026 13:48:47 +0400 Subject: [PATCH] feat: show translations as tabs instead of grid --- components/teks/teks.js | 127 +++++++++++++++++----------------------- 1 file changed, 55 insertions(+), 72 deletions(-) diff --git a/components/teks/teks.js b/components/teks/teks.js index 54dd5db..7ba498a 100644 --- a/components/teks/teks.js +++ b/components/teks/teks.js @@ -1,9 +1,10 @@ 'use client' -import {useEffect} from 'react' +import {useEffect, useState} from 'react' import PropTypes from 'prop-types' import Box from '@mui/material/Box' -import Grid from '@mui/material/Grid' +import Tabs from '@mui/material/Tabs' +import Tab from '@mui/material/Tab' import Typography from '@mui/material/Typography' import Tooltip from '@mui/material/Tooltip' import {useMediaQuery} from '@mui/material' @@ -78,54 +79,30 @@ const Root = styled('div')(( }, })) -const LANG_NAMES = {fr: 'Français', en: 'English', es: 'Español', de: 'Deutsch', it: 'Italiano'} - -const langToArray = parole => { - const langArray = [] - - if (parole && parole.traductions) { - const {francais, anglais, espagnol, allemand, italien} = parole.traductions - - if (anglais) { - langArray.push({title: 'English', lang: anglais}) - } - - if (francais) { - langArray.push({title: 'Français', lang: francais}) - } - - if (espagnol) { - langArray.push({title: 'Español', lang: espagnol}) - } - - if (allemand) { - langArray.push({title: 'Deutsch', lang: allemand}) - } - - if (italien) { - langArray.push({title: 'Italiano', lang: italien}) - } - } - - return langArray +const LANG_NAMES = { + fr: 'Français', en: 'English', es: 'Español', de: 'Deutsch', it: 'Italiano', + pt: 'Português', ja: '日本語', ko: '한국어', } -const alignTeks = (langArray, isMobile) => { - if (langArray.length > 0 && !isMobile) { - return 'justify' +const TRAD_FIELDS = [ + {field: 'anglais', title: 'English'}, + {field: 'francais', title: 'Français'}, + {field: 'espagnol', title: 'Español'}, + {field: 'allemand', title: 'Deutsch'}, + {field: 'italien', title: 'Italiano'}, + {field: 'portugais', title: 'Português'}, + {field: 'japonais', title: '日本語'}, + {field: 'coreen', title: '한국어'}, +] + +const langToArray = parole => { + if (!parole || !parole.traductions) { + return [] } - if (langArray.length > 0 && isMobile) { - return 'justify' - } - - if (langArray.length === 0 && isMobile) { - return 'justify' - } - - if (langArray.length === 0 && !isMobile) { - return 'center' - } + return TRAD_FIELDS + .filter(({field}) => parole.traductions[field]) + .map(({field, title}) => ({title, lang: parole.traductions[field]})) } const ExplicitTooltip = Tooltip @@ -135,6 +112,7 @@ export default function Teks({parole}) { const langArray = langToArray(parole) const enhancedAliases = getAlias(parole.artistes, parole.prioriteArtistes, true) const coverFmt = formatKuveti(parole.couverture) + const [tab, setTab] = useState(0) useEffect(() => { const isBrowser = () => typeof window !== 'undefined' @@ -231,35 +209,40 @@ export default function Teks({parole}) { )} - - 0 ? 6 : null}}> - - - Transcription - {parole.langueSource && parole.langueSource !== 'ka' && ( - - ({LANG_NAMES[parole.langueSource]}) - - )} - - + + setTab(value)} + variant='scrollable' + scrollButtons='auto' + centered={langArray.length === 0} + sx={{borderBottom: 1, borderColor: 'divider', mb: 2}} + > + + {langArray.map(({title}) => ( + + ))} + + {tab === 0 && ( + <> + {parole.langueSource && parole.langueSource !== 'ka' && ( + + ({LANG_NAMES[parole.langueSource]}) + + )} + {formatJsonString(parole.transcription)} - - - {langArray.map(({title, lang}) => ( - - - - {title} - - - {formatJsonString(lang)} - - - + + )} + {langArray.map(({title, lang}, index) => ( + tab === index + 1 && ( + + {formatJsonString(lang)} + + ) ))} - + ) }