2022-09-11 19:37:24 +05:30
|
|
|
// external
|
2023-01-28 22:09:27 +05:30
|
|
|
import { GetServerSideProps, GetStaticProps, GetStaticPaths } from 'next';
|
2022-12-31 22:02:24 +05:30
|
|
|
import Head from 'next/head';
|
2023-01-28 22:09:27 +05:30
|
|
|
import Meta from 'src/components/meta/Meta';
|
|
|
|
import Layout from 'src/layouts/Layout';
|
|
|
|
import ErrorInfo from 'src/components/error/ErrorInfo';
|
|
|
|
// prettier-ignore
|
|
|
|
import { Basic, Cast, DidYouKnow, Info, Media, MoreLikeThis, Reviews } from 'src/components/title';
|
|
|
|
import Title from 'src/interfaces/shared/title';
|
|
|
|
import { AppError } from 'src/interfaces/shared/error';
|
|
|
|
import title from 'src/utils/fetchers/title';
|
|
|
|
import { getProxiedIMDbImgUrl } from 'src/utils/helpers';
|
|
|
|
import styles from 'src/styles/modules/pages/title/title.module.scss';
|
2022-09-11 19:37:24 +05:30
|
|
|
|
2022-12-31 22:02:24 +05:30
|
|
|
type Props = { data: Title; error: null } | { error: AppError; data: null };
|
2022-09-11 19:37:24 +05:30
|
|
|
|
|
|
|
// TO-DO: make a wrapper page component to display errors, if present in props
|
|
|
|
const TitleInfo = ({ data, error }: Props) => {
|
|
|
|
if (error)
|
2022-12-31 22:02:24 +05:30
|
|
|
return <ErrorInfo message={error.message} statusCode={error.statusCode} />;
|
2022-09-11 19:37:24 +05:30
|
|
|
|
|
|
|
const info = {
|
|
|
|
meta: data.meta,
|
|
|
|
keywords: data.keywords,
|
|
|
|
details: data.details,
|
|
|
|
boxOffice: data.boxOffice,
|
|
|
|
technicalSpecs: data.technicalSpecs,
|
|
|
|
accolades: data.accolades,
|
2022-12-31 22:02:24 +05:30
|
|
|
};
|
2022-09-11 19:37:24 +05:30
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<Meta
|
|
|
|
title={`${data.basic.title} (${
|
|
|
|
data.basic.releaseYear?.start || data.basic.type.name
|
|
|
|
})`}
|
|
|
|
description={data.basic.plot || undefined}
|
|
|
|
/>
|
2022-10-30 19:18:12 -04:00
|
|
|
<Head>
|
|
|
|
<meta
|
2023-01-28 22:09:27 +05:30
|
|
|
title='og:image'
|
2022-10-31 17:37:36 -04:00
|
|
|
content={
|
|
|
|
data.basic.poster?.url
|
|
|
|
? getProxiedIMDbImgUrl(data.basic.poster?.url)
|
|
|
|
: '/icon-512.png'
|
|
|
|
}
|
2022-10-30 19:18:12 -04:00
|
|
|
/>
|
|
|
|
</Head>
|
2022-09-11 19:37:24 +05:30
|
|
|
<Layout className={styles.title}>
|
|
|
|
<Basic data={data.basic} className={styles.basic} />
|
2022-12-31 22:02:24 +05:30
|
|
|
<Media className={styles.media} media={data.media} />
|
2022-09-11 19:37:24 +05:30
|
|
|
<Cast className={styles.cast} cast={data.cast} />
|
|
|
|
<div className={styles.textarea}>
|
|
|
|
<DidYouKnow data={data.didYouKnow} />
|
2022-12-31 22:02:24 +05:30
|
|
|
<Reviews reviews={data.reviews} />
|
2022-09-11 19:37:24 +05:30
|
|
|
</div>
|
2022-12-31 22:02:24 +05:30
|
|
|
<Info className={styles.infoarea} info={info} />
|
2022-09-11 19:37:24 +05:30
|
|
|
<MoreLikeThis className={styles.related} data={data.moreLikeThis} />
|
|
|
|
</Layout>
|
|
|
|
</>
|
2022-12-31 22:02:24 +05:30
|
|
|
);
|
|
|
|
};
|
2022-09-11 19:37:24 +05:30
|
|
|
|
|
|
|
// TO-DO: make a getServerSideProps wrapper for handling errors
|
2023-01-28 22:09:27 +05:30
|
|
|
export const getServerSideProps: GetServerSideProps = async ctx => {
|
|
|
|
const titleId = ctx.params!.titleId as string;
|
2022-09-11 19:37:24 +05:30
|
|
|
|
|
|
|
try {
|
2023-01-28 22:09:27 +05:30
|
|
|
const data = await title(titleId);
|
2022-09-11 19:37:24 +05:30
|
|
|
|
2023-01-28 22:09:27 +05:30
|
|
|
return { props: { data, error: null } };
|
2022-09-11 19:37:24 +05:30
|
|
|
} catch (error: any) {
|
2023-01-28 22:09:27 +05:30
|
|
|
const { message, statusCode } = error;
|
|
|
|
ctx.res.statusCode = statusCode;
|
|
|
|
ctx.res.statusMessage = message;
|
2022-09-11 19:37:24 +05:30
|
|
|
|
2023-01-28 22:09:27 +05:30
|
|
|
return { props: { error: { message, statusCode }, data: null } };
|
2022-09-11 19:37:24 +05:30
|
|
|
}
|
2023-01-28 22:09:27 +05:30
|
|
|
};
|
2022-09-11 19:37:24 +05:30
|
|
|
|
2023-01-28 22:09:27 +05:30
|
|
|
export default TitleInfo;
|
2022-09-11 19:37:24 +05:30
|
|
|
|
|
|
|
// could've used getStaticProps instead of getServerSideProps, but meh.
|
|
|
|
/*
|
|
|
|
export const getStaticProps: GetStaticProps = async ctx => {
|
|
|
|
const titleId = ctx.params!.titleId as string;
|
|
|
|
try {
|
|
|
|
const data = await title(titleId);
|
|
|
|
|
|
|
|
return {
|
|
|
|
props: { data, error: null },
|
|
|
|
revalidate: 60 * 60 * 24, // 1 day
|
|
|
|
};
|
|
|
|
} catch (error) {
|
|
|
|
// console.log(error);
|
|
|
|
|
|
|
|
return { notFound: true };
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
export const getStaticPaths: GetStaticPaths = () => {
|
|
|
|
return {
|
|
|
|
paths: [{ params: { titleId: 'tt0133093' } }],
|
|
|
|
fallback: 'blocking',
|
|
|
|
};
|
|
|
|
};
|
|
|
|
*/
|