From 57b050f19619454acae9e4f2630c1bb2a63dbccc Mon Sep 17 00:00:00 2001
From: zyachel
Date: Sat, 31 Dec 2022 22:02:24 +0530
Subject: [PATCH] refactor: refactor code a bit
make a hook to abstarct logic from page
changes to .prettierrc
changes to a couple of imports/exports
bunch of screen reader tweaks
---
.prettierrc | 12 ++-
src/components/buttons/ThemeToggler.tsx | 2 +-
src/components/{Error => error}/ErrorInfo.tsx | 20 ++--
src/components/{Meta => meta}/Meta.tsx | 0
src/components/title/Basic.tsx | 42 ++++-----
src/components/title/Info.tsx | 48 +++++-----
src/components/title/Media.tsx | 22 ++---
src/components/title/Reviews.tsx | 16 ++--
src/components/title/index.tsx | 9 ++
src/hooks/usePageLoading.ts | 31 +++++++
src/pages/404.tsx | 2 +-
src/pages/500.tsx | 4 +-
src/pages/_app.tsx | 33 ++-----
src/pages/_document.tsx | 18 ++--
src/pages/about/index.tsx | 92 +++++++++----------
src/pages/contact/index.tsx | 16 ++--
src/pages/privacy/index.tsx | 12 +--
src/pages/title/[titleId]/index.tsx | 55 ++++++-----
18 files changed, 226 insertions(+), 208 deletions(-)
rename src/components/{Error => error}/ErrorInfo.tsx (74%)
rename src/components/{Meta => meta}/Meta.tsx (100%)
create mode 100644 src/components/title/index.tsx
create mode 100644 src/hooks/usePageLoading.ts
diff --git a/.prettierrc b/.prettierrc
index fbe0e55..25453e9 100644
--- a/.prettierrc
+++ b/.prettierrc
@@ -1,6 +1,8 @@
{
- "trailingComma": "es5",
- "tabWidth": 2,
- "semi": false,
- "singleQuote": true
-}
\ No newline at end of file
+ "trailingComma": "es5",
+ "tabWidth": 2,
+ "arrowParens": "avoid",
+ "semi": true,
+ "singleQuote": true,
+ "jsxSingleQuote": true
+}
diff --git a/src/components/buttons/ThemeToggler.tsx b/src/components/buttons/ThemeToggler.tsx
index 52f2157..bd9614b 100644
--- a/src/components/buttons/ThemeToggler.tsx
+++ b/src/components/buttons/ThemeToggler.tsx
@@ -17,9 +17,9 @@ const ThemeToggler = (props: Props) => {
return (
@@ -99,7 +99,7 @@ const Basic = ({ data, className }: Props) => {
{formatNumber(data.ranking.position)}
{' '}
@@ -136,7 +136,7 @@ const Basic = ({ data, className }: Props) => {
{data.plot || '-'}
}
- {data.primaryCrew.map((crewType) => (
+ {data.primaryCrew.map(crewType => (
{`${crewType.type.category}: `}
@@ -153,7 +153,7 @@ const Basic = ({ data, className }: Props) => {
))}
- )
-}
+ );
+};
-export default Basic
+export default Basic;
diff --git a/src/components/title/Info.tsx b/src/components/title/Info.tsx
index 8ee9983..12f6d5f 100644
--- a/src/components/title/Info.tsx
+++ b/src/components/title/Info.tsx
@@ -1,5 +1,5 @@
import Link from 'next/link';
-import { NextRouter } from 'next/router';
+import { useRouter } from 'next/router';
import { Info } from '../../interfaces/shared/title';
import { formatMoney, formatTime } from '../../utils/helpers';
@@ -8,10 +8,10 @@ import styles from '../../styles/modules/components/title/info.module.scss';
type Props = {
info: Info;
className: string;
- router: NextRouter;
};
-const Info = ({ info, className, router }: Props) => {
+const Info = ({ info, className }: Props) => {
+ const router = useRouter();
const { titleId } = router.query;
const { boxOffice, details, meta, keywords, technicalSpecs, accolades } =
info;
@@ -20,7 +20,7 @@ const Info = ({ info, className, router }: Props) => {
{meta.infoEpisode && (
- Episode info
+ Episode info
{meta.infoEpisode.numSeason && (
@@ -50,14 +50,14 @@ const Info = ({ info, className, router }: Props) => {
{meta.infoEpisode.prevId && (
- Go to previous episode
+ Go to previous episode
)}
{meta.infoEpisode.nextId && (
- Go to next episode
+ Go to next episode
)}
@@ -66,7 +66,7 @@ const Info = ({ info, className, router }: Props) => {
)}
{meta.infoSeries && (
- Series info
+ Series info
)}
{!!keywords.total && (
- Keywords
+ Keywords
{keywords.list.map(word => (
-
- {word}
+ {word}
))}
@@ -135,7 +135,7 @@ const Info = ({ info, className, router }: Props) => {
)}
{!!Object.keys(details).length && (
- Details
+ Details
{details.releaseDate && (
@@ -156,7 +156,7 @@ const Info = ({ info, className, router }: Props) => {
- {country.text}
+ {country.text}
))}
@@ -168,7 +168,7 @@ const Info = ({ info, className, router }: Props) => {
{details.officialSites.sites.map((site, i) => (
{!!i && ', '}
-
+
{site.name}
@@ -182,7 +182,7 @@ const Info = ({ info, className, router }: Props) => {
{!!i && ', '}
- {lang.text}
+ {lang.text}
))}
@@ -201,7 +201,7 @@ const Info = ({ info, className, router }: Props) => {
{!!i && ', '}
- {loc}
+ {loc}
))}
@@ -214,7 +214,7 @@ const Info = ({ info, className, router }: Props) => {
{!!i && ', '}
- {co.name}
+ {co.name}
))}
@@ -225,7 +225,7 @@ const Info = ({ info, className, router }: Props) => {
)}
{!!Object.keys(boxOffice).length && (
- Box office
+ Box office
{boxOffice.budget && (
@@ -277,7 +277,7 @@ const Info = ({ info, className, router }: Props) => {
)}
{!!Object.keys(technicalSpecs).length && (
- Technical specs
+ Technical specs
{technicalSpecs.runtime && (
@@ -293,7 +293,7 @@ const Info = ({ info, className, router }: Props) => {
{!!i && ', '}
- {color.name}
+ {color.name}
))}
@@ -308,7 +308,7 @@ const Info = ({ info, className, router }: Props) => {
{!!i && ', '}
- {sound.name}
+ {sound.name}
))}
diff --git a/src/components/title/Media.tsx b/src/components/title/Media.tsx
index e2c63ed..c9b44af 100644
--- a/src/components/title/Media.tsx
+++ b/src/components/title/Media.tsx
@@ -1,6 +1,5 @@
import Image from 'next/future/image';
import Link from 'next/link';
-import { NextRouter } from 'next/router';
import { Media } from '../../interfaces/shared/title';
import { getProxiedIMDbImgUrl, modifyIMDbImg } from '../../utils/helpers';
@@ -9,21 +8,20 @@ import styles from '../../styles/modules/components/title/media.module.scss';
type Props = {
className: string;
media: Media;
- router: NextRouter;
};
-const Media = ({ className, media, router }: Props) => {
+const Media = ({ className, media }: Props) => {
return (
{(media.trailer || !!media.videos.total) && (
- Videos
+ Videos
{media.trailer && (
-
+