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 }) {
|
2024-08-26 18:36:51 +02:00
|
|
|
const [loading, setLoading] = useState<boolean>(false)
|
|
|
|
|
const [markdown, setMarkdown] = useState<string | undefined>(undefined)
|
2024-07-28 01:04:08 +02:00
|
|
|
|
|
|
|
|
useEffect(() => {
|
2024-08-26 18:36:51 +02:00
|
|
|
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.`)
|
2024-08-26 18:36:51 +02:00
|
|
|
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>
|
|
|
|
|
)
|
|
|
|
|
}
|