Move paroles pages to app directory

This commit is contained in:
2023-07-22 13:28:30 +04:00
parent 6f48dadbe6
commit ff992e04ed
6 changed files with 215 additions and 150 deletions
-96
View File
@@ -1,96 +0,0 @@
import PropTypes from 'prop-types'
import {getAlias} from '../../lib/utils/format'
import {jwennTeksEpiSlug} from '../../lib/oki-api'
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, parole, slug}) {
if (hasError) {
console.log('⚠️ error :', errorMessage)
return <Custom500 />
}
if (!parole) {
return <Custom404 />
}
const summary = `Paroles de « ${parole?.attributes?.titre} » : ${parole?.attributes?.transcription.slice(0, 100)}...`
const artistes = parole.attributes.artistes.length === 1 ? parole.attributes.artistes[0].data.attributes.alias : getAlias(parole.attributes.artistes, parole.attributes.prioriteArtistes)
const {couverture} = parole.attributes
const formatKouveti = () => {
if (!couverture?.data?.attributes) {
return null
}
if (couverture.data.attributes && couverture.data.attributes.formats && couverture.data.attributes.formats.large) {
return couverture.data.attributes.formats.large
}
if (couverture.data.attributes && couverture.data.attributes.formats && couverture.data.attributes.formats.medium) {
return couverture.data.attributes.formats.medium
}
if (couverture.data.attributes && couverture.data.attributes.formats && couverture.data.attributes.formats.small) {
return couverture.data.attributes.formats.small
}
return couverture.data.attributes
}
return (
<HeadLayout
imageUrl={formatKouveti() ? formatKouveti().url : null}
imageWidth={formatKouveti() ? formatKouveti().width : null}
imageHeight={formatKouveti() ? formatKouveti().height : null}
imageMime={formatKouveti() ? formatKouveti().mime : null}
title={`${artistes} - ${parole.attributes.titre} | Paroles et Traductions`} tab={2} slug={`paroles/${slug}`}
summary={summary}
>
<TeksDrawer parole={parole.attributes} paroleId={parole.id} slug={slug} />
</HeadLayout>
)
}
export async function getServerSideProps({query}) {
const {slug} = query
let paroles
let parole
let hasError
let errorMessage
try {
parole = await jwennTeksEpiSlug(slug)
} catch (error) {
errorMessage = error
hasError = true
}
return {
props: {
hasError: hasError || null,
errorMessage: errorMessage ? errorMessage.message : null,
paroles: paroles || null,
parole: parole || null,
slug
}
}
}
SlugTeks.defaultProps = {
hasError: null,
errorMessage: null,
parole: null
}
SlugTeks.propTypes = {
hasError: PropTypes.bool,
errorMessage: PropTypes.string,
parole: PropTypes.object,
slug: PropTypes.string.isRequired,
}
-54
View File
@@ -1,54 +0,0 @@
import PropTypes from 'prop-types'
import {jwennDenyeTeks} from '../../lib/oki-api'
import HeadLayout from '../../components/head-layout'
import Custom500 from '../500'
import TeksDrawer from '../../components/teks/teks-drawer'
export default function Teks({errorCode, errorMessage, denyeTeks}) {
if (errorCode) {
console.log('⚠️ error', errorMessage)
return <Custom500 />
}
return (
<HeadLayout title='Paroles et Traductions' summary='Retrouvez les paroles et traductions de vos chansons préférées.' tab={2} slug='paroles'>
<TeksDrawer denyeTeks={denyeTeks} />
</HeadLayout>
)
}
export async function getServerSideProps() {
let denyeTeks
let hasError
let errorMessage
try {
denyeTeks = await jwennDenyeTeks()
} catch (error) {
errorMessage = error.message
hasError = true
}
return {
props: {
errorCode: hasError || null,
errorMessage: errorMessage || null,
denyeTeks: denyeTeks || null
}
}
}
Teks.defaultProps = {
errorCode: null,
errorMessage: null,
denyeTeks: null
}
Teks.propTypes = {
errorCode: PropTypes.bool,
errorMessage: PropTypes.string,
denyeTeks: PropTypes.array
}