diff options
-rw-r--r-- | modern/.eslintrc.js | 2 | ||||
-rw-r--r-- | modern/package.json | 10 | ||||
-rw-r--r-- | modern/src/common/components/LocalizationProvider.js | 114 | ||||
-rw-r--r-- | modern/src/index.js | 20 | ||||
-rw-r--r-- | modern/src/settings/NotificationPage.js | 102 |
5 files changed, 126 insertions, 122 deletions
diff --git a/modern/.eslintrc.js b/modern/.eslintrc.js index f380f4c6..6cef63d8 100644 --- a/modern/.eslintrc.js +++ b/modern/.eslintrc.js @@ -15,7 +15,9 @@ module.exports = { 'no-prototype-builtins': [0], 'no-nested-ternary': [0], 'operator-linebreak': [0], + 'import/no-unresolved': [0], 'react/jsx-filename-extension': [1, { extensions: ['.js'] }], + 'react/function-component-definition': [1, { namedComponents: 'arrow-function', unnamedComponents: 'arrow-function' }], 'react/prop-types': [0], 'react/jsx-props-no-spreading': [0], 'jsx-a11y/anchor-is-valid': [0], diff --git a/modern/package.json b/modern/package.json index 771a786b..3f28ef5f 100644 --- a/modern/package.json +++ b/modern/package.json @@ -50,10 +50,10 @@ ] }, "devDependencies": { - "eslint": "^7.30.0", - "eslint-config-airbnb": "^18.2.1", - "eslint-plugin-import": "^2.23.4", - "eslint-plugin-react": "^7.24.0", - "eslint-plugin-react-hooks": "^1.7.0" + "eslint": "^8.16.0", + "eslint-config-airbnb": "^19.0.4", + "eslint-plugin-import": "^2.26.0", + "eslint-plugin-react": "^7.30.0", + "eslint-plugin-react-hooks": "^4.5.0" } } diff --git a/modern/src/common/components/LocalizationProvider.js b/modern/src/common/components/LocalizationProvider.js index 0df242dc..bcddd1b2 100644 --- a/modern/src/common/components/LocalizationProvider.js +++ b/modern/src/common/components/LocalizationProvider.js @@ -1,60 +1,60 @@ import React, { createContext, useContext, useMemo } from 'react'; -import usePersistedState from '../util/usePersistedState'; -import af from '../../../../web/l10n/af.json'; -import ar from '../../../../web/l10n/ar.json'; -import az from '../../../../web/l10n/az.json'; -import bg from '../../../../web/l10n/bg.json'; -import bn from '../../../../web/l10n/bn.json'; -import cs from '../../../../web/l10n/cs.json'; -import da from '../../../../web/l10n/da.json'; -import de from '../../../../web/l10n/de.json'; -import el from '../../../../web/l10n/el.json'; -import en from '../../../../web/l10n/en.json'; -import es from '../../../../web/l10n/es.json'; -import fa from '../../../../web/l10n/fa.json'; -import fi from '../../../../web/l10n/fi.json'; -import fr from '../../../../web/l10n/fr.json'; -import he from '../../../../web/l10n/he.json'; -import hi from '../../../../web/l10n/hi.json'; -import hr from '../../../../web/l10n/hr.json'; -import hu from '../../../../web/l10n/hu.json'; -import id from '../../../../web/l10n/id.json'; -import it from '../../../../web/l10n/it.json'; -import ja from '../../../../web/l10n/ja.json'; -import ka from '../../../../web/l10n/ka.json'; -import kk from '../../../../web/l10n/kk.json'; -import km from '../../../../web/l10n/km.json'; -import ko from '../../../../web/l10n/ko.json'; -import lo from '../../../../web/l10n/lo.json'; -import lt from '../../../../web/l10n/lt.json'; -import lv from '../../../../web/l10n/lv.json'; -import ml from '../../../../web/l10n/ml.json'; -import mn from '../../../../web/l10n/mn.json'; -import ms from '../../../../web/l10n/ms.json'; -import nb from '../../../../web/l10n/nb.json'; -import ne from '../../../../web/l10n/ne.json'; -import nl from '../../../../web/l10n/nl.json'; -import nn from '../../../../web/l10n/nn.json'; -import pl from '../../../../web/l10n/pl.json'; -import pt from '../../../../web/l10n/pt.json'; -import ptBR from '../../../../web/l10n/pt_BR.json'; -import ro from '../../../../web/l10n/ro.json'; -import ru from '../../../../web/l10n/ru.json'; -import si from '../../../../web/l10n/si.json'; -import sk from '../../../../web/l10n/sk.json'; -import sl from '../../../../web/l10n/sl.json'; -import sq from '../../../../web/l10n/sq.json'; -import sr from '../../../../web/l10n/sr.json'; -import sv from '../../../../web/l10n/sv.json'; -import ta from '../../../../web/l10n/ta.json'; -import th from '../../../../web/l10n/th.json'; -import tr from '../../../../web/l10n/tr.json'; -import uk from '../../../../web/l10n/uk.json'; -import uz from '../../../../web/l10n/uz.json'; -import vi from '../../../../web/l10n/vi.json'; -import zh from '../../../../web/l10n/zh.json'; -import zhTW from '../../../../web/l10n/zh_TW.json'; +import af from 'traccar-web/web/l10n/af.json'; +import ar from 'traccar-web/web/l10n/ar.json'; +import az from 'traccar-web/web/l10n/az.json'; +import bg from 'traccar-web/web/l10n/bg.json'; +import bn from 'traccar-web/web/l10n/bn.json'; +import cs from 'traccar-web/web/l10n/cs.json'; +import da from 'traccar-web/web/l10n/da.json'; +import de from 'traccar-web/web/l10n/de.json'; +import el from 'traccar-web/web/l10n/el.json'; +import en from 'traccar-web/web/l10n/en.json'; +import es from 'traccar-web/web/l10n/es.json'; +import fa from 'traccar-web/web/l10n/fa.json'; +import fi from 'traccar-web/web/l10n/fi.json'; +import fr from 'traccar-web/web/l10n/fr.json'; +import he from 'traccar-web/web/l10n/he.json'; +import hi from 'traccar-web/web/l10n/hi.json'; +import hr from 'traccar-web/web/l10n/hr.json'; +import hu from 'traccar-web/web/l10n/hu.json'; +import id from 'traccar-web/web/l10n/id.json'; +import it from 'traccar-web/web/l10n/it.json'; +import ja from 'traccar-web/web/l10n/ja.json'; +import ka from 'traccar-web/web/l10n/ka.json'; +import kk from 'traccar-web/web/l10n/kk.json'; +import km from 'traccar-web/web/l10n/km.json'; +import ko from 'traccar-web/web/l10n/ko.json'; +import lo from 'traccar-web/web/l10n/lo.json'; +import lt from 'traccar-web/web/l10n/lt.json'; +import lv from 'traccar-web/web/l10n/lv.json'; +import ml from 'traccar-web/web/l10n/ml.json'; +import mn from 'traccar-web/web/l10n/mn.json'; +import ms from 'traccar-web/web/l10n/ms.json'; +import nb from 'traccar-web/web/l10n/nb.json'; +import ne from 'traccar-web/web/l10n/ne.json'; +import nl from 'traccar-web/web/l10n/nl.json'; +import nn from 'traccar-web/web/l10n/nn.json'; +import pl from 'traccar-web/web/l10n/pl.json'; +import pt from 'traccar-web/web/l10n/pt.json'; +import ptBR from 'traccar-web/web/l10n/pt_BR.json'; +import ro from 'traccar-web/web/l10n/ro.json'; +import ru from 'traccar-web/web/l10n/ru.json'; +import si from 'traccar-web/web/l10n/si.json'; +import sk from 'traccar-web/web/l10n/sk.json'; +import sl from 'traccar-web/web/l10n/sl.json'; +import sq from 'traccar-web/web/l10n/sq.json'; +import sr from 'traccar-web/web/l10n/sr.json'; +import sv from 'traccar-web/web/l10n/sv.json'; +import ta from 'traccar-web/web/l10n/ta.json'; +import th from 'traccar-web/web/l10n/th.json'; +import tr from 'traccar-web/web/l10n/tr.json'; +import uk from 'traccar-web/web/l10n/uk.json'; +import uz from 'traccar-web/web/l10n/uz.json'; +import vi from 'traccar-web/web/l10n/vi.json'; +import zh from 'traccar-web/web/l10n/zh.json'; +import zhTW from 'traccar-web/web/l10n/zh_TW.json'; +import usePersistedState from '../util/usePersistedState'; const languages = { af: { data: af, name: 'Afrikaans' }, @@ -143,8 +143,10 @@ const LocalizationContext = createContext({ export const LocalizationProvider = ({ children }) => { const [language, setLanguage] = usePersistedState('language', getDefaultLanguage()); + const value = useMemo(() => ({ languages, language, setLanguage }), [languages, language, setLanguage]); + return ( - <LocalizationContext.Provider value={{ languages, language, setLanguage }}> + <LocalizationContext.Provider value={value}> {children} </LocalizationContext.Provider> ); diff --git a/modern/src/index.js b/modern/src/index.js index cb6710d5..43462d35 100644 --- a/modern/src/index.js +++ b/modern/src/index.js @@ -11,14 +11,16 @@ import { LocalizationProvider } from './common/components/LocalizationProvider'; const base = window.location.href.indexOf('modern') >= 0 ? '/modern' : null; -ReactDOM.render(( - <Provider store={store}> - <LocalizationProvider> - <BrowserRouter basename={base}> - <App /> - </BrowserRouter> - </LocalizationProvider> - </Provider> -), document.getElementById('root')); +ReactDOM.render( + ( + <Provider store={store}> + <LocalizationProvider> + <BrowserRouter basename={base}> + <App /> + </BrowserRouter> + </LocalizationProvider> + </Provider> + ), document.getElementById('root'), +); serviceWorker.register(); diff --git a/modern/src/settings/NotificationPage.js b/modern/src/settings/NotificationPage.js index 38ba19e5..0533b58e 100644 --- a/modern/src/settings/NotificationPage.js +++ b/modern/src/settings/NotificationPage.js @@ -39,60 +39,58 @@ const NotificationPage = () => { breadcrumbs={['settingsTitle', 'sharedNotification']} > {item && ( - <> - <Accordion defaultExpanded> - <AccordionSummary expandIcon={<ExpandMoreIcon />}> - <Typography variant="subtitle1"> - {t('sharedRequired')} - </Typography> - </AccordionSummary> - <AccordionDetails className={classes.details}> - <SelectField - margin="normal" - value={item.type} - emptyValue={null} - onChange={(e) => setItem({ ...item, type: e.target.value })} - endpoint="/api/notifications/types" - keyGetter={(it) => it.type} - titleGetter={(it) => t(prefixString('event', it.type))} - label={t('sharedType')} - variant="filled" - /> - <SelectField - multiple - margin="normal" - value={item.notificators ? item.notificators.split(/[, ]+/) : []} - onChange={(e) => setItem({ ...item, notificators: e.target.value.join() })} - endpoint="/api/notifications/notificators" - keyGetter={(it) => it.type} - titleGetter={(it) => t(prefixString('notificator', it.type))} - label={t('notificationNotificators')} - variant="filled" - /> - {(!item.type || item.type === 'alarm') && ( - <SelectField - multiple - margin="normal" - value={item.attributes && item.attributes.alarms ? item.attributes.alarms.split(/[, ]+/) : []} - onChange={(e) => setItem({ ...item, attributes: { ...item.attributes, alarms: e.target.value.join() } })} - data={alarms} - keyGetter={(it) => it.key} - label={t('sharedAlarms')} - variant="filled" + <Accordion defaultExpanded> + <AccordionSummary expandIcon={<ExpandMoreIcon />}> + <Typography variant="subtitle1"> + {t('sharedRequired')} + </Typography> + </AccordionSummary> + <AccordionDetails className={classes.details}> + <SelectField + margin="normal" + value={item.type} + emptyValue={null} + onChange={(e) => setItem({ ...item, type: e.target.value })} + endpoint="/api/notifications/types" + keyGetter={(it) => it.type} + titleGetter={(it) => t(prefixString('event', it.type))} + label={t('sharedType')} + variant="filled" + /> + <SelectField + multiple + margin="normal" + value={item.notificators ? item.notificators.split(/[, ]+/) : []} + onChange={(e) => setItem({ ...item, notificators: e.target.value.join() })} + endpoint="/api/notifications/notificators" + keyGetter={(it) => it.type} + titleGetter={(it) => t(prefixString('notificator', it.type))} + label={t('notificationNotificators')} + variant="filled" + /> + {(!item.type || item.type === 'alarm') && ( + <SelectField + multiple + margin="normal" + value={item.attributes && item.attributes.alarms ? item.attributes.alarms.split(/[, ]+/) : []} + onChange={(e) => setItem({ ...item, attributes: { ...item.attributes, alarms: e.target.value.join() } })} + data={alarms} + keyGetter={(it) => it.key} + label={t('sharedAlarms')} + variant="filled" + /> + )} + <FormControlLabel + control={( + <Checkbox + checked={item.always} + onChange={(event) => setItem({ ...item, always: event.target.checked })} /> - )} - <FormControlLabel - control={( - <Checkbox - checked={item.always} - onChange={(event) => setItem({ ...item, always: event.target.checked })} - /> )} - label={t('notificationAlways')} - /> - </AccordionDetails> - </Accordion> - </> + label={t('notificationAlways')} + /> + </AccordionDetails> + </Accordion> )} </EditItemView> ); |