34 lines
1.1 KiB
TypeScript
Raw Normal View History

2024-12-30 23:50:15 +01:00
import React, {useEffect, useState} from 'react'
import snarkdown from 'snarkdown'
import {Skeleton, Typography} from 'antd'
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))
2024-12-30 23:50:15 +01:00
.catch(() => {
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])
2024-12-30 23:50:15 +01:00
return (
<Skeleton loading={loading} active>
{markdown !== undefined
? <div
dangerouslySetInnerHTML={{__html: snarkdown(markdown)}}
/>
: <Typography.Text strong>
{t`📝 Please create the /public/content/${resource} file.`}
</Typography.Text>}
</Skeleton>
)
}