Projekt

Obecné

Profil

Stáhnout (4.17 KB) Statistiky
| Větev: | Tag: | Revize:
1
import { Checkbox, FormControlLabel, Stack, Typography } from '@mui/material'
2
import { useEffect, useState } from 'react'
3
import { useDispatch, useSelector } from 'react-redux'
4
import { RootState } from '../../redux/store'
5
import { updatePrimaryPath } from '../trackingToolSlice'
6
import { MapPointType, PathVariant } from '../trackingToolUtils'
7

    
8
const MapPointToggleables = () => {
9
    const dispatch = useDispatch()
10
    const paths = useSelector(
11
        (state: RootState) => state.trackingTool.pathVariants
12
    )
13
    const [path, setPath] = useState<PathVariant>([])
14
    const primaryPathIdx = useSelector(
15
        (state: RootState) => state.trackingTool.primaryPathIdx
16
    )
17
    useEffect(() => {
18
        setPath(
19
            paths && paths.length > primaryPathIdx ? paths[primaryPathIdx] : []
20
        )
21
    }, [paths, primaryPathIdx])
22

    
23
    const [enableMap, setEnableMap] = useState({
24
        [MapPointType.LocalCatalog]: true,
25
        [MapPointType.FromCoordinates]: true,
26
        [MapPointType.GeoJson]: true,
27
        [MapPointType.ExternalCatalog]: true,
28
    })
29

    
30
    // Disables specific feature
31
    const toggleFeature = (feature: MapPointType) => {
32
        setEnableMap({ ...enableMap, [feature]: !enableMap[feature] })
33
        const newPath = path.map((point) => {
34
            if (point.type === feature) {
35
                return {
36
                    ...point,
37
                    hidden: enableMap[point.type],
38
                    addToPath: !enableMap[point.type] ? true : point.addToPath,
39
                }
40
            }
41

    
42
            return point
43
        })
44
        dispatch(updatePrimaryPath(newPath))
45
    }
46

    
47
    return (
48
        <Stack direction="column">
49
            <Stack direction="row" justifyItems="space-between">
50
                <Typography align="left" variant="h6" sx={{ mr: 1 }}>
51
                    From file
52
                </Typography>
53
                <FormControlLabel
54
                    control={
55
                        <Checkbox
56
                            checked={enableMap[MapPointType.GeoJson]}
57
                            onChange={() => toggleFeature(MapPointType.GeoJson)}
58
                        />
59
                    }
60
                    label="Show All"
61
                />
62
            </Stack>
63
            <Stack direction="row" justifyItems="space-between">
64
                <Typography align="left" variant="h6" sx={{ mr: 1 }}>
65
                    From local catalog
66
                </Typography>
67
                <FormControlLabel
68
                    control={
69
                        <Checkbox
70
                            checked={enableMap[MapPointType.LocalCatalog]}
71
                            onChange={() =>
72
                                toggleFeature(MapPointType.LocalCatalog)
73
                            }
74
                        />
75
                    }
76
                    label="Show All"
77
                />
78
            </Stack>
79
            <Stack direction="row" justifyItems="space-between">
80
                <Typography align="left" variant="h6" sx={{ mr: 1 }}>
81
                    From coordinates
82
                </Typography>
83
                <FormControlLabel
84
                    control={
85
                        <Checkbox
86
                            checked={enableMap[MapPointType.FromCoordinates]}
87
                            onChange={() =>
88
                                toggleFeature(MapPointType.FromCoordinates)
89
                            }
90
                        />
91
                    }
92
                    label="Show All"
93
                />
94
            </Stack>
95
            <Stack direction="row" justifyItems="space-between">
96
                <Typography align="left" variant="h6" sx={{ mr: 1 }}>
97
                    From external catalog
98
                </Typography>
99
                <FormControlLabel
100
                    control={
101
                        <Checkbox
102
                            checked={enableMap[MapPointType.ExternalCatalog]}
103
                            onChange={() =>
104
                                toggleFeature(MapPointType.ExternalCatalog)
105
                            }
106
                        />
107
                    }
108
                    label="Show All"
109
                />
110
            </Stack>
111
        </Stack>
112
    )
113
}
114

    
115
export default MapPointToggleables
(4-4/5)