Imrove api calls in paroles and slug page

This commit is contained in:
Cédric FAMIBELLE-PRONZOLA
2022-05-22 22:21:10 +04:00
parent 8711fef70d
commit da4c220ed8
2 changed files with 10 additions and 23 deletions
+6 -14
View File
@@ -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
}
+4 -9
View File
@@ -1,13 +1,13 @@
import PropTypes from 'prop-types'
import {jwennDenyeTeks, jwennTeks} from '../../lib/oki-api'
import {jwennDenyeTeks} from '../../lib/oki-api'
import TeksDrawer from '../../components/teks/teks-drawer'
import HeadLayout from '../../components/head-layout'
import Custom500 from '../500'
import TeksDrawer from '../../components/teks/teks-drawer'
export default function Teks({errorCode, errorMessage, paroles, denyeTeks}) {
export default function Teks({errorCode, errorMessage, denyeTeks}) {
if (errorCode) {
console.log('⚠️ error', errorMessage)
return <Custom500 />
@@ -15,19 +15,17 @@ export default function Teks({errorCode, errorMessage, paroles, denyeTeks}) {
return (
<HeadLayout title='Paroles et Traductions' tab={1} slug='paroles'>
<TeksDrawer paroles={paroles} denyeTeks={denyeTeks} />
<TeksDrawer denyeTeks={denyeTeks} />
</HeadLayout>
)
}
export async function getServerSideProps() {
let paroles
let denyeTeks
let hasError
let errorMessage
try {
paroles = await jwennTeks()
denyeTeks = await jwennDenyeTeks()
} catch (error) {
errorMessage = error.message
@@ -38,7 +36,6 @@ export async function getServerSideProps() {
props: {
errorCode: hasError || null,
errorMessage: errorMessage || null,
paroles: paroles || null,
denyeTeks: denyeTeks || null
}
}
@@ -47,13 +44,11 @@ export async function getServerSideProps() {
Teks.defaultProps = {
errorCode: null,
errorMessage: null,
paroles: null,
denyeTeks: null
}
Teks.propTypes = {
errorCode: PropTypes.bool,
errorMessage: PropTypes.string,
paroles: PropTypes.array,
denyeTeks: PropTypes.array
}