Projekt

Obecné

Profil

« Předchozí | Další » 

Revize de12c6be

Přidáno uživatelem Václav Honzík před asi 2 roky(ů)

draggable

re #9741

Zobrazit rozdíly:

frontend/src/features/TrackingTool/TrackingTool.tsx
1 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 { clear, consumeErr as consumeError } from './trackingToolSlice'
24
import { showNotification } from '../Notification/notificationSlice'
25
import ClearIcon from '@mui/icons-material/Clear'
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 { clear, consumeErr as consumeError } from "./trackingToolSlice"
24
import { showNotification } from "../Notification/notificationSlice"
25
import ClearIcon from "@mui/icons-material/Clear"
26 26

  
27 27
// Page with tracking tool
28 28
const TrackingTool = () => {
29
    // Path response from the API
30
    const pathDto = useSelector(
31
        (state: RootState) => state.trackingTool.pathDto
32
    )
33
    const pathVariants = useSelector(
34
        (state: RootState) => state.trackingTool.pathVariants
35
    )
36
    const mapCenter = useSelector(
37
        (state: RootState) => state.trackingTool.mapCenter
38
    )
39

  
40
    // const map = useMap()
29
  // Path response from the API
30
  const pathDto = useSelector((state: RootState) => state.trackingTool.pathDto)
31
  const pathVariants = useSelector(
32
    (state: RootState) => state.trackingTool.pathVariants
33
  )
34
  const mapCenter = useSelector(
35
    (state: RootState) => state.trackingTool.mapCenter
36
  )
41 37

  
42
    // // Set the map center
43
    // useEffect(() => {
44
    //     map.flyTo(mapCenter, mapConfig.defaultZoom)
45
    // }, [map, mapCenter])
38
  // Consume any error
39
  const err = useSelector((state: RootState) => state.trackingTool.lastError)
40
  const dispatch = useDispatch()
46 41

  
47
    // Consume any error
48
    const err = useSelector((state: RootState) => state.trackingTool.lastError)
49
    const dispatch = useDispatch()
42
  useEffect(() => {
43
    if (!err) {
44
      return
45
    }
46
    const error = `${err}`
47
    dispatch(consumeError())
48
    dispatch(
49
      showNotification({
50
        message: error,
51
        severity: "error",
52
      })
53
    )
54
  }, [err, dispatch])
50 55

  
51
    useEffect(() => {
52
        if (!err) {
53
            return
54
        }
55
        const error = `${err}`
56
        dispatch(consumeError())
57
        dispatch(
58
            showNotification({
59
                message: error,
60
                severity: 'error',
61
            })
62
        )
63
    }, [err, dispatch])
56
  return (
57
    <Fragment>
58
      <Typography variant="h3" sx={{ mb: 2 }} fontWeight="bold">
59
        Tracking Tool
60
      </Typography>
64 61

  
65
    return (
66
        <Fragment>
67
            <Typography variant="h3" sx={{ mb: 2 }} fontWeight="bold">
68
                Tracking Tool
62
      <Grid container>
63
        <Grid item xs={12}>
64
          {pathDto && pathDto?.foundCatalogItems?.length === 0 && (
65
            <Typography
66
              variant="body1"
67
              sx={{ mb: 2 }}
68
              fontWeight="500"
69
              align="center"
70
              color="error.main"
71
            >
72
              Looks like no path / catalog items match this query.
69 73
            </Typography>
74
          )}
75
          {!pathDto && (
76
            <Stack
77
              direction="row"
78
              alignItems="flex-start"
79
              spacing={2}
80
              sx={{ mt: 1 }}
81
            >
82
              <Typography variant="h5" sx={{ mb: 2 }} fontWeight="500">
83
                Upload:
84
              </Typography>
85
              <PlaintextUpload />
86
              <FileUpload />
87
            </Stack>
88
          )}
70 89

  
71
            <Grid container>
72
                <Grid item xs={12}>
73
                    {pathDto && pathDto?.foundCatalogItems?.length === 0 && (
74
                        <Typography
75
                            variant="body1"
76
                            sx={{ mb: 2 }}
77
                            fontWeight="500"
78
                            align="center"
79
                            color="error.main"
80
                        >
81
                            Looks like no path / catalog items match this query.
82
                        </Typography>
83
                    )}
84
                    {!pathDto && (
85
                        <Stack
86
                            direction="row"
87
                            alignItems="flex-start"
88
                            spacing={2}
89
                            sx={{ mt: 1 }}
90
                        >
91
                            <Typography
92
                                variant="h5"
93
                                sx={{ mb: 2 }}
94
                                fontWeight="500"
95
                            >
96
                                Upload:
97
                            </Typography>
98
                            <PlaintextUpload />
99
                            <FileUpload />
100
                        </Stack>
101
                    )}
102

  
103
                    {pathDto && (
104
                        <Stack alignItems="flex-end">
105
                            <Button
106
                                startIcon={<ClearIcon />}
107
                                sx={{ mb: 1 }}
108
                                variant="contained"
109
                                onClick={() => dispatch(clear())}
110
                            >
111
                                Clear Map
112
                            </Button>
113
                        </Stack>
114
                    )}
115
                </Grid>
90
          {pathDto && (
91
            <Stack alignItems="flex-end">
92
              <Button
93
                startIcon={<ClearIcon />}
94
                sx={{ mb: 1 }}
95
                variant="contained"
96
                onClick={() => dispatch(clear())}
97
              >
98
                Clear Map
99
              </Button>
100
            </Stack>
101
          )}
102
        </Grid>
116 103

  
117
                <Grid
118
                    item
119
                    xs={12}
120
                    md={12}
121
                    style={{
122
                        minHeight: '60vh',
123
                        maxHeight: '100vh',
124
                        width: '100%',
125
                    }}
126
                >
127
                    <MapContainer
128
                        center={[mapCenter[0], mapCenter[1]]}
129
                        zoom={mapConfig.defaultZoom}
130
                        style={{ height: '100%', minHeight: '100%' }}
131
                    >
132
                        <TileLayer
133
                            attribution={mapConfig.attribution}
134
                            url={mapConfig.url}
135
                        />
136
                        {pathVariants?.map((pathVariant, idx) => (
137
                            <MapPath pathVariant={pathVariant} idx={idx} />
138
                        ))}
139
                    </MapContainer>
140
                    {pathDto && (
141
                        <Fragment>
142
                            <Card variant="outlined" sx={{ mt: 2 }}>
143
                                <CardContent>
144
                                    <Stack direction="column">
145
                                        <Typography
146
                                            variant="h5"
147
                                            sx={{ mb: 1 }}
148
                                            fontWeight="600"
149
                                        >
150
                                            Processed Text
151
                                        </Typography>
152
                                        <Typography variant="body2">
153
                                            {formatHtmlStringToReactDom(
154
                                                pathDto.text ?? ''
155
                                            )}
156
                                        </Typography>
157
                                    </Stack>
158
                                </CardContent>
159
                            </Card>
160
                        </Fragment>
161
                    )}
162
                </Grid>
163
            </Grid>
164
        </Fragment>
165
    )
104
        <Grid
105
          item
106
          xs={12}
107
          md={12}
108
          style={{
109
            minHeight: "60vh",
110
            maxHeight: "100vh",
111
            width: "100%",
112
          }}
113
        >
114
          <MapContainer
115
            center={[mapCenter[0], mapCenter[1]]}
116
            zoom={mapConfig.defaultZoom}
117
            style={{ height: "100%", minHeight: "100%" }}
118
          >
119
            <TileLayer
120
              attribution={mapConfig.attribution}
121
              url={mapConfig.url}
122
            />
123
            {pathVariants?.map((pathVariant, idx) => (
124
              <MapPath idx={idx} />
125
            ))}
126
          </MapContainer>
127
          {pathDto && (
128
            <Fragment>
129
              <Card variant="outlined" sx={{ mt: 2 }}>
130
                <CardContent>
131
                  <Stack direction="column">
132
                    <Typography variant="h5" sx={{ mb: 1 }} fontWeight="600">
133
                      Processed Text
134
                    </Typography>
135
                    <Typography variant="body2">
136
                      {formatHtmlStringToReactDom(pathDto.text ?? "")}
137
                    </Typography>
138
                  </Stack>
139
                </CardContent>
140
              </Card>
141
            </Fragment>
142
          )}
143
        </Grid>
144
      </Grid>
145
    </Fragment>
146
  )
166 147
}
167 148

  
168 149
export default TrackingTool

Také k dispozici: Unified diff