Skip to content

Commit

Permalink
fix(contributor-spotlight): show PageNotFound on error (#9759)
Browse files Browse the repository at this point in the history
Previously we just showed an empty page.
  • Loading branch information
caugner authored Mar 28, 2024
1 parent a0813d0 commit 0312f1a
Showing 1 changed file with 32 additions and 28 deletions.
60 changes: 32 additions & 28 deletions client/src/contributor-spotlight/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import { Quote } from "../ui/molecules/quote";

import "./index.scss";
import { useLocale } from "../hooks";
import { PageNotFound } from "../page-not-found";
import { Loading } from "../ui/atoms/loading";

type ContributorDetails = {
sections: [string];
Expand All @@ -31,7 +33,7 @@ export function ContributorSpotlight(props: HydrationData<ContributorDetails>) {

const fallbackData = props.hyData ? props : undefined;

const { data: { hyData } = {} } = useSWR<any>(
const { error, data: { hyData } = {} } = useSWR<any>(
contributorJSONUrl,
async (url) => {
const response = await fetch(url);
Expand All @@ -55,37 +57,39 @@ export function ContributorSpotlight(props: HydrationData<ContributorDetails>) {
document.title = pageTitle;
}, [hyData]);

if (error) {
return <PageNotFound />;
} else if (!hyData) {
return <Loading />;
}

return (
<>
<main className="contributor-spotlight-content-container">
{hyData && (
<>
<h1 className="_ify">Contributor profile</h1>
<section className="profile-header">
<img
className="profile-image"
src={`${baseURL}/${hyData.profileImg}`}
alt={hyData.profileImgAlt}
width="200"
height="200"
/>
<a
className="username"
href={`https://github.com/${hyData.usernames.github}`}
>
@{hyData.usernames.github}
</a>
</section>
<section
dangerouslySetInnerHTML={{ __html: hyData.sections[0] }}
></section>
<Quote name={hyData.contributorName}>{hyData.quote}</Quote>
<h1 className="_ify">Contributor profile</h1>
<section className="profile-header">
<img
className="profile-image"
src={`${baseURL}/${hyData.profileImg}`}
alt={hyData.profileImgAlt}
width="200"
height="200"
/>
<a
className="username"
href={`https://github.com/${hyData.usernames.github}`}
>
@{hyData.usernames.github}
</a>
</section>
<section
dangerouslySetInnerHTML={{ __html: hyData.sections[0] }}
></section>
<Quote name={hyData.contributorName}>{hyData.quote}</Quote>

{hyData.sections.slice(1).map((section) => {
return <section dangerouslySetInnerHTML={{ __html: section }} />;
})}
</>
)}
{hyData.sections.slice(1).map((section) => {
return <section dangerouslySetInnerHTML={{ __html: section }} />;
})}
</main>
<GetInvolved />
</>
Expand Down

0 comments on commit 0312f1a

Please sign in to comment.