1 |
ae770857
|
Schwobik
|
import {Button, Container, Paper, Typography} from '@mui/material'
|
2 |
|
|
import {Fragment, useEffect, useState} from 'react'
|
3 |
|
|
import { useDispatch, useSelector } from 'react-redux'
|
4 |
|
|
import { logout } from '../Auth/userSlice'
|
5 |
|
|
import { RootState } from '../redux/store'
|
6 |
|
|
import {SourcesDto, TitlePageDto} from "../../swagger/data-contracts"
|
7 |
|
|
import axiosInstance from "../../api/api"
|
8 |
|
|
import 'react-quill/dist/quill.snow.css'
|
9 |
|
|
import ContentLoading from "../Reusables/ContentLoading"
|
10 |
|
|
import EditBibliography from "./EditBibliography"
|
11 |
|
|
import {Link as RouterLink, useNavigate} from "react-router-dom"
|
12 |
|
|
import EditIcon from '@mui/icons-material/Edit'
|
13 |
93048c8c
|
Vaclav Honzik
|
import { formatHtmlStringToReactDom } from "../../utils/Formatting/HtmlUtils"
|
14 |
ae770857
|
Schwobik
|
|
15 |
|
|
|
16 |
|
|
const apiError =
|
17 |
|
|
'Error while fetching data from the server, please try again later.'
|
18 |
|
|
|
19 |
|
|
const Bibliography = () => {
|
20 |
|
|
const [sources, setSources] = useState<SourcesDto | undefined>(undefined)
|
21 |
|
|
const [isContentLoading, setIsContentLoading] = useState(true)
|
22 |
|
|
const [err, setErr] = useState<string | undefined>(undefined)
|
23 |
|
|
|
24 |
|
|
let navigate = useNavigate()
|
25 |
|
|
const openEditHomePage = () => {
|
26 |
|
|
let path = '/editBibliography'
|
27 |
|
|
navigate(path)
|
28 |
|
|
}
|
29 |
|
|
|
30 |
|
|
const isAdmin = useSelector(
|
31 |
|
|
(state: RootState) => state.user.roles.includes("ROLE_ADMIN")
|
32 |
|
|
)
|
33 |
|
|
// Fetch the item from the api after mounting the component
|
34 |
|
|
useEffect(() => {
|
35 |
|
|
// Function to fetch the item from the api
|
36 |
|
|
const fetchItem = async () => {
|
37 |
|
|
try {
|
38 |
|
|
const { data, status } = await axiosInstance.get(
|
39 |
|
|
`/sources`
|
40 |
|
|
)
|
41 |
|
|
if (status !== 200) {
|
42 |
|
|
setErr(apiError)
|
43 |
|
|
return
|
44 |
|
|
}
|
45 |
|
|
|
46 |
|
|
setSources(data)
|
47 |
|
|
setIsContentLoading(false)
|
48 |
|
|
} catch (err: any) {
|
49 |
|
|
setErr(apiError)
|
50 |
|
|
}
|
51 |
|
|
}
|
52 |
|
|
fetchItem()
|
53 |
|
|
}, [])
|
54 |
|
|
|
55 |
|
|
return (
|
56 |
|
|
<Fragment>
|
57 |
|
|
<Typography variant="h3" sx={{ mb: 2 }} fontWeight="bold">
|
58 |
|
|
Sources
|
59 |
|
|
</Typography>
|
60 |
|
|
<Paper style={{ minHeight: '80vh', display:'flex', justifyContent: 'space-between', flexDirection:'column'}} variant="outlined">
|
61 |
|
|
{isContentLoading && !err ? <ContentLoading /> : null}
|
62 |
|
|
{!isContentLoading && sources ? (
|
63 |
de72dff4
|
Schwobik
|
<Container sx={{ mt: 4 }} maxWidth={false}>
|
64 |
ae770857
|
Schwobik
|
{formatHtmlStringToReactDom(sources["sources"] as string)}
|
65 |
|
|
</Container>
|
66 |
|
|
) : null}
|
67 |
|
|
|
68 |
|
|
{isAdmin ? (
|
69 |
de72dff4
|
Schwobik
|
<Container sx={{ mb: 3 }} maxWidth={false} >
|
70 |
ae770857
|
Schwobik
|
<Button
|
71 |
|
|
startIcon={<EditIcon />}
|
72 |
|
|
variant="contained"
|
73 |
|
|
component={RouterLink}
|
74 |
|
|
to="/editSources"
|
75 |
|
|
color="primary"
|
76 |
|
|
sx={{ mb: 2 }}
|
77 |
|
|
>
|
78 |
|
|
Edit
|
79 |
|
|
</Button>
|
80 |
|
|
</Container>
|
81 |
|
|
) : null}
|
82 |
|
|
</Paper>
|
83 |
|
|
</Fragment>
|
84 |
|
|
)
|
85 |
|
|
}
|
86 |
|
|
|
87 |
|
|
export default Bibliography
|