-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathindex.tsx
59 lines (47 loc) · 1.72 KB
/
index.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import React, { useEffect, useState } from 'react';
import { useNavigate, useParams } from 'react-router-dom';
import Api from 'src/Api';
import Button from 'src/components/base/Button';
import Error from 'src/components/base/Error';
import './index.css';
const ViewMessagePage: React.FunctionComponent = () => {
const { id } = useParams();
const navigate = useNavigate();
const [html, setHtml] = useState('');
const [error, setError] = useState<string | undefined>(undefined);
useEffect(() => {
loadMessage();
}, []);
if (typeof id === 'undefined') {
navigate('/blog');
return <></>;
}
const loadMessage = async () => {
const response = await Api.RenderMessage({ id });
if (typeof response.error !== 'undefined') {
setError(response.error);
return;
}
setError(undefined);
setHtml(response.response!);
};
const backClickHandler: React.EventHandler<React.SyntheticEvent<HTMLButtonElement>> = async (event) => {
event.preventDefault();
navigate('/blog');
};
return (
<div className='ViewMessagePage'>
<div className='ViewMessagePage-Header'>
<span className='ViewMessagePage-Title'>Excess | Message</span>
</div>
<div className='ViewMessagePage-Container'>
<Error error={error}/>
<div className='ViewMessagePage-Message' dangerouslySetInnerHTML={{__html: html}}></div>
<div className='ViewMessagePage-Buttons'>
<Button onClick={backClickHandler} id='back' text='Back'/>
</div>
</div>
</div>
);
};
export default ViewMessagePage;