1
|
import {
|
2
|
Button,
|
3
|
Card,
|
4
|
CardContent,
|
5
|
Grid,
|
6
|
Stack,
|
7
|
Typography,
|
8
|
} from '@mui/material'
|
9
|
import { Fragment, useEffect, useState } from 'react'
|
10
|
import { MapContainer, TileLayer, useMap } from 'react-leaflet'
|
11
|
import mapConfig from '../../config/mapConfig'
|
12
|
import TextPath from 'react-leaflet-textpath'
|
13
|
import PlaintextUpload from './PlaintextUpload'
|
14
|
import FileUpload from './FileUpload'
|
15
|
import L from 'leaflet'
|
16
|
import DeleteIcon from '@mui/icons-material/Delete'
|
17
|
import { PathDto } from '../../swagger/data-contracts'
|
18
|
import { formatHtmlStringToReactDom } from '../../utils/formatting/HtmlUtils'
|
19
|
import MapPath from './MapPath'
|
20
|
import EditIcon from '@mui/icons-material/Edit'
|
21
|
import { useDispatch, useSelector } from 'react-redux'
|
22
|
import { RootState } from '../redux/store'
|
23
|
import { consumeErr as consumeError } from './trackingToolSlice'
|
24
|
import { showNotification } from '../Notification/notificationSlice'
|
25
|
|
26
|
// Page with tracking tool
|
27
|
const TrackingTool = () => {
|
28
|
// Path response from the API
|
29
|
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
|
|
33
|
// const map = useMap()
|
34
|
|
35
|
// // Set the map center
|
36
|
// useEffect(() => {
|
37
|
// map.flyTo(mapCenter, mapConfig.defaultZoom)
|
38
|
// }, [map, mapCenter])
|
39
|
|
40
|
// 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
|
|
58
|
return (
|
59
|
<Fragment>
|
60
|
<Typography variant="h3" sx={{ mb: 2 }} fontWeight="bold">
|
61
|
Tracking Tool
|
62
|
</Typography>
|
63
|
|
64
|
{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
|
Processed Text
|
75
|
</Typography>
|
76
|
<Typography variant="body2">
|
77
|
{formatHtmlStringToReactDom(
|
78
|
pathDto.text ?? ''
|
79
|
)}
|
80
|
</Typography>
|
81
|
</Stack>
|
82
|
<Stack justifyItems="flex-end" alignSelf="flex-end" alignItems="flex-end">
|
83
|
<Button size="small" variant="outlined" startIcon={<EditIcon />}>Edit</Button>
|
84
|
</Stack>
|
85
|
</CardContent>
|
86
|
</Card>
|
87
|
</Fragment>
|
88
|
)}
|
89
|
<Grid container>
|
90
|
<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
|
<Stack
|
104
|
direction="row"
|
105
|
alignItems="flex-start"
|
106
|
spacing={2}
|
107
|
sx={{ mt: 1 }}
|
108
|
>
|
109
|
<Typography
|
110
|
variant="h5"
|
111
|
sx={{ mb: 2 }}
|
112
|
fontWeight="500"
|
113
|
>
|
114
|
{pathDto ? 'Update path' : 'Show Path'}
|
115
|
</Typography>
|
116
|
<PlaintextUpload />
|
117
|
<FileUpload />
|
118
|
</Stack>
|
119
|
</Grid>
|
120
|
|
121
|
<Grid
|
122
|
item
|
123
|
xs={12}
|
124
|
md={12}
|
125
|
style={{
|
126
|
minHeight: '60vh',
|
127
|
maxHeight: '100vh',
|
128
|
width: '100%',
|
129
|
}}
|
130
|
>
|
131
|
<MapContainer
|
132
|
center={[mapCenter[0], mapCenter[1]]}
|
133
|
zoom={mapConfig.defaultZoom}
|
134
|
style={{ height: '100%', minHeight: '100%' }}
|
135
|
>
|
136
|
<TileLayer
|
137
|
attribution={mapConfig.attribution}
|
138
|
url={mapConfig.url}
|
139
|
/>
|
140
|
{pathVariants?.map((pathVariant, idx) => (
|
141
|
<MapPath
|
142
|
pathVariant={pathVariant}
|
143
|
idx={idx} />
|
144
|
))}
|
145
|
</MapContainer>
|
146
|
</Grid>
|
147
|
</Grid>
|
148
|
</Fragment>
|
149
|
)
|
150
|
}
|
151
|
|
152
|
export default TrackingTool
|