Change teks to parole

This commit is contained in:
Cédric FAMIBELLE-PRONZOLA
2022-05-20 02:15:56 +04:00
parent b8be0ccd97
commit 2aa9e63e14
13 changed files with 158 additions and 153 deletions
+33 -32
View File
@@ -1,6 +1,6 @@
import PropTypes from 'prop-types'
import {jwennTeksEpiSlug, jwennTeks, jwennKomanteEpiTeksId} from '../../lib/oki-api'
import {jwennTeks, jwennKomanteEpiTeksId} from '../../lib/oki-api'
import TeksDrawer from '../../components/teks/teks-drawer'
import HeadLayout from '../../components/head-layout'
@@ -8,41 +8,41 @@ import HeadLayout from '../../components/head-layout'
import Custom500 from '../500'
import Custom404 from '../404'
const jwennAwtis = awtis => {
const alias = awtis.map(({alias}) => alias)
const jwennAwtis = artiste => {
const alias = artiste.data.map(({attributes}) => attributes.alias)
return new Intl.ListFormat('fr').format(alias)
}
export default function SlugTeks({hasError, errorMessage, teks, anTeks, slug, komante}) {
export default function SlugTeks({hasError, errorMessage, paroles, parole, slug, commentaires}) {
if (hasError) {
console.log('⚠️ error :', errorMessage)
return <Custom500 />
}
if (!anTeks) {
if (!parole) {
return <Custom404 />
}
const awtis = anTeks.awtis.length === 1 ? anTeks.awtis[0].alias : jwennAwtis(anTeks.awtis)
const {kouveti} = anTeks
const artistes = parole.attributes.artistes.length === 1 ? parole.attributes.artistes[0].data.attributes.alias : jwennAwtis(parole.attributes.artistes)
const {couverture} = parole.attributes
const formatKouveti = () => {
if (!kouveti) {
if (!couverture) {
return null
}
if (kouveti && kouveti.formats && kouveti.formats.large) {
return kouveti.formats.large
if (couverture && couverture.formats && couverture.formats.large) {
return couverture.formats.large
}
if (kouveti && kouveti.formats && kouveti.formats.medium) {
return kouveti.formats.medium
if (couverture && couverture.formats && couverture.formats.medium) {
return couverture.formats.medium
}
if (kouveti && kouveti.formats && kouveti.formats.small) {
return kouveti.formats.small
if (couverture && couverture.formats && couverture.formats.small) {
return couverture.formats.small
}
return kouveti
return couverture
}
return (
@@ -51,25 +51,26 @@ export default function SlugTeks({hasError, errorMessage, teks, anTeks, slug, ko
imageWidth={formatKouveti() ? formatKouveti().width : null}
imageHeight={formatKouveti() ? formatKouveti().height : null}
imageMime={formatKouveti() ? formatKouveti().mime : null}
title={`${awtis} - ${anTeks.tit} | Paroles et Traductions`} tab={1} slug={`paroles/${slug}`}
title={`${artistes} - ${parole.attributes.titre} | Paroles et Traductions`} tab={1} slug={`paroles/${slug}`}
>
<TeksDrawer teks={teks} anTeks={anTeks} komante={komante} />
<TeksDrawer paroles={paroles} parole={parole.attributes} paroleId={parole.id} commentaires={commentaires} />
</HeadLayout>
)
}
export async function getServerSideProps({query}) {
const {slug} = query
let teks
let anTeks
let paroles
let parole
let hasError
let errorMessage
let komante
let commentaires
try {
teks = await jwennTeks()
anTeks = await jwennTeksEpiSlug(slug)
komante = await jwennKomanteEpiTeksId(anTeks?.id)
paroles = await jwennTeks()
parole = paroles.find(({attributes}) => attributes.slug === slug)
commentaires = paroles.map(({attributes}) => attributes.commentaires)
commentaires = await jwennKomanteEpiTeksId(parole?.id)
} catch (error) {
errorMessage = error
hasError = true
@@ -79,10 +80,10 @@ export async function getServerSideProps({query}) {
props: {
hasError: hasError || null,
errorMessage: errorMessage ? errorMessage.message : null,
teks: teks || null,
anTeks: anTeks || null,
paroles: paroles || null,
parole: parole || null,
slug,
komante: komante || null
commentaires: commentaires || null
}
}
}
@@ -90,16 +91,16 @@ export async function getServerSideProps({query}) {
SlugTeks.defaultProps = {
hasError: null,
errorMessage: null,
teks: null,
anTeks: null,
komante: null
paroles: null,
parole: null,
commentaires: null
}
SlugTeks.propTypes = {
hasError: PropTypes.bool,
errorMessage: PropTypes.string,
teks: PropTypes.array,
anTeks: PropTypes.object,
paroles: PropTypes.array,
parole: PropTypes.object,
slug: PropTypes.string.isRequired,
komante: PropTypes.array
commentaires: PropTypes.array
}