import React, { useEffect, useState } from 'react'; import { FormattedMessage } from 'react-intl'; import { useParams } from 'react-router-dom'; import { fetchAboutPage } from 'soapbox/actions/about'; import { useSoapboxConfig, useSettings, useAppDispatch } from 'soapbox/hooks'; import { languages } from '../preferences'; /** Displays arbitary user-uploaded HTML on a page at `/about/:slug` */ const AboutPage: React.FC = () => { const dispatch = useAppDispatch(); const { slug } = useParams<{ slug?: string }>(); const settings = useSettings(); const soapboxConfig = useSoapboxConfig(); const [pageHtml, setPageHtml] = useState(''); const [locale, setLocale] = useState(settings.get('locale')); const { aboutPages } = soapboxConfig; const page = aboutPages.get(slug || 'about'); const defaultLocale = page?.get('default') as string | undefined; const pageLocales = page?.get('locales', []) as string[]; useEffect(() => { const fetchLocale = Boolean(page && locale !== defaultLocale && pageLocales.includes(locale)); dispatch(fetchAboutPage(slug, fetchLocale ? locale : undefined)).then(html => { setPageHtml(html); }).catch(error => { // TODO: Better error handling. 404 page? setPageHtml('

Page not found

'); }); }, [locale, slug]); const alsoAvailable = (defaultLocale) && (
{' '}
); return (
{alsoAvailable}
); }; export default AboutPage;