import * as React from "react"; import { useParams } from "react-router-dom"; import useSWR from "swr"; import { WRITER_MODE } from "../env"; import { HydrationData } from "../../../libs/types/hydration"; import { GetInvolved } from "../ui/molecules/get_involved"; 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"; import { Prose } from "../document/ingredients/prose"; type ContributorDetails = { sections: [string]; contributorName: string; folderName: string; isFeatured: boolean; profileImg: string; profileImgAlt: string; webLinks: { github: string; }; quote: string; }; export function ContributorSpotlight(props: HydrationData) { const locale = useLocale(); const { "*": slug } = useParams(); const baseURL = `/${locale.toLowerCase()}/community/spotlight/${slug}`; const contributorJSONUrl = `${baseURL}/index.json`; const fallbackData = props.hyData ? props : undefined; const { error, data: { hyData } = {} } = useSWR( contributorJSONUrl, async (url) => { const response = await fetch(url); if (!response.ok) { const text = await response.text(); throw new Error(`${response.status} on ${url}: ${text}`); } return await response.json(); }, { fallbackData, revalidateOnFocus: WRITER_MODE, revalidateOnMount: !fallbackData, } ); React.useEffect(() => { const pageTitle = hyData && `Contributor Spotlight - ${hyData.contributorName} - MDN Web Docs`; document.title = pageTitle; }, [hyData]); if (error) { return ; } else if (!hyData) { return ; } return ( <>

Contributor profile

{hyData.profileImgAlt} @{hyData.usernames.github}
{hyData.quote} {hyData.sections.slice(1).map((section, index) => { return ( ); })}
); }