diff --git a/components/teks/teks-drawer.js b/components/teks/teks-drawer.js index b3a2397..f20656f 100644 --- a/components/teks/teks-drawer.js +++ b/components/teks/teks-drawer.js @@ -1,48 +1,31 @@ -import {useEffect, useState, forwardRef} from 'react' +import {useEffect, useState} from 'react' import PropTypes from 'prop-types' import Link from 'next/link' -import {useSession} from 'next-auth/client' import { - Grid, Toolbar, Typography, AppBar, CssBaseline, Drawer, Hidden, - IconButton, - Box, - useMediaQuery, - Snackbar, - Tooltip, - Zoom + IconButton } from '@mui/material' import KeyboardBackspaceIcon from '@mui/icons-material/KeyboardBackspace' -import ExplicitIcon from '@mui/icons-material/Explicit' import MenuIcon from '@mui/icons-material/Menu' import {useTheme, styled} from '@mui/material/styles' -import MuiAlert from '@mui/material/Alert' -import {formatJsonString} from '../../lib/utils/format' - -import VweKomante from '../komante/vwe-komante' -import Dekoneksyon from '../sesyon/dekoneksyon' - import DrawerBar from './drawer-bar' import DenyeTeks from './denye-teks' import VweKouteAchte from './vwe-koute-achte' -import OkiMizik from './oki-mizik' -import Pataje from './pataje' -import EntegreMizik from './entegre-mizik' +import Teks from './teks' const PREFIX = 'teks-drawer' const classes = { - tooltip: `${PREFIX}-tooltip`, root: `${PREFIX}-root`, drawer: `${PREFIX}-drawer`, appBar: `${PREFIX}-appBar`, @@ -52,12 +35,10 @@ const classes = { content: `${PREFIX}-content`, list: `${PREFIX}-list`, form: `${PREFIX}-form`, - text: `${PREFIX}-text`, gridText: `${PREFIX}-gridText`, grid: `${PREFIX}-grid`, koute: `${PREFIX}-koute`, - vwe: `${PREFIX}-vwe`, - pataje: `${PREFIX}-pataje` + vwe: `${PREFIX}-vwe` } const Root = styled('div')(( @@ -114,21 +95,6 @@ const Root = styled('div')(( marginLeft: theme.spacing(1) }, - [`& .${classes.text}`]: { - marginBottom: '0.5em' - }, - - [`& .${classes.gridText}`]: { - border: '2px solid grey', - borderRadius: '5px', - marginTop: '2em', - padding: '1em' - }, - - [`& .${classes.grid}`]: { - marginTop: '1em' - }, - [`& .${classes.koute}`]: { position: 'absolute', right: '40px', @@ -145,74 +111,12 @@ const Root = styled('div')(( [theme.breakpoints.up('sm')]: { top: '10px' } - }, - - [`& .${classes.pataje}`]: { - position: 'fixed', - top: '59px', - left: '110px', - zIndex: 2, - [theme.breakpoints.up('sm')]: { - top: '62px', - left: '340px' - } } })) -const Alert = forwardRef(function Alert(props, ref) { - return -}) - const drawerWidth = 240 -const langToArray = anTeks => { - const langArray = [] - - if (anTeks && anTeks.tradiksyon) { - const {francais, english, espagnol} = anTeks.tradiksyon - - if (francais) { - langArray.push({title: 'Traduction', flag: 'fr', lang: francais}) - } - - if (english) { - langArray.push({title: 'Translation', flag: 'en', lang: english}) - } - - if (espagnol) { - langArray.push({title: 'Traducción', flag: 'es', lang: espagnol}) - } - } - - 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 - export default function TeksDrawer({teks, anTeks, komante}) { - const [session] = useSession() - - const isMobile = useMediaQuery('(max-width:800px)') - const langArray = langToArray(anTeks) - const theme = useTheme() const [esMobilOuve, meteEsMobilOuve] = useState(false) const [open, setOpen] = useState(false) @@ -313,106 +217,16 @@ export default function TeksDrawer({teks, anTeks, komante}) { {anTeks ? ( - <> - - - - - - - {anTeks.awtis.map(a => a.alias).join(', ')} - - - {anTeks.tit} - {anTeks.eksplisit && ( - - - - )} - - - {komante && ( - - )} - {session && ( - - )} - - - {anTeks.user && ( - - texte soumis par {anTeks.user.username} - - )} - - {(anTeks.okiMizikID || anTeks.kouteyAchtey.length > 0) && ( - - - - )} - {anTeks.okiMizikID && ( - - )} - - 0 ? 6 : null}> - - - Transcription - - - {formatJsonString(anTeks.transkripsyon)} - - - - {langArray.map(({title, flag, lang}) => ( - - - - {flag === 'fr' && ( - - 🇫🇷 - - )} - {flag === 'en' && ( - - 🇬🇧 - - )} - {flag === 'es' && ( - - 🇪🇸 - - )} {title} - - - {formatJsonString(lang)} - - - - ))} - - {success && ( - - - {success} - - - )} - {error && ( - - - Une erreur s’est produite : {error.message} - - - )} - > + ) : ( )} diff --git a/components/teks/teks.js b/components/teks/teks.js new file mode 100644 index 0000000..2fa8565 --- /dev/null +++ b/components/teks/teks.js @@ -0,0 +1,241 @@ +import {forwardRef} from 'react' +import PropTypes from 'prop-types' +import { + Box, + Grid, + Snackbar, + Typography, + Tooltip, + Zoom, + useMediaQuery +} from '@mui/material' +import {styled} from '@mui/material/styles' +import MuiAlert from '@mui/material/Alert' +import ExplicitIcon from '@mui/icons-material/Explicit' +import {useSession} from 'next-auth/client' + +import {formatJsonString} from '../../lib/utils/format' + +import VweKomante from '../komante/vwe-komante' +import Dekoneksyon from '../sesyon/dekoneksyon' + +import EntegreMizik from './entegre-mizik' +import OkiMizik from './oki-mizik' +import Pataje from './pataje' + +const PREFIX = 'teks' + +const classes = { + root: `${PREFIX}-root`, + tooltip: `${PREFIX}-tooltip`, + text: `${PREFIX}-text`, + gridText: `${PREFIX}-gridText`, + grid: `${PREFIX}-grid`, + koute: `${PREFIX}-koute`, + vwe: `${PREFIX}-vwe`, + pataje: `${PREFIX}-pataje` +} + +const Root = styled('div')(( + { + theme + } +) => ({ + [`& .${classes.text}`]: { + marginBottom: '0.5em' + }, + + [`& .${classes.gridText}`]: { + border: '2px solid grey', + borderRadius: '5px', + marginTop: '2em', + padding: '1em' + }, + + [`& .${classes.grid}`]: { + marginTop: '1em' + }, + + [`& .${classes.pataje}`]: { + position: 'fixed', + top: '59px', + left: '110px', + zIndex: 2, + [theme.breakpoints.up('sm')]: { + top: '62px', + left: '340px' + } + } +})) + +const langToArray = anTeks => { + const langArray = [] + + if (anTeks && anTeks.tradiksyon) { + const {francais, english, espagnol} = anTeks.tradiksyon + + if (francais) { + langArray.push({title: 'Traduction', flag: 'fr', lang: francais}) + } + + if (english) { + langArray.push({title: 'Translation', flag: 'en', lang: english}) + } + + if (espagnol) { + langArray.push({title: 'Traducción', flag: 'es', lang: espagnol}) + } + } + + 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 Alert = forwardRef(function Alert(props, ref) { + return +}) + +const ExplicitTooltip = Tooltip + +export default function Teks({anTeks, komante, open, success, error, setSuccess, setError, handleClose}) { + const isMobile = useMediaQuery('(max-width:800px)') + const [session] = useSession() + const langArray = langToArray(anTeks) + + return ( + + + + + + + + {anTeks.awtis.map(a => a.alias).join(', ')} + + + {anTeks.tit} + {anTeks.eksplisit && ( + + + + )} + + + {komante && ( + + )} + {session && ( + + )} + + + {anTeks.user && ( + + texte soumis par {anTeks.user.username} + + )} + + {(anTeks.okiMizikID || anTeks.kouteyAchtey.length > 0) && ( + + + + )} + {anTeks.okiMizikID && ( + + )} + + 0 ? 6 : null}> + + + Transcription + + + {formatJsonString(anTeks.transkripsyon)} + + + + {langArray.map(({title, flag, lang}) => ( + + + + {flag === 'fr' && ( + + 🇫🇷 + + )} + {flag === 'en' && ( + + 🇬🇧 + + )} + {flag === 'es' && ( + + 🇪🇸 + + )} {title} + + + {formatJsonString(lang)} + + + + ))} + + {success && ( + + + {success} + + + )} + {error && ( + + + Une erreur s’est produite : {error.message} + + + )} + + ) +} + +Teks.propTypes = { + anTeks: PropTypes.object.isRequired, + komante: PropTypes.array, + open: PropTypes.bool.isRequired, + success: PropTypes.string, + error: PropTypes.string, + setSuccess: PropTypes.func.isRequired, + setError: PropTypes.func.isRequired, + handleClose: PropTypes.func.isRequired +} + +Teks.defaultProps = { + komante: null, + success: '', + error: '' +}