From 4bd87647d0551c20e13589a62690a6f3e5ad8ff7 Mon Sep 17 00:00:00 2001 From: Brandon Cohen Date: Thu, 11 May 2023 00:16:50 -0400 Subject: [PATCH] fix: corrected initial fallback data load on details page (#3395) --- src/pages/movie/[movieId]/index.tsx | 36 ++++++++++++++--------------- src/pages/tv/[tvId]/index.tsx | 34 +++++++++++++-------------- 2 files changed, 34 insertions(+), 36 deletions(-) diff --git a/src/pages/movie/[movieId]/index.tsx b/src/pages/movie/[movieId]/index.tsx index 2bb971c18..053ee3ff3 100644 --- a/src/pages/movie/[movieId]/index.tsx +++ b/src/pages/movie/[movieId]/index.tsx @@ -1,7 +1,7 @@ import MovieDetails from '@app/components/MovieDetails'; import type { MovieDetails as MovieDetailsType } from '@server/models/Movie'; import axios from 'axios'; -import type { NextPage } from 'next'; +import type { GetServerSideProps, NextPage } from 'next'; interface MoviePageProps { movie?: MovieDetailsType; @@ -11,25 +11,25 @@ const MoviePage: NextPage = ({ movie }) => { return ; }; -MoviePage.getInitialProps = async (ctx) => { - if (ctx.req) { - const response = await axios.get( - `http://localhost:${process.env.PORT || 5055}/api/v1/movie/${ - ctx.query.movieId - }`, - { - headers: ctx.req?.headers?.cookie - ? { cookie: ctx.req.headers.cookie } - : undefined, - } - ); +export const getServerSideProps: GetServerSideProps = async ( + ctx +) => { + const response = await axios.get( + `http://localhost:${process.env.PORT || 5055}/api/v1/movie/${ + ctx.query.movieId + }`, + { + headers: ctx.req?.headers?.cookie + ? { cookie: ctx.req.headers.cookie } + : undefined, + } + ); - return { + return { + props: { movie: response.data, - }; - } - - return {}; + }, + }; }; export default MoviePage; diff --git a/src/pages/tv/[tvId]/index.tsx b/src/pages/tv/[tvId]/index.tsx index 69fe216fd..a8a3cbd7d 100644 --- a/src/pages/tv/[tvId]/index.tsx +++ b/src/pages/tv/[tvId]/index.tsx @@ -1,7 +1,7 @@ import TvDetails from '@app/components/TvDetails'; import type { TvDetails as TvDetailsType } from '@server/models/Tv'; import axios from 'axios'; -import type { NextPage } from 'next'; +import type { GetServerSideProps, NextPage } from 'next'; interface TvPageProps { tv?: TvDetailsType; @@ -11,25 +11,23 @@ const TvPage: NextPage = ({ tv }) => { return ; }; -TvPage.getInitialProps = async (ctx) => { - if (ctx.req) { - const response = await axios.get( - `http://localhost:${process.env.PORT || 5055}/api/v1/tv/${ - ctx.query.tvId - }`, - { - headers: ctx.req?.headers?.cookie - ? { cookie: ctx.req.headers.cookie } - : undefined, - } - ); +export const getServerSideProps: GetServerSideProps = async ( + ctx +) => { + const response = await axios.get( + `http://localhost:${process.env.PORT || 5055}/api/v1/tv/${ctx.query.tvId}`, + { + headers: ctx.req?.headers?.cookie + ? { cookie: ctx.req.headers.cookie } + : undefined, + } + ); - return { + return { + props: { tv: response.data, - }; - } - - return {}; + }, + }; }; export default TvPage;