Skip to content

Commit

Permalink
feat(pages): fallback to link to terms on Github
Browse files Browse the repository at this point in the history
- Facebook terms checker sometimes fail to load terms for unknown reasons
  • Loading branch information
MrOrz committed Jan 10, 2024
1 parent 20083e3 commit fd5271c
Showing 1 changed file with 22 additions and 2 deletions.
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

0 comments on commit fd5271c

Please sign in to comment.