1 |
8c57f958
|
Vaclav Honzik
|
import {
|
2 |
|
|
Button,
|
3 |
|
|
Card,
|
4 |
|
|
CardContent,
|
5 |
|
|
Grid,
|
6 |
|
|
Stack,
|
7 |
|
|
Typography,
|
8 |
|
|
} from '@mui/material'
|
9 |
91fd3fa6
|
Vaclav Honzik
|
import { Fragment, useEffect, useState } from 'react'
|
10 |
8c57f958
|
Vaclav Honzik
|
import { MapContainer, TileLayer, useMap } from 'react-leaflet'
|
11 |
788ce11e
|
Vaclav Honzik
|
import mapConfig from '../../config/mapConfig'
|
12 |
76e15218
|
Vaclav Honzik
|
import TextPath from 'react-leaflet-textpath'
|
13 |
0d90d67b
|
Vaclav Honzik
|
import PlaintextUpload from './PlaintextUpload'
|
14 |
|
|
import FileUpload from './FileUpload'
|
15 |
4f42fa52
|
Václav Honzík
|
import L from 'leaflet'
|
16 |
|
|
import DeleteIcon from '@mui/icons-material/Delete'
|
17 |
dda6e56e
|
Vaclav Honzik
|
import { PathDto } from '../../swagger/data-contracts'
|
18 |
|
|
import { formatHtmlStringToReactDom } from '../../utils/formatting/HtmlUtils'
|
19 |
b70813cb
|
Vaclav Honzik
|
import MapPath from './MapPath'
|
20 |
8c57f958
|
Vaclav Honzik
|
import EditIcon from '@mui/icons-material/Edit'
|
21 |
dd270a41
|
Vaclav Honzik
|
import { useDispatch, useSelector } from 'react-redux'
|
22 |
8c57f958
|
Vaclav Honzik
|
import { RootState } from '../redux/store'
|
23 |
dd270a41
|
Vaclav Honzik
|
import { consumeErr as consumeError } from './trackingToolSlice'
|
24 |
|
|
import { showNotification } from '../Notification/notificationSlice'
|
25 |
788ce11e
|
Vaclav Honzik
|
|
26 |
|
|
// Page with tracking tool
|
27 |
|
|
const TrackingTool = () => {
|
28 |
dda6e56e
|
Vaclav Honzik
|
// Path response from the API
|
29 |
8c57f958
|
Vaclav Honzik
|
const pathDto = useSelector((state: RootState) => state.trackingTool.pathDto)
|
30 |
|
|
const pathVariants = useSelector((state: RootState) => state.trackingTool.pathVariants)
|
31 |
|
|
const mapCenter = useSelector((state: RootState) => state.trackingTool.mapCenter)
|
32 |
dda6e56e
|
Vaclav Honzik
|
|
33 |
8c57f958
|
Vaclav Honzik
|
// const map = useMap()
|
34 |
76e15218
|
Vaclav Honzik
|
|
35 |
8c57f958
|
Vaclav Honzik
|
// // Set the map center
|
36 |
|
|
// useEffect(() => {
|
37 |
|
|
// map.flyTo(mapCenter, mapConfig.defaultZoom)
|
38 |
|
|
// }, [map, mapCenter])
|
39 |
b70813cb
|
Vaclav Honzik
|
|
40 |
dd270a41
|
Vaclav Honzik
|
// Consume any error
|
41 |
|
|
const err = useSelector((state: RootState) => state.trackingTool.lastError)
|
42 |
|
|
const dispatch = useDispatch()
|
43 |
|
|
|
44 |
|
|
useEffect(() => {
|
45 |
|
|
console.log('oi')
|
46 |
|
|
if (!err) {
|
47 |
|
|
return
|
48 |
|
|
}
|
49 |
|
|
const error = `${err}`
|
50 |
|
|
dispatch(consumeError())
|
51 |
|
|
dispatch(showNotification({
|
52 |
|
|
message: error,
|
53 |
|
|
severity: 'error',
|
54 |
|
|
|
55 |
|
|
}))
|
56 |
|
|
}, [err, dispatch])
|
57 |
788ce11e
|
Vaclav Honzik
|
|
58 |
|
|
return (
|
59 |
|
|
<Fragment>
|
60 |
|
|
<Typography variant="h3" sx={{ mb: 2 }} fontWeight="bold">
|
61 |
|
|
Tracking Tool
|
62 |
|
|
</Typography>
|
63 |
|
|
|
64 |
dda6e56e
|
Vaclav Honzik
|
{pathDto && (
|
65 |
|
|
<Fragment>
|
66 |
|
|
<Card variant="outlined">
|
67 |
|
|
<CardContent>
|
68 |
|
|
<Stack direction="column">
|
69 |
|
|
<Typography
|
70 |
|
|
variant="h5"
|
71 |
|
|
sx={{ mb: 1 }}
|
72 |
|
|
fontWeight="600"
|
73 |
|
|
>
|
74 |
b70813cb
|
Vaclav Honzik
|
Processed Text
|
75 |
dda6e56e
|
Vaclav Honzik
|
</Typography>
|
76 |
|
|
<Typography variant="body2">
|
77 |
|
|
{formatHtmlStringToReactDom(
|
78 |
|
|
pathDto.text ?? ''
|
79 |
|
|
)}
|
80 |
|
|
</Typography>
|
81 |
|
|
</Stack>
|
82 |
8c57f958
|
Vaclav Honzik
|
<Stack justifyItems="flex-end" alignSelf="flex-end" alignItems="flex-end">
|
83 |
|
|
<Button size="small" variant="outlined" startIcon={<EditIcon />}>Edit</Button>
|
84 |
|
|
</Stack>
|
85 |
dda6e56e
|
Vaclav Honzik
|
</CardContent>
|
86 |
|
|
</Card>
|
87 |
|
|
</Fragment>
|
88 |
|
|
)}
|
89 |
788ce11e
|
Vaclav Honzik
|
<Grid container>
|
90 |
dda6e56e
|
Vaclav Honzik
|
<Grid item xs={12}>
|
91 |
|
|
{pathDto && pathDto?.foundCatalogItems?.length === 0 && (
|
92 |
|
|
<Typography
|
93 |
|
|
variant="body1"
|
94 |
|
|
sx={{ mb: 2 }}
|
95 |
|
|
fontWeight="500"
|
96 |
|
|
align="center"
|
97 |
|
|
color="error.main"
|
98 |
|
|
>
|
99 |
|
|
Looks like no path / catalog items match this query.
|
100 |
|
|
</Typography>
|
101 |
|
|
)}
|
102 |
|
|
|
103 |
788ce11e
|
Vaclav Honzik
|
<Stack
|
104 |
|
|
direction="row"
|
105 |
|
|
alignItems="flex-start"
|
106 |
|
|
spacing={2}
|
107 |
067c00a0
|
Vaclav Honzik
|
sx={{ mt: 1 }}
|
108 |
788ce11e
|
Vaclav Honzik
|
>
|
109 |
|
|
<Typography
|
110 |
|
|
variant="h5"
|
111 |
|
|
sx={{ mb: 2 }}
|
112 |
|
|
fontWeight="500"
|
113 |
|
|
>
|
114 |
dda6e56e
|
Vaclav Honzik
|
{pathDto ? 'Update path' : 'Show Path'}
|
115 |
788ce11e
|
Vaclav Honzik
|
</Typography>
|
116 |
8c57f958
|
Vaclav Honzik
|
<PlaintextUpload />
|
117 |
0d90d67b
|
Vaclav Honzik
|
<FileUpload />
|
118 |
788ce11e
|
Vaclav Honzik
|
</Stack>
|
119 |
|
|
</Grid>
|
120 |
dda6e56e
|
Vaclav Honzik
|
|
121 |
76e15218
|
Vaclav Honzik
|
<Grid
|
122 |
|
|
item
|
123 |
|
|
xs={12}
|
124 |
41a11178
|
Vaclav Honzik
|
md={12}
|
125 |
76e15218
|
Vaclav Honzik
|
style={{
|
126 |
|
|
minHeight: '60vh',
|
127 |
|
|
maxHeight: '100vh',
|
128 |
|
|
width: '100%',
|
129 |
|
|
}}
|
130 |
|
|
>
|
131 |
788ce11e
|
Vaclav Honzik
|
<MapContainer
|
132 |
91fd3fa6
|
Vaclav Honzik
|
center={[mapCenter[0], mapCenter[1]]}
|
133 |
788ce11e
|
Vaclav Honzik
|
zoom={mapConfig.defaultZoom}
|
134 |
|
|
style={{ height: '100%', minHeight: '100%' }}
|
135 |
|
|
>
|
136 |
76e15218
|
Vaclav Honzik
|
<TileLayer
|
137 |
|
|
attribution={mapConfig.attribution}
|
138 |
|
|
url={mapConfig.url}
|
139 |
|
|
/>
|
140 |
dd270a41
|
Vaclav Honzik
|
{pathVariants?.map((pathVariant, idx) => (
|
141 |
|
|
<MapPath
|
142 |
|
|
pathVariant={pathVariant}
|
143 |
|
|
idx={idx} />
|
144 |
|
|
))}
|
145 |
788ce11e
|
Vaclav Honzik
|
</MapContainer>
|
146 |
|
|
</Grid>
|
147 |
|
|
</Grid>
|
148 |
|
|
</Fragment>
|
149 |
|
|
)
|
150 |
|
|
}
|
151 |
|
|
|
152 |
|
|
export default TrackingTool
|