1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
|
import React from 'react';
import {
Accordion,
AccordionSummary,
AccordionDetails,
Typography,
Container,
FormControl,
InputLabel,
Select,
MenuItem,
Checkbox,
FormControlLabel,
FormGroup,
} from '@mui/material';
import makeStyles from '@mui/styles/makeStyles';
import ExpandMoreIcon from '@mui/icons-material/ExpandMore';
import { useLocalization, useTranslation, useTranslationKeys } from '../common/components/LocalizationProvider';
import usePersistedState from '../common/util/usePersistedState';
import PageLayout from '../common/components/PageLayout';
import SettingsMenu from './components/SettingsMenu';
import usePositionAttributes from '../common/attributes/usePositionAttributes';
import { prefixString, unprefixString } from '../common/util/stringUtils';
import SelectField from '../common/components/SelectField';
const useStyles = makeStyles((theme) => ({
container: {
marginTop: theme.spacing(2),
},
details: {
display: 'flex',
flexDirection: 'column',
gap: theme.spacing(2),
paddingBottom: theme.spacing(3),
},
}));
const PreferencesPage = () => {
const classes = useStyles();
const t = useTranslation();
const { languages, language, setLanguage } = useLocalization();
const languageList = Object.entries(languages).map((values) => ({ code: values[0], name: values[1].name }));
const positionAttributes = usePositionAttributes(t);
const [positionItems, setPositionItems] = usePersistedState('positionItems', ['speed', 'address', 'totalDistance', 'course']);
const [mapLiveRoutes, setMapLiveRoutes] = usePersistedState('mapLiveRoutes', false);
const [mapFollow, setMapFollow] = usePersistedState('mapFollow', false);
const [mapCluster, setMapCluster] = usePersistedState('mapCluster', true);
const [mapMapOnSelect, setMapOnSelect] = usePersistedState('mapOnSelect', false);
const alarms = useTranslationKeys((it) => it.startsWith('alarm')).map((it) => ({
key: unprefixString('alarm', it),
name: t(it),
}));
const [soundEvents, setSoundEvents] = usePersistedState('soundEvents', []);
const [soundAlarms, setSoundAlarms] = usePersistedState('soundAlarms', ['sos']);
return (
<PageLayout menu={<SettingsMenu />} breadcrumbs={['settingsTitle', 'sharedPreferences']}>
<Container maxWidth="xs" className={classes.container}>
<Accordion defaultExpanded>
<AccordionSummary expandIcon={<ExpandMoreIcon />}>
<Typography variant="subtitle1">
{t('sharedPreferences')}
</Typography>
</AccordionSummary>
<AccordionDetails className={classes.details}>
<FormControl>
<InputLabel>{t('loginLanguage')}</InputLabel>
<Select
label={t('loginLanguage')}
value={language}
onChange={(e) => setLanguage(e.target.value)}
>
{languageList.map((it) => <MenuItem key={it.code} value={it.code}>{it.name}</MenuItem>)}
</Select>
</FormControl>
</AccordionDetails>
</Accordion>
<Accordion>
<AccordionSummary expandIcon={<ExpandMoreIcon />}>
<Typography variant="subtitle1">
{t('mapTitle')}
</Typography>
</AccordionSummary>
<AccordionDetails className={classes.details}>
<FormControl>
<InputLabel>{t('sharedAttributes')}</InputLabel>
<Select
label={t('sharedAttributes')}
value={positionItems}
onChange={(e) => setPositionItems(e.target.value)}
multiple
>
{Object.keys(positionAttributes).map((key) => (
<MenuItem key={key} value={key}>{positionAttributes[key].name}</MenuItem>
))}
</Select>
</FormControl>
<FormGroup>
<FormControlLabel
control={<Checkbox checked={mapLiveRoutes} onChange={(e) => setMapLiveRoutes(e.target.checked)} />}
label={t('mapLiveRoutes')}
/>
<FormControlLabel
control={<Checkbox checked={mapFollow} onChange={(e) => setMapFollow(e.target.checked)} />}
label={t('deviceFollow')}
/>
<FormControlLabel
control={<Checkbox checked={mapCluster} onChange={(e) => setMapCluster(e.target.checked)} />}
label={t('mapClustering')}
/>
<FormControlLabel
control={<Checkbox checked={mapMapOnSelect} onChange={(e) => setMapOnSelect(e.target.checked)} />}
label={t('mapOnSelect')}
/>
</FormGroup>
</AccordionDetails>
</Accordion>
<Accordion>
<AccordionSummary expandIcon={<ExpandMoreIcon />}>
<Typography variant="subtitle1">
{t('sharedSound')}
</Typography>
</AccordionSummary>
<AccordionDetails className={classes.details}>
<SelectField
multiple
value={soundEvents}
onChange={(e) => setSoundEvents(e.target.value)}
endpoint="/api/notifications/types"
keyGetter={(it) => it.type}
titleGetter={(it) => t(prefixString('event', it.type))}
label={t('reportEventTypes')}
/>
<SelectField
multiple
value={soundAlarms}
onChange={(e) => setSoundAlarms(e.target.value)}
data={alarms}
keyGetter={(it) => it.key}
label={t('sharedAlarms')}
/>
</AccordionDetails>
</Accordion>
</Container>
</PageLayout>
);
};
export default PreferencesPage;
|