Skip to content

Commit

Permalink
fix(name): fix a couple of crashes in name and title route
Browse files Browse the repository at this point in the history
  • Loading branch information
zyachel committed May 21, 2023
1 parent be80244 commit 8d9b663
Show file tree
Hide file tree
Showing 10 changed files with 95 additions and 141 deletions.
2 changes: 1 addition & 1 deletion src/components/name/Basic.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ type Props = {

const Basic = ({ data, className }: Props) => {
return (
<CardBasic className={className} image={data.poster.url} title={data.name}>
<CardBasic className={className} image={data.poster?.url} title={data.name}>
<div className={styles.ratings}>
{data.ranking && (
<p className={styles.rating}>
Expand Down
76 changes: 23 additions & 53 deletions src/components/name/Credits.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,59 +13,29 @@ const Credits = ({ className, data }: Props) => {
return (
<section className={`${className} ${styles.credits}`}>
<h2 className='heading heading__secondary'>Credits</h2>
<section>
<h3 className='heading heading__tertiary'>Released</h3>
{data.released.map(
(item, i) =>
!!item.total && (
<details open={i === 0} key={item.category.id}>
<summary>
{item.category.text} ({item.total})
</summary>
<ul className={styles.container} key={item.category.id}>
{item.titles.map(title => (
<CardTitle
key={title.id}
link={`/title/${title.id}`}
name={title.title}
titleType={title.type.text}
image={title.poster?.url}
year={title.releaseYear}
ratings={title.ratings}
/>
))}
</ul>
</details>
)
)}
</section>
<section>
<h3 className='heading heading__tertiary'>Unreleased</h3>
{data.unreleased.map(
(item, i) =>
!!item.total && (
<details open={i === 0} key={item.category.id}>
<summary>
{item.category.text} ({item.total})
</summary>
<ul className={styles.container}>
{item.titles.map(title => (
<CardTitle
key={title.id}
link={`/title/${title.id}`}
name={title.title}
titleType={title.type.text}
image={title.poster?.url}
year={title.releaseYear}
>
<p>{title.productionStatus}</p>
</CardTitle>
))}
</ul>
</details>
)
)}
</section>
{data.released.map(
(item, i) =>
!!item.total && (
<details open={i === 0} key={item.category.id}>
<summary>
{item.category.text} ({item.total})
</summary>
<ul className={styles.container} key={item.category.id}>
{item.titles.map(title => (
<CardTitle
key={title.id}
link={`/title/${title.id}`}
name={title.title}
titleType={title.type.text}
image={title.poster?.url}
year={title.releaseYear}
ratings={title.ratings}
/>
))}
</ul>
</details>
)
)}
</section>
);
};
Expand Down
76 changes: 37 additions & 39 deletions src/components/name/DidYouKnow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,46 +7,44 @@ type Props = {
};

const DidYouKnow = ({ data }: Props) => (
<section className={styles.didYouKnow}>
<section className={styles.container}>
<h2 className='heading heading__secondary'>Did you know</h2>
<div className={styles.container}>
{!!data.trivia?.total && (
<section>
<h3 className='heading heading__tertiary'>Trivia</h3>
<div dangerouslySetInnerHTML={{ __html: data.trivia.html }}></div>
</section>
)}
{!!data.quotes?.total && (
<section>
<h3 className='heading heading__tertiary'>Quotes</h3>
<div dangerouslySetInnerHTML={{ __html: data.quotes.html }}></div>
</section>
)}
{!!data.trademark?.total && (
<section>
<h3 className='heading heading__tertiary'>Trademark</h3>
<div dangerouslySetInnerHTML={{ __html: data.trademark.html }}></div>
</section>
)}
{!!data.nicknames.length && (
<section>
<h3 className='heading heading__tertiary'>Nicknames</h3>
<p>{data.nicknames.join(', ')}</p>
</section>
)}
{!!data.salary?.total && (
<section>
<h3 className='heading heading__tertiary'>Salary</h3>
<p>
<span>{data.salary.value} in </span>
<Link href={`/title/${data.salary.title.id}`}>
<a className={'link'}>{data.salary.title.text}</a>
</Link>
<span> ({data.salary.title.year})</span>
</p>
</section>
)}
</div>
{!!data.trivia?.total && (
<section>
<h3 className='heading heading__tertiary'>Trivia</h3>
<div dangerouslySetInnerHTML={{ __html: data.trivia.html }}></div>
</section>
)}
{!!data.quotes?.total && (
<section>
<h3 className='heading heading__tertiary'>Quotes</h3>
<div dangerouslySetInnerHTML={{ __html: data.quotes.html }}></div>
</section>
)}
{!!data.trademark?.total && (
<section>
<h3 className='heading heading__tertiary'>Trademark</h3>
<div dangerouslySetInnerHTML={{ __html: data.trademark.html }}></div>
</section>
)}
{!!data.nicknames.length && (
<section>
<h3 className='heading heading__tertiary'>Nicknames</h3>
<p>{data.nicknames.join(', ')}</p>
</section>
)}
{!!data.salary?.total && (
<section>
<h3 className='heading heading__tertiary'>Salary</h3>
<p>
<span>{data.salary.value} in </span>
<Link href={`/title/${data.salary.title.id}`}>
<a className={'link'}>{data.salary.title.text}</a>
</Link>
<span> ({data.salary.title.year})</span>
</p>
</section>
)}
</section>
);

Expand Down
48 changes: 20 additions & 28 deletions src/components/name/Info.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,15 @@ const PersonalDetails = ({ info, accolades }: Props) => {
<p>
<span>Died: </span>
<span>{info.death.date}</span>
<span>
{' '}
in{' '}
<Link href={`/search/name?death_place=${info.death.location}`}>
<a className='link'>{info.death.location}</a>
</Link>
</span>
{info.death.location && (
<span>
{' '}
in{' '}
<Link href={`/search/name?death_place=${info.death.location}`}>
<a className='link'>{info.death.location}</a>
</Link>
</span>
)}
</p>
)}
{info.death.cause && (
Expand All @@ -102,11 +104,9 @@ const PersonalDetails = ({ info, accolades }: Props) => {
<span>Spouses: </span>
{info.spouses.map((spouse, i) => (
<span key={spouse.name}>
<>
{!!i && ', '}
{renderPersonNameWithLink(spouse)} {spouse.range} (
{spouse.attributes.join(', ')})
</>
{!!i && ', '}
{renderPersonNameWithLink(spouse)} {spouse.range}
{spouse.attributes && ' (' + spouse.attributes.join(', ') + ')'}
</span>
))}
</p>
Expand All @@ -116,10 +116,8 @@ const PersonalDetails = ({ info, accolades }: Props) => {
<span>Children: </span>
{info.children.map((child, i) => (
<span key={child.name}>
<>
{!!i && ', '}
{renderPersonNameWithLink(child)}
</>
{!!i && ', '}
{renderPersonNameWithLink(child)}
</span>
))}
</p>
Expand All @@ -129,10 +127,8 @@ const PersonalDetails = ({ info, accolades }: Props) => {
<span>Parents: </span>
{info.parents.map((parent, i) => (
<span key={parent.name}>
<>
{!!i && ', '}
{renderPersonNameWithLink(parent)}
</>
{!!i && ', '}
{renderPersonNameWithLink(parent)}
</span>
))}
</p>
Expand All @@ -142,10 +138,8 @@ const PersonalDetails = ({ info, accolades }: Props) => {
<span>Relatives: </span>
{info.relatives.map((relative, i) => (
<span key={relative.name}>
<>
{!!i && ', '}
{renderPersonNameWithLink(relative)} ({relative.relation})
</>
{!!i && ', '}
{renderPersonNameWithLink(relative)} ({relative.relation})
</span>
))}
</p>
Expand All @@ -155,10 +149,8 @@ const PersonalDetails = ({ info, accolades }: Props) => {
<span>Other Works: </span>
{info.otherWorks.map((work, i) => (
<span key={work.text}>
<>
{!!i && ', '}
<span dangerouslySetInnerHTML={{ __html: work.text }} />
</>
{!!i && ', '}
<span dangerouslySetInnerHTML={{ __html: work.text }} />
</span>
))}
</p>
Expand Down
18 changes: 9 additions & 9 deletions src/interfaces/misc/rawName.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export default interface Name {
total: number;
};*/

primaryImage: {
primaryImage?: {
id: string;
url: string;
height: number;
Expand Down Expand Up @@ -687,13 +687,13 @@ export default interface Name {
}>;
};
};
titleGenres: {
genres: Array<{
genre: {
text: string;
};
}>;
};
titleGenres: {
genres: Array<{
genre: {
text: string;
};
}>;
};
productionStatus: {
currentProductionStage: {
id: string;
Expand Down Expand Up @@ -882,7 +882,7 @@ export default interface Name {
plainText: string;
};
};
attributes: Array<{
attributes?: Array<{
id: string;
text: string;
}>;
Expand Down
2 changes: 1 addition & 1 deletion src/interfaces/misc/rawTitle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ export default interface RawTitle {
runtime: {
value: number;
};
description: {
description?: {
value: string;
language: string;
};
Expand Down
6 changes: 0 additions & 6 deletions src/styles/modules/components/name/credits.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,6 @@
display: grid;
gap: var(--comp-whitespace);

& > section {
overflow-x: auto;
display: grid;
gap: var(--spacer-1);
}

details {
overflow-x: auto;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.bio {
.container {
display: grid;
gap: var(--comp-whitespace);
}
4 changes: 2 additions & 2 deletions src/utils/cleaners/name.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ const cleanName = (rawData: RawName) => {
})),
},
released: getCredits(misc.releasedPrimaryCredits),
unreleased: getCredits<'unreleased'>(misc.unreleasedPrimaryCredits),
// unreleased: getCredits<'unreleased'>(misc.unreleasedPrimaryCredits),
},
personalDetails: {
officialSites: misc.personalDetailsExternalLinks.edges.map(item => ({
Expand All @@ -162,7 +162,7 @@ const cleanName = (rawData: RawName) => {
name: spouse.spouse.asMarkdown.plainText,
id: spouse.spouse.name?.id ?? null,
range: spouse.timeRange.displayableProperty.value.plaidHtml,
attributes: spouse.attributes.map(attr => attr.text),
attributes: spouse.attributes?.map(attr => attr.text) ?? null,
})) ?? null,
children: misc.children.edges.map(child => ({
name: child.node.relationName.displayableProperty.value.plainText,
Expand Down
2 changes: 1 addition & 1 deletion src/utils/cleaners/title.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ const cleanTitle = (rawData: RawTitle) => {
isMature: main.primaryVideos.edges[0].node.isMature,
thumbnail: main.primaryVideos.edges[0].node.thumbnail.url,
runtime: main.primaryVideos.edges[0].node.runtime.value,
caption: main.primaryVideos.edges[0].node.description.value,
caption: main.primaryVideos.edges[0].node.description?.value ?? null,
urls: main.primaryVideos.edges[0].node.playbackURLs.map(url => ({
resolution: url.displayName.value,
mimeType: url.mimeType,
Expand Down

0 comments on commit 8d9b663

Please sign in to comment.