29 lines
1.1 KiB
TypeScript
Raw Normal View History

2024-07-28 01:04:08 +02:00
import React, {useEffect, useState} from "react";
import snarkdown from "snarkdown"
import {Skeleton, Typography} from "antd";
2024-07-28 01:04:08 +02:00
import axios from "axios";
import {t} from "ttag";
2024-07-23 18:37:59 +02:00
2024-07-28 01:04:08 +02:00
export default function TextPage({resource}: { resource: string }) {
const [loading, setLoading] = useState<boolean>(false)
const [markdown, setMarkdown] = useState<string | undefined>(undefined)
2024-07-28 01:04:08 +02:00
useEffect(() => {
setLoading(true)
axios.get('/content/' + resource)
.then(res => setMarkdown(res.data))
.catch(err => {
2024-08-27 20:02:38 +02:00
console.error(`Please create the /public/content/${resource} file.`)
setMarkdown(undefined)
})
.finally(() => setLoading(false))
2024-07-28 01:04:08 +02:00
}, [resource])
return <Skeleton loading={loading} active>
{markdown !== undefined ? <div
dangerouslySetInnerHTML={{__html: snarkdown(markdown)}}></div> :
<Typography.Text strong>
2024-08-26 19:09:32 +02:00
{t`📝 Please create the /public/content/${resource} file.`}
</Typography.Text>}
2024-07-28 01:04:08 +02:00
</Skeleton>
}