Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add fallback when terms fail to load #558

Merged
merged 3 commits into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions components/AppLayout/AppFooter.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,14 @@ const useStyles = makeStyles(theme => ({
},
},
container: {
width: 800,
width: '100%',
maxWidth: 800,
color: theme.palette.text.primary,
gap: 20,
margin: 60,
display: 'flex',
flexWrap: 'wrap',
justifyContent: 'space-between',
},
second: {
display: 'flex',
Expand All @@ -49,7 +53,8 @@ const useStyles = makeStyles(theme => ({
height: 'auto',
},
column: {
flex: '1 1',
flex: '0 1 auto',
minWidth: 'max-content', // distribute width using longest content in the column
},
linkTextWithIcon: {
marginLeft: 12,
Expand Down Expand Up @@ -169,12 +174,11 @@ function AppFooter() {
const isDesktop = useMediaQuery('(min-width:768px)');

return (
// <Box component="footer" display={['block', 'block', 'block']}>
<Box component="footer">
<div className={classes.first}>
<div className={classes.container}>
{isDesktop && <FactCheckSection classes={classes} />}
{isDesktop && <AboutSection classes={classes} />}
<FactCheckSection classes={classes} />
<AboutSection classes={classes} />
<ContactSection classes={classes} isDesktop={isDesktop} />
</div>
</div>
Expand Down
24 changes: 22 additions & 2 deletions pages/terms.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ const TERMS_REVISIONS_URL =
const TERMS_MARKDOWN_URL =
'https://raw.githubusercontent.com/cofacts/rumors-site/master/LEGAL.md';

const TERMS_FALLBACK_URL =
'https://github.com/cofacts/rumors-site/blob/master/LEGAL.md';

// cdn.js URL and checksum from cdn.js website
//
const JS_LIBS = [
Expand Down Expand Up @@ -69,7 +72,16 @@ function Terms() {
const [termsHtml, setTermsHtml] = useState(null);

useEffect(() => {
const markdownPromise = fetch(TERMS_MARKDOWN_URL).then(resp => resp.text());
const markdownPromise = fetch(TERMS_MARKDOWN_URL)
.then(resp => {
if (resp.status !== 200) throw resp.statusText;
return resp.text();
})
.catch(error => {
console.error('Failed to fetch terms markdown', error);
window.rollbar.error('Failed to fetch terms markdown', error);
return `Cannot load terms content due to "${error}"; please view the terms [here](${TERMS_FALLBACK_URL}) instead.`;
});

const scriptPromises = JS_LIBS.map(([src, integrity], idx) => {
// Don't insert the same script when visit this page the second time
Expand Down Expand Up @@ -103,13 +115,21 @@ function Terms() {
<a key="revision" href={TERMS_REVISIONS_URL}>{t`Github`}</a>
);

const termFallbackLink = (
<a key="fallback" href={TERMS_FALLBACK_URL}>{t`User Agreement`}</a>
);

return (
<AppLayout>
<Head>
<title>{t`User Agreement`}</title>
</Head>
<TermArticle>
{termsHtml ? <div dangerouslySetInnerHTML={termsHtml} /> : t`Loading`}
{termsHtml ? (
<div dangerouslySetInnerHTML={termsHtml} />
) : (
jt`Loading ${termFallbackLink}...`
)}
<hr />
<p>{jt`See ${revisionLink} for other revisions of the user agreement.`}</p>
</TermArticle>
Expand Down
Loading