1
|
import {Button, Container, Paper, Typography} from '@mui/material'
|
2
|
import {Fragment, useEffect, useState} from 'react'
|
3
|
import { useDispatch, useSelector } from 'react-redux'
|
4
|
import { RootState } from '../redux/store'
|
5
|
import axiosInstance from "../../api/api"
|
6
|
import 'react-quill/dist/quill.snow.css'
|
7
|
import NotAuthorized from "../NotAuthorized/NotAuthorized"
|
8
|
import SingleFileSelectionForm from "../Reusables/SingleFileSelectionForm"
|
9
|
import * as yup from "yup"
|
10
|
import {useFormik} from "formik"
|
11
|
|
12
|
|
13
|
interface UploadValues {
|
14
|
file?: File
|
15
|
}
|
16
|
|
17
|
const initialValues: UploadValues = {}
|
18
|
|
19
|
|
20
|
const ExternalSources = () => {
|
21
|
|
22
|
const [filename, setFilename] = useState<string | undefined>(undefined)
|
23
|
const [fileProcessing, setFileProcessing] = useState(false)
|
24
|
const [loading, setLoading] = useState(false)
|
25
|
|
26
|
const validationSchema = yup.object().shape({
|
27
|
file: yup.mixed().required('File is required'),
|
28
|
})
|
29
|
|
30
|
const formik = useFormik({
|
31
|
initialValues,
|
32
|
validationSchema,
|
33
|
onSubmit: async (values) => {
|
34
|
setFileProcessing(true)
|
35
|
const formData = new FormData()
|
36
|
// @ts-ignore
|
37
|
formData.append("file", values.file)
|
38
|
|
39
|
setLoading(true)
|
40
|
const {data, status} = await axiosInstance.post(
|
41
|
'/external-catalog-items',
|
42
|
formData,
|
43
|
{headers: {
|
44
|
'Content-Type': 'multipart/form-data'
|
45
|
}}
|
46
|
)
|
47
|
if (status !== 200) {
|
48
|
// TODO
|
49
|
}
|
50
|
setLoading(false)
|
51
|
},
|
52
|
})
|
53
|
|
54
|
// Callback when user selects the file
|
55
|
const onFileSelected = (event: any) => {
|
56
|
const file = event.currentTarget.files[0]
|
57
|
if (file) {
|
58
|
setFilename(file.name)
|
59
|
formik.setFieldValue('file', file)
|
60
|
}
|
61
|
}
|
62
|
|
63
|
const onClose = () => {
|
64
|
if (fileProcessing) {
|
65
|
return
|
66
|
}
|
67
|
setFilename(undefined)
|
68
|
formik.resetForm()
|
69
|
}
|
70
|
|
71
|
const onClearSelectedFile = () => {
|
72
|
setFilename(undefined)
|
73
|
formik.setFieldValue('file', undefined)
|
74
|
}
|
75
|
|
76
|
|
77
|
const isAdmin = useSelector(
|
78
|
(state: RootState) => state.user.roles.includes("ROLE_ADMIN")
|
79
|
)
|
80
|
const handleClick = () => {
|
81
|
|
82
|
}
|
83
|
|
84
|
const cigsUrl = "https://zenodo.org/record/5642899#.YoeJLXXP1hE";
|
85
|
const pleiadesUrl = "https://pleiades.stoa.org/";
|
86
|
const pleiadesDownloadsUrl = "https://atlantides.org/downloads/pleiades/dumps/";
|
87
|
const aneUrl = "https://www.lingfil.uu.se/research/assyriology/earth/";
|
88
|
const aneDownloadsUrl = "https://zenodo.org/record/6384045";
|
89
|
const geonamesUrl = "https://www.geonames.org/";
|
90
|
|
91
|
return (
|
92
|
<Fragment>
|
93
|
<Typography variant="h3" sx={{ mb: 2 }} fontWeight="bold">
|
94
|
External Sources
|
95
|
</Typography>
|
96
|
{isAdmin ? (
|
97
|
<Paper style={{ minHeight: '80vh' }} variant="outlined">
|
98
|
<Container sx={{ mt: 4 }}>
|
99
|
<Typography sx={{ mb: 2 }}>
|
100
|
Please upload CSV file from <a target="_blank" rel="noopener noreferrer" href={cigsUrl}>CIGS</a> (older versions than version 1.4 do not work).
|
101
|
</Typography>
|
102
|
<Typography sx={{ mb: 3 }}>
|
103
|
Files from <a target="_blank" rel="noopener noreferrer" href={pleiadesUrl}>Pleiades</a> (downloads available <a target="_blank" rel="noopener noreferrer" href={pleiadesDownloadsUrl}>here</a>), <a target="_blank" rel="noopener noreferrer" href={aneUrl}>ANE</a> (downloads available <a target="_blank" rel="noopener noreferrer" href={aneDownloadsUrl}>here</a>)
|
104
|
and <a target="_blank" rel="noopener noreferrer" href={geonamesUrl}>GeoNames</a> will be added automatically.
|
105
|
</Typography>
|
106
|
<SingleFileSelectionForm
|
107
|
onFileSelected={onFileSelected}
|
108
|
onClearSelectedFile={onClearSelectedFile}
|
109
|
filename={filename}
|
110
|
formik={formik}
|
111
|
loading={loading}
|
112
|
/>
|
113
|
</Container>
|
114
|
</Paper>
|
115
|
) : <NotAuthorized />}
|
116
|
</Fragment>
|
117
|
)
|
118
|
}
|
119
|
|
120
|
export default ExternalSources
|