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 PropTypes from 'prop-types'
|
||||||
|
|
||||||
import {getAlias} from '../../lib/utils/format'
|
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 HeadLayout from '../../components/head-layout'
|
||||||
|
import TeksDrawer from '../../components/teks/teks-drawer'
|
||||||
|
|
||||||
import Custom500 from '../500'
|
import Custom500 from '../500'
|
||||||
import Custom404 from '../404'
|
import Custom404 from '../404'
|
||||||
|
|
||||||
export default function SlugTeks({hasError, errorMessage, paroles, parole, slug, commentaires}) {
|
export default function SlugTeks({hasError, errorMessage, parole, slug}) {
|
||||||
if (hasError) {
|
if (hasError) {
|
||||||
console.log('⚠️ error :', errorMessage)
|
console.log('⚠️ error :', errorMessage)
|
||||||
return <Custom500 />
|
return <Custom500 />
|
||||||
@@ -49,7 +49,7 @@ export default function SlugTeks({hasError, errorMessage, paroles, parole, slug,
|
|||||||
imageMime={formatKouveti() ? formatKouveti().mime : null}
|
imageMime={formatKouveti() ? formatKouveti().mime : null}
|
||||||
title={`${artistes} - ${parole.attributes.titre} | Paroles et Traductions`} tab={1} slug={`paroles/${slug}`}
|
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>
|
</HeadLayout>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -60,13 +60,10 @@ export async function getServerSideProps({query}) {
|
|||||||
let parole
|
let parole
|
||||||
let hasError
|
let hasError
|
||||||
let errorMessage
|
let errorMessage
|
||||||
let commentaires
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
paroles = await jwennTeks()
|
paroles = await jwennTeks()
|
||||||
parole = paroles.find(({attributes}) => attributes.slug === slug)
|
parole = paroles.find(({attributes}) => attributes.slug === slug)
|
||||||
commentaires = paroles.map(({attributes}) => attributes.commentaires)
|
|
||||||
commentaires = await jwennKomanteEpiTeksId(parole?.id)
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
errorMessage = error
|
errorMessage = error
|
||||||
hasError = true
|
hasError = true
|
||||||
@@ -78,8 +75,7 @@ export async function getServerSideProps({query}) {
|
|||||||
errorMessage: errorMessage ? errorMessage.message : null,
|
errorMessage: errorMessage ? errorMessage.message : null,
|
||||||
paroles: paroles || null,
|
paroles: paroles || null,
|
||||||
parole: parole || null,
|
parole: parole || null,
|
||||||
slug,
|
slug
|
||||||
commentaires: commentaires || null
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -87,16 +83,12 @@ export async function getServerSideProps({query}) {
|
|||||||
SlugTeks.defaultProps = {
|
SlugTeks.defaultProps = {
|
||||||
hasError: null,
|
hasError: null,
|
||||||
errorMessage: null,
|
errorMessage: null,
|
||||||
paroles: null,
|
parole: null
|
||||||
parole: null,
|
|
||||||
commentaires: null
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SlugTeks.propTypes = {
|
SlugTeks.propTypes = {
|
||||||
hasError: PropTypes.bool,
|
hasError: PropTypes.bool,
|
||||||
errorMessage: PropTypes.string,
|
errorMessage: PropTypes.string,
|
||||||
paroles: PropTypes.array,
|
|
||||||
parole: PropTypes.object,
|
parole: PropTypes.object,
|
||||||
slug: PropTypes.string.isRequired,
|
slug: PropTypes.string.isRequired,
|
||||||
commentaires: PropTypes.array
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
import PropTypes from 'prop-types'
|
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 HeadLayout from '../../components/head-layout'
|
||||||
|
|
||||||
import Custom500 from '../500'
|
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) {
|
if (errorCode) {
|
||||||
console.log('⚠️ error', errorMessage)
|
console.log('⚠️ error', errorMessage)
|
||||||
return <Custom500 />
|
return <Custom500 />
|
||||||
@@ -15,19 +15,17 @@ export default function Teks({errorCode, errorMessage, paroles, denyeTeks}) {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<HeadLayout title='Paroles et Traductions' tab={1} slug='paroles'>
|
<HeadLayout title='Paroles et Traductions' tab={1} slug='paroles'>
|
||||||
<TeksDrawer paroles={paroles} denyeTeks={denyeTeks} />
|
<TeksDrawer denyeTeks={denyeTeks} />
|
||||||
</HeadLayout>
|
</HeadLayout>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getServerSideProps() {
|
export async function getServerSideProps() {
|
||||||
let paroles
|
|
||||||
let denyeTeks
|
let denyeTeks
|
||||||
let hasError
|
let hasError
|
||||||
let errorMessage
|
let errorMessage
|
||||||
|
|
||||||
try {
|
try {
|
||||||
paroles = await jwennTeks()
|
|
||||||
denyeTeks = await jwennDenyeTeks()
|
denyeTeks = await jwennDenyeTeks()
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
errorMessage = error.message
|
errorMessage = error.message
|
||||||
@@ -38,7 +36,6 @@ export async function getServerSideProps() {
|
|||||||
props: {
|
props: {
|
||||||
errorCode: hasError || null,
|
errorCode: hasError || null,
|
||||||
errorMessage: errorMessage || null,
|
errorMessage: errorMessage || null,
|
||||||
paroles: paroles || null,
|
|
||||||
denyeTeks: denyeTeks || null
|
denyeTeks: denyeTeks || null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -47,13 +44,11 @@ export async function getServerSideProps() {
|
|||||||
Teks.defaultProps = {
|
Teks.defaultProps = {
|
||||||
errorCode: null,
|
errorCode: null,
|
||||||
errorMessage: null,
|
errorMessage: null,
|
||||||
paroles: null,
|
|
||||||
denyeTeks: null
|
denyeTeks: null
|
||||||
}
|
}
|
||||||
|
|
||||||
Teks.propTypes = {
|
Teks.propTypes = {
|
||||||
errorCode: PropTypes.bool,
|
errorCode: PropTypes.bool,
|
||||||
errorMessage: PropTypes.string,
|
errorMessage: PropTypes.string,
|
||||||
paroles: PropTypes.array,
|
|
||||||
denyeTeks: PropTypes.array
|
denyeTeks: PropTypes.array
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user