Imrove api calls in paroles and slug page
This commit is contained in:
+6
-14
@@ -1,15 +1,15 @@
|
||||
import PropTypes from 'prop-types'
|
||||
|
||||
import {getAlias} from '../../lib/utils/format'
|
||||
import {jwennTeks, jwennKomanteEpiTeksId} from '../../lib/oki-api'
|
||||
import {jwennTeks} from '../../lib/oki-api'
|
||||
|
||||
import TeksDrawer from '../../components/teks/teks-drawer'
|
||||
import HeadLayout from '../../components/head-layout'
|
||||
import TeksDrawer from '../../components/teks/teks-drawer'
|
||||
|
||||
import Custom500 from '../500'
|
||||
import Custom404 from '../404'
|
||||
|
||||
export default function SlugTeks({hasError, errorMessage, paroles, parole, slug, commentaires}) {
|
||||
export default function SlugTeks({hasError, errorMessage, parole, slug}) {
|
||||
if (hasError) {
|
||||
console.log('⚠️ error :', errorMessage)
|
||||
return <Custom500 />
|
||||
@@ -49,7 +49,7 @@ export default function SlugTeks({hasError, errorMessage, paroles, parole, slug,
|
||||
imageMime={formatKouveti() ? formatKouveti().mime : null}
|
||||
title={`${artistes} - ${parole.attributes.titre} | Paroles et Traductions`} tab={1} slug={`paroles/${slug}`}
|
||||
>
|
||||
<TeksDrawer paroles={paroles} parole={parole.attributes} paroleId={parole.id} commentaires={commentaires} />
|
||||
<TeksDrawer parole={parole.attributes} paroleId={parole.id} slug={slug} />
|
||||
</HeadLayout>
|
||||
)
|
||||
}
|
||||
@@ -60,13 +60,10 @@ export async function getServerSideProps({query}) {
|
||||
let parole
|
||||
let hasError
|
||||
let errorMessage
|
||||
let commentaires
|
||||
|
||||
try {
|
||||
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
|
||||
@@ -78,8 +75,7 @@ export async function getServerSideProps({query}) {
|
||||
errorMessage: errorMessage ? errorMessage.message : null,
|
||||
paroles: paroles || null,
|
||||
parole: parole || null,
|
||||
slug,
|
||||
commentaires: commentaires || null
|
||||
slug
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -87,16 +83,12 @@ export async function getServerSideProps({query}) {
|
||||
SlugTeks.defaultProps = {
|
||||
hasError: null,
|
||||
errorMessage: null,
|
||||
paroles: null,
|
||||
parole: null,
|
||||
commentaires: null
|
||||
parole: null
|
||||
}
|
||||
|
||||
SlugTeks.propTypes = {
|
||||
hasError: PropTypes.bool,
|
||||
errorMessage: PropTypes.string,
|
||||
paroles: PropTypes.array,
|
||||
parole: PropTypes.object,
|
||||
slug: PropTypes.string.isRequired,
|
||||
commentaires: PropTypes.array
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user