Projekt

Obecné

Profil

« Předchozí | Další » 

Revize dd270a41

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

path autorefresh works as intended

re #9629

Zobrazit rozdíly:

frontend/src/features/TrackingTool/MapPath.tsx
3 3
import { PathVariant } from './buildPathVariants'
4 4
import TextPath from 'react-leaflet-textpath'
5 5
import { Marker, Popup } from 'react-leaflet'
6
import { Checkbox, FormControlLabel, Stack, Typography } from '@mui/material'
6
import {
7
    Checkbox,
8
    FormControlLabel,
9
    Paper,
10
    Stack,
11
    Typography,
12
} from '@mui/material'
7 13
import { formatHtmlStringToReactDom } from '../../utils/formatting/HtmlUtils'
8 14
import { DialogCatalogItemDetail as CatalogItemDetailDialog } from '../Catalog/CatalogItemDetail'
9 15
import { useDispatch, useSelector } from 'react-redux'
......
31 37
// Map path component
32 38
const MapPath: FunctionComponent<MapPathProps> = ({ idx, pathVariant }) => {
33 39
    // List of all map points that belong to the path
34
    const [mapPoints, setMapPoints] = useState<DisplayableMapPoint[]>(
35
        pathVariant
36
            .filter((item) => item.latitude && item.longitude)
37
            .map((item) => new DisplayableMapPoint(item))
40
    const pathVariants = useSelector(
41
        (state: RootState) => state.trackingTool.pathVariants
38 42
    )
43
    const [mapPoints, setMapPoints] = useState<DisplayableMapPoint[]>([])
44
    const dispatch = useDispatch()
39 45

  
40 46
    // Set of all active paths
41 47
    const activePaths = useSelector(
......
54 60

  
55 61
    const getActiveMapPoints = () => mapPoints.filter((item) => item.active)
56 62

  
57
    const dispatch = useDispatch()
63
    // Refresh the list of map points if it has changed
64
    useEffect(() => {
65
        if (!pathVariants || pathVariants.length <= idx) {
66
            return
67
        }
68
        setMapPoints(
69
            [...pathVariants[idx]]
70
                .filter((item) => item.latitude && item.longitude)
71
                .map((item) => new DisplayableMapPoint(item))
72
        )
73
    }, [pathVariants, idx])
58 74

  
59 75
    // Builds all edges of the path
60 76
    const buildEdges = () => {
frontend/src/features/TrackingTool/TrackingTool.tsx
18 18
import { formatHtmlStringToReactDom } from '../../utils/formatting/HtmlUtils'
19 19
import MapPath from './MapPath'
20 20
import EditIcon from '@mui/icons-material/Edit'
21
import { useSelector } from 'react-redux'
21
import { useDispatch, useSelector } from 'react-redux'
22 22
import { RootState } from '../redux/store'
23
import { consumeErr as consumeError } from './trackingToolSlice'
24
import { showNotification } from '../Notification/notificationSlice'
23 25

  
24 26
// Page with tracking tool
25 27
const TrackingTool = () => {
......
35 37
    //     map.flyTo(mapCenter, mapConfig.defaultZoom)
36 38
    // }, [map, mapCenter])
37 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])
38 57

  
39 58
    return (
40 59
        <Fragment>
......
118 137
                            attribution={mapConfig.attribution}
119 138
                            url={mapConfig.url}
120 139
                        />
121
                        {pathVariants &&
122
                            pathVariants.map((pathVariant, idx) => (
123
                                <MapPath
124
                                    key={idx}
125
                                    pathVariant={pathVariant}
126
                                    idx={idx}
127
                                />
128
                            ))}
140
                        {pathVariants?.map((pathVariant, idx) => (
141
                            <MapPath
142
                                pathVariant={pathVariant}
143
                                idx={idx} />
144
                        ))}
129 145
                    </MapContainer>
130 146
                </Grid>
131 147
            </Grid>
frontend/src/features/TrackingTool/trackingToolSlice.ts
9 9
    isLoading: boolean // whether the data is being loaded
10 10
    pathDto?: PathDto // the data
11 11
    pathVariants?: PathVariant[] // undefined signals that no path variants were yet fetched from the API
12
    lastErr?: string // consumable for errors during thunks
12
    lastError?: string // consumable for errors during thunks
13 13
    mapCenter: LatLngTuple // pair of latitude and longitude
14 14
    primaryPathIdx: number // index of the primary path
15 15
    activePaths: Set<number> // indices of the active paths
......
70 70
        })
71 71
        builder.addCase(sendTextForProcessing.rejected, (state, action) => ({
72 72
            ...initialState,
73
            lastErr: action.error.message,
73
            lastError: action.error.message,
74 74
            isLoading: false,
75 75
            dialogApiCallSuccess: false,
76 76
        }))
frontend/src/features/TrackingTool/trackingToolThunks.ts
13 13
            }
14 14
            return data
15 15
        } catch (err: any) {
16
            console.log(err)
16 17
            return Promise.reject('Error, server is currently unavailable')
17 18
        }
18 19
    }

Také k dispozici: Unified diff