aboutsummaryrefslogtreecommitdiff
path: root/modern/src/SocketController.js
diff options
context:
space:
mode:
authorAnton Tananaev <anton@traccar.org>2022-10-28 13:28:28 -0700
committerAnton Tananaev <anton@traccar.org>2022-10-28 13:28:28 -0700
commitfac80024e0956d543b762296e0ee49cd72035b93 (patch)
tree41074dddc57d0c4fdb1b7162b1c3d74633e4ea31 /modern/src/SocketController.js
parentef315b8e10329db80da1a97e96b3cc82481370ae (diff)
downloadtrackermap-web-fac80024e0956d543b762296e0ee49cd72035b93.tar.gz
trackermap-web-fac80024e0956d543b762296e0ee49cd72035b93.tar.bz2
trackermap-web-fac80024e0956d543b762296e0ee49cd72035b93.zip
Persist user preferences
Diffstat (limited to 'modern/src/SocketController.js')
-rw-r--r--modern/src/SocketController.js14
1 files changed, 3 insertions, 11 deletions
diff --git a/modern/src/SocketController.js b/modern/src/SocketController.js
index 87b842fa..970298c3 100644
--- a/modern/src/SocketController.js
+++ b/modern/src/SocketController.js
@@ -1,23 +1,21 @@
import React, { useEffect, useRef, useState } from 'react';
import { useDispatch, useSelector, connect } from 'react-redux';
import { Snackbar } from '@mui/material';
-import { useNavigate } from 'react-router-dom';
import { positionsActions, devicesActions, sessionActions } from './store';
import { useEffectAsync } from './reactHelper';
import { useTranslation } from './common/components/LocalizationProvider';
import { snackBarDurationLongMs } from './common/util/duration';
-import usePersistedState from './common/util/usePersistedState';
import alarm from './resources/alarm.mp3';
import { eventsActions } from './store/events';
import useFeatures from './common/util/useFeatures';
+import { useAttributePreference } from './common/util/preferences';
const logoutCode = 4000;
const SocketController = () => {
const dispatch = useDispatch();
- const navigate = useNavigate();
const t = useTranslation();
const authenticated = useSelector((state) => !!state.session.user);
@@ -28,8 +26,8 @@ const SocketController = () => {
const [events, setEvents] = useState([]);
const [notifications, setNotifications] = useState([]);
- const [soundEvents] = usePersistedState('soundEvents', []);
- const [soundAlarms] = usePersistedState('soundAlarms', ['sos']);
+ const soundEvents = useAttributePreference('soundEvents', '');
+ const soundAlarms = useAttributePreference('soundAlarms', 'sos');
const features = useFeatures();
@@ -96,12 +94,6 @@ const SocketController = () => {
}
};
}
- const response = await fetch('/api/session');
- if (response.ok) {
- dispatch(sessionActions.updateUser(await response.json()));
- } else {
- navigate('/login');
- }
return null;
}, [authenticated]);