From 1030798a734c2fa1d123476b24810b953d02146e Mon Sep 17 00:00:00 2001 From: zyachel Date: Sun, 15 Dec 2024 09:23:41 +0000 Subject: [PATCH] fix(reviews): revert implementation of reviews route have to rewrite it later re: https://github.com/zyachel/libremdb/issues/91 --- .../reviews/[paginationKey]/index.tsx | 72 --------------- src/pages/title/[titleId]/reviews/index.tsx | 91 +------------------ 2 files changed, 4 insertions(+), 159 deletions(-) delete mode 100644 src/pages/title/[titleId]/reviews/[paginationKey]/index.tsx diff --git a/src/pages/title/[titleId]/reviews/[paginationKey]/index.tsx b/src/pages/title/[titleId]/reviews/[paginationKey]/index.tsx deleted file mode 100644 index 9b82288..0000000 --- a/src/pages/title/[titleId]/reviews/[paginationKey]/index.tsx +++ /dev/null @@ -1,72 +0,0 @@ -import { GetServerSideProps, InferGetServerSidePropsType } from 'next'; -import Meta from 'src/components/meta/Meta'; -import Layout from 'src/components/layout'; -import ErrorInfo from 'src/components/error/ErrorInfo'; -import { BasicCard, Filters, Pagination, Reviews } from 'src/components/titleReviews'; -import { AppError } from 'src/interfaces/shared/error'; -import getOrSetApiCache from 'src/utils/getOrSetApiCache'; -import { cursoredReviews } from 'src/utils/fetchers/titleReviews'; -import { cleanQueryStr, getErrorProperties } from 'src/utils/helpers'; -import { titleReviewsKey } from 'src/utils/constants/keys'; -import styles from 'src/styles/modules/pages/titleReviews/titleReviews.module.scss'; -import { TitleReviewsCursored } from 'src/interfaces/shared/titleReviews'; -import { keys as titleReviewsQueryKeys } from 'src/utils/constants/titleReviewsFilters'; - -type Props = InferGetServerSidePropsType; - -const CursoredReviewsPage = ({ data, error, originalPath }: Props) => { - if (error) return ; - - return ( - <> - - - - - - - - - - ); -}; - -// TO-DO: make a getServerSideProps wrapper for handling errors -type Data = ({ data: TitleReviewsCursored; error: null } | { error: AppError; data: null }) & { - originalPath: string; -}; -type Params = { titleId: string; paginationKey: string }; - -export const getServerSideProps: GetServerSideProps = async ctx => { - const titleId = ctx.params!.titleId; - const paginationKey = ctx.params!.paginationKey; - const title = ctx.query.title as string | null; - - const originalPath = `/title/${titleId}/reviews/_ajax?paginationKey=${paginationKey}`; - const queryObj = ctx.query as Record; - const queryStr = cleanQueryStr(queryObj, titleReviewsQueryKeys); - - try { - const data = await getOrSetApiCache( - titleReviewsKey(titleId, queryStr, paginationKey), - cursoredReviews, - titleId, - paginationKey, - queryStr, - title - ); - - return { props: { data, error: null, originalPath } }; - } catch (error) { - const { message, statusCode } = getErrorProperties(error); - ctx.res.statusCode = statusCode; - ctx.res.statusMessage = message; - - return { props: { error: { message, statusCode }, data: null, originalPath } }; - } -}; - -export default CursoredReviewsPage; diff --git a/src/pages/title/[titleId]/reviews/index.tsx b/src/pages/title/[titleId]/reviews/index.tsx index d4b37c7..05ec8e9 100644 --- a/src/pages/title/[titleId]/reviews/index.tsx +++ b/src/pages/title/[titleId]/reviews/index.tsx @@ -1,92 +1,9 @@ -import { GetServerSideProps, InferGetServerSidePropsType } from 'next'; -import Meta from 'src/components/meta/Meta'; -import Layout from 'src/components/layout'; import ErrorInfo from 'src/components/error/ErrorInfo'; -import { Filters, Pagination, Reviews, TitleCard } from 'src/components/titleReviews'; -import { AppError } from 'src/interfaces/shared/error'; -import getOrSetApiCache from 'src/utils/getOrSetApiCache'; -import titleReviews from 'src/utils/fetchers/titleReviews'; -import { cleanQueryStr, getErrorProperties, getProxiedIMDbImgUrl } from 'src/utils/helpers'; -import { titleReviewsKey } from 'src/utils/constants/keys'; -import styles from 'src/styles/modules/pages/titleReviews/titleReviews.module.scss'; -import TitleReviews from 'src/interfaces/shared/titleReviews'; -import { keys as titleReviewFiltersQueryKeys } from 'src/utils/constants/titleReviewsFilters'; -import { useState } from 'react'; -import ProgressBar from 'src/components/loaders/ProgressBar'; +import { useRouter } from 'next/router'; -type Props = InferGetServerSidePropsType; - -// TO-DO: make a wrapper page component to display errors, if present in props -const ReviewsPage = ({ data, error, originalPath }: Props) => { - const [allData, setAllData] = useState({ list: data?.list ?? [], cursor: data?.cursor ?? null }); - const [isFetching, setIsFetching] = useState(false); - - if (error) return ; - - const handleOnClickLoadMore = (queryStr = '') => { - if (!data.cursor) return; - setIsFetching(true); - fetch(`/api/title/${data.meta.titleId}/reviews/${allData.cursor}?${queryStr}`) - .then(res => { - if (!res.ok) throw new Error('something went wrong'); - return res.json(); - }) - .then((newData: { data: NonNullable }) => - setAllData(prev => ({ - list: prev.list.concat(newData.data.list), - cursor: newData.data.cursor ?? null, - })) - ) - .catch(console.log) - .finally(() => setIsFetching(false)); - }; - - return ( - <> - {isFetching && } - - - - - - - - - - ); -}; - -// TO-DO: make a getServerSideProps wrapper for handling errors -type Data = ({ data: TitleReviews; error: null } | { error: AppError; data: null }) & { - originalPath: string; -}; -type Params = { titleId: string }; - -export const getServerSideProps: GetServerSideProps = async ctx => { - const titleId = ctx.params!.titleId; - const originalPath = ctx.resolvedUrl; - const queryParams = ctx.query as Record; - const queryStr = cleanQueryStr(queryParams, titleReviewFiltersQueryKeys); - try { - const data = await getOrSetApiCache( - titleReviewsKey(titleId, queryStr, null), - titleReviews, - titleId, - queryStr - ); - - return { props: { data, error: null, originalPath } }; - } catch (error) { - const { message, statusCode } = getErrorProperties(error); - ctx.res.statusCode = statusCode; - ctx.res.statusMessage = message; - - return { props: { error: { message, statusCode }, data: null, originalPath } }; - } +const ReviewsPage = () => { + const router = useRouter(); + return ; }; export default ReviewsPage;