Change teks to parole
This commit is contained in:
+33
-32
@@ -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
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ import HeadLayout from '../../components/head-layout'
|
||||
|
||||
import Custom500 from '../500'
|
||||
|
||||
export default function Teks({errorCode, errorMessage, teks, denyeTeks}) {
|
||||
export default function Teks({errorCode, errorMessage, paroles, denyeTeks}) {
|
||||
if (errorCode) {
|
||||
console.log('⚠️ error', errorMessage)
|
||||
return <Custom500 />
|
||||
@@ -15,19 +15,19 @@ export default function Teks({errorCode, errorMessage, teks, denyeTeks}) {
|
||||
|
||||
return (
|
||||
<HeadLayout title='Paroles et Traductions' tab={1} slug='paroles'>
|
||||
<TeksDrawer teks={teks} denyeTeks={denyeTeks} />
|
||||
<TeksDrawer paroles={paroles} denyeTeks={denyeTeks} />
|
||||
</HeadLayout>
|
||||
)
|
||||
}
|
||||
|
||||
export async function getServerSideProps() {
|
||||
let teks
|
||||
let paroles
|
||||
let denyeTeks
|
||||
let hasError
|
||||
let errorMessage
|
||||
|
||||
try {
|
||||
teks = await jwennTeks()
|
||||
paroles = await jwennTeks()
|
||||
denyeTeks = await jwennDenyeTeks()
|
||||
} catch (error) {
|
||||
errorMessage = error.message
|
||||
@@ -38,7 +38,7 @@ export async function getServerSideProps() {
|
||||
props: {
|
||||
errorCode: hasError || null,
|
||||
errorMessage: errorMessage || null,
|
||||
teks: teks || null,
|
||||
paroles: paroles || null,
|
||||
denyeTeks: denyeTeks || null
|
||||
}
|
||||
}
|
||||
@@ -47,13 +47,13 @@ export async function getServerSideProps() {
|
||||
Teks.defaultProps = {
|
||||
errorCode: null,
|
||||
errorMessage: null,
|
||||
teks: null,
|
||||
paroles: null,
|
||||
denyeTeks: null
|
||||
}
|
||||
|
||||
Teks.propTypes = {
|
||||
errorCode: PropTypes.bool,
|
||||
errorMessage: PropTypes.string,
|
||||
teks: PropTypes.array,
|
||||
paroles: PropTypes.array,
|
||||
denyeTeks: PropTypes.array
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user