Change awtis to artiste
This commit is contained in:
+46
-21
@@ -7,34 +7,38 @@ import HeadLayout from '../../components/head-layout'
|
||||
import {jwennAwtisEpiSlug} from '../../lib/oki-api'
|
||||
|
||||
import Custom404 from '../404'
|
||||
import Custom500 from '../500'
|
||||
|
||||
export default function SlugAwtis({error, anAwtis}) {
|
||||
if (error) {
|
||||
return <Custom404 statusCode={error} />
|
||||
export default function SlugAwtis({errorCode, error404, errorMessage, anAwtis}) {
|
||||
if (error404) {
|
||||
return <Custom404 statusCode={error404} />
|
||||
}
|
||||
|
||||
const {foto} = anAwtis
|
||||
if (errorCode) {
|
||||
console.log('⚠️ error', errorMessage)
|
||||
return <Custom500 statusCode={errorCode} />
|
||||
}
|
||||
|
||||
const {photo} = anAwtis
|
||||
|
||||
const formatKouveti = () => {
|
||||
if (foto.length === 0) {
|
||||
if (!photo) {
|
||||
return null
|
||||
}
|
||||
|
||||
const [anFoto] = foto
|
||||
|
||||
if (anFoto && anFoto.formats && anFoto.formats.large) {
|
||||
return anFoto.formats.large
|
||||
if (photo && photo.formats && photo.formats.large) {
|
||||
return photo.formats.large
|
||||
}
|
||||
|
||||
if (anFoto && anFoto.formats && anFoto.formats.medium) {
|
||||
return anFoto.formats.medium
|
||||
if (photo && photo.formats && photo.formats.medium) {
|
||||
return photo.formats.medium
|
||||
}
|
||||
|
||||
if (anFoto && anFoto.formats && anFoto.formats.small) {
|
||||
return anFoto.formats.small
|
||||
if (photo && photo.formats && photo.formats.small) {
|
||||
return photo.formats.small
|
||||
}
|
||||
|
||||
return anFoto
|
||||
return photo
|
||||
}
|
||||
|
||||
return (
|
||||
@@ -43,10 +47,10 @@ export default function SlugAwtis({error, anAwtis}) {
|
||||
imageWidth={formatKouveti() ? formatKouveti().width : null}
|
||||
imageHeight={formatKouveti() ? formatKouveti().height : null}
|
||||
imageMime={formatKouveti() ? formatKouveti().mime : null}
|
||||
title={`${anAwtis.alias} - Paroles et Traductions`} tab={2} slug={`awtis/${anAwtis.slug}`}
|
||||
title={`${anAwtis.attributes.alias} - Paroles et Traductions`} tab={2} slug={`awtis/${anAwtis.attributes.slug}`}
|
||||
>
|
||||
<Box sx={{display: 'flex', flexDirection: 'column', minHeight: '100vh'}}>
|
||||
<AwtisDetay anAwtis={anAwtis} />
|
||||
<AwtisDetay anAwtis={anAwtis.attributes} />
|
||||
</Box>
|
||||
<Footer />
|
||||
</HeadLayout>
|
||||
@@ -55,21 +59,42 @@ export default function SlugAwtis({error, anAwtis}) {
|
||||
|
||||
export async function getServerSideProps({query}) {
|
||||
const {slug} = query
|
||||
const anAwtis = await jwennAwtisEpiSlug(slug)
|
||||
let anAwtis
|
||||
let error404
|
||||
let errorCode
|
||||
let errorMessage
|
||||
|
||||
try {
|
||||
anAwtis = await jwennAwtisEpiSlug(slug)
|
||||
} catch (error) {
|
||||
errorMessage = error.message
|
||||
errorCode = true
|
||||
}
|
||||
|
||||
if (!anAwtis) {
|
||||
error404 = true
|
||||
}
|
||||
|
||||
return {
|
||||
props: {
|
||||
error: Boolean(!anAwtis),
|
||||
anAwtis: anAwtis ? anAwtis : null
|
||||
error404: error404 || null,
|
||||
errorCode: errorCode || null,
|
||||
errorMessage: errorMessage || null,
|
||||
anAwtis: anAwtis || null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SlugAwtis.defaultProps = {
|
||||
anAwtis: null
|
||||
anAwtis: null,
|
||||
error404: null,
|
||||
errorCode: null,
|
||||
errorMessage: null,
|
||||
}
|
||||
|
||||
SlugAwtis.propTypes = {
|
||||
error: PropTypes.bool.isRequired,
|
||||
error404: PropTypes.bool,
|
||||
errorCode: PropTypes.bool,
|
||||
errorMessage: PropTypes.string,
|
||||
anAwtis: PropTypes.object
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user