aboutsummaryrefslogtreecommitdiff
path: root/modern
diff options
context:
space:
mode:
authorAnton Tananaev <anton@traccar.org>2022-10-28 17:08:59 -0700
committerAnton Tananaev <anton@traccar.org>2022-10-28 17:08:59 -0700
commit6a4eba7b63c84c20188b8a6b16f6107698bfde91 (patch)
treee486dbb32afadee5c2e2c7151d963871820eeb4f /modern
parent17b990eabe36138a4a879deef8d03b16ee27e1ba (diff)
downloadtrackermap-web-6a4eba7b63c84c20188b8a6b16f6107698bfde91.tar.gz
trackermap-web-6a4eba7b63c84c20188b8a6b16f6107698bfde91.tar.bz2
trackermap-web-6a4eba7b63c84c20188b8a6b16f6107698bfde91.zip
Move positions to session
Diffstat (limited to 'modern')
-rw-r--r--modern/src/SocketController.js6
-rw-r--r--modern/src/main/DeviceRow.js2
-rw-r--r--modern/src/main/MainPage.js2
-rw-r--r--modern/src/map/main/MapDefaultCamera.js2
-rw-r--r--modern/src/map/main/MapLiveRoutes.js2
-rw-r--r--modern/src/map/main/MapSelectedDevice.js2
-rw-r--r--modern/src/settings/AccumulatorsPage.js2
-rw-r--r--modern/src/store/index.js3
-rw-r--r--modern/src/store/positions.js16
-rw-r--r--modern/src/store/session.js4
10 files changed, 13 insertions, 28 deletions
diff --git a/modern/src/SocketController.js b/modern/src/SocketController.js
index 970298c3..521ad54d 100644
--- a/modern/src/SocketController.js
+++ b/modern/src/SocketController.js
@@ -2,7 +2,7 @@ import React, { useEffect, useRef, useState } from 'react';
import { useDispatch, useSelector, connect } from 'react-redux';
import { Snackbar } from '@mui/material';
-import { positionsActions, devicesActions, sessionActions } from './store';
+import { devicesActions, sessionActions } from './store';
import { useEffectAsync } from './reactHelper';
import { useTranslation } from './common/components/LocalizationProvider';
import { snackBarDurationLongMs } from './common/util/duration';
@@ -52,7 +52,7 @@ const SocketController = () => {
headers: { 'Content-Type': 'application/json' },
});
if (positionsResponse.ok) {
- dispatch(positionsActions.update(await positionsResponse.json()));
+ dispatch(sessionActions.updatePositions(await positionsResponse.json()));
}
} catch (error) {
// ignore errors
@@ -67,7 +67,7 @@ const SocketController = () => {
dispatch(devicesActions.update(data.devices));
}
if (data.positions) {
- dispatch(positionsActions.update(data.positions));
+ dispatch(sessionActions.updatePositions(data.positions));
}
if (data.events) {
if (!features.disableEvents) {
diff --git a/modern/src/main/DeviceRow.js b/modern/src/main/DeviceRow.js
index 5699c274..dbe5df6e 100644
--- a/modern/src/main/DeviceRow.js
+++ b/modern/src/main/DeviceRow.js
@@ -55,7 +55,7 @@ const DeviceRow = ({ data, index, style }) => {
const admin = useAdministrator();
const item = data[index];
- const position = useSelector((state) => state.positions.items[item.id]);
+ const position = useSelector((state) => state.session.positions[item.id]);
const geofences = useSelector((state) => state.geofences.items);
diff --git a/modern/src/main/MainPage.js b/modern/src/main/MainPage.js
index 0655fa92..f5d6d25b 100644
--- a/modern/src/main/MainPage.js
+++ b/modern/src/main/MainPage.js
@@ -67,7 +67,7 @@ const MainPage = () => {
const mapOnSelect = useAttributePreference('mapOnSelect', true);
const selectedDeviceId = useSelector((state) => state.devices.selectedId);
- const positions = useSelector((state) => state.positions.items);
+ const positions = useSelector((state) => state.session.positions);
const [filteredPositions, setFilteredPositions] = useState([]);
const selectedPosition = filteredPositions.find((position) => selectedDeviceId && position.deviceId === selectedDeviceId);
diff --git a/modern/src/map/main/MapDefaultCamera.js b/modern/src/map/main/MapDefaultCamera.js
index f6b6ed9c..90b3061b 100644
--- a/modern/src/map/main/MapDefaultCamera.js
+++ b/modern/src/map/main/MapDefaultCamera.js
@@ -6,7 +6,7 @@ import { map } from '../core/MapView';
const MapDefaultCamera = () => {
const selectedDeviceId = useSelector((state) => state.devices.selectedId);
- const positions = useSelector((state) => state.positions.items);
+ const positions = useSelector((state) => state.session.positions);
const defaultLatitude = usePreference('latitude');
const defaultLongitude = usePreference('longitude');
diff --git a/modern/src/map/main/MapLiveRoutes.js b/modern/src/map/main/MapLiveRoutes.js
index d0f67a73..55a04606 100644
--- a/modern/src/map/main/MapLiveRoutes.js
+++ b/modern/src/map/main/MapLiveRoutes.js
@@ -15,7 +15,7 @@ const MapLiveRoutes = () => {
const selectedDeviceId = useSelector((state) => state.devices.selectedId);
const currentDeviceId = usePrevious(selectedDeviceId);
- const position = useSelector((state) => state.positions.items[selectedDeviceId]);
+ const position = useSelector((state) => state.session.positions[selectedDeviceId]);
const [route, setRoute] = useState([]);
diff --git a/modern/src/map/main/MapSelectedDevice.js b/modern/src/map/main/MapSelectedDevice.js
index 3f444409..caf40cf8 100644
--- a/modern/src/map/main/MapSelectedDevice.js
+++ b/modern/src/map/main/MapSelectedDevice.js
@@ -13,7 +13,7 @@ const MapSelectedDevice = () => {
const selectZoom = useAttributePreference('web.selectZoom', 10);
const mapFollow = useAttributePreference('mapFollow', false);
- const position = useSelector((state) => state.positions.items[selectedDeviceId]);
+ const position = useSelector((state) => state.session.positions[selectedDeviceId]);
useEffect(() => {
if ((selectedDeviceId !== previousDeviceId || mapFollow) && position) {
diff --git a/modern/src/settings/AccumulatorsPage.js b/modern/src/settings/AccumulatorsPage.js
index 363bc376..5067e4fd 100644
--- a/modern/src/settings/AccumulatorsPage.js
+++ b/modern/src/settings/AccumulatorsPage.js
@@ -48,7 +48,7 @@ const AccumulatorsPage = () => {
const distanceUnit = useAttributePreference('distanceUnit');
const { deviceId } = useParams();
- const position = useSelector((state) => state.positions.items[deviceId]);
+ const position = useSelector((state) => state.session.positions[deviceId]);
const [item, setItem] = useState();
diff --git a/modern/src/store/index.js b/modern/src/store/index.js
index 71c0b2b8..0cc32d38 100644
--- a/modern/src/store/index.js
+++ b/modern/src/store/index.js
@@ -3,7 +3,6 @@ import { combineReducers, configureStore } from '@reduxjs/toolkit';
import { errorsReducer as errors } from './errors';
import { sessionReducer as session } from './session';
import { devicesReducer as devices } from './devices';
-import { positionsReducer as positions } from './positions';
import { eventsReducer as events } from './events';
import { geofencesReducer as geofences } from './geofences';
import { groupsReducer as groups } from './groups';
@@ -16,7 +15,6 @@ const reducer = combineReducers({
errors,
session,
devices,
- positions,
events,
geofences,
groups,
@@ -28,7 +26,6 @@ const reducer = combineReducers({
export { errorsActions } from './errors';
export { sessionActions } from './session';
export { devicesActions } from './devices';
-export { positionsActions } from './positions';
export { eventsActions } from './events';
export { geofencesActions } from './geofences';
export { groupsActions } from './groups';
diff --git a/modern/src/store/positions.js b/modern/src/store/positions.js
deleted file mode 100644
index 8858298d..00000000
--- a/modern/src/store/positions.js
+++ /dev/null
@@ -1,16 +0,0 @@
-import { createSlice } from '@reduxjs/toolkit';
-
-const { reducer, actions } = createSlice({
- name: 'positions',
- initialState: {
- items: {},
- },
- reducers: {
- update(state, action) {
- action.payload.forEach((item) => state.items[item.deviceId] = item);
- },
- },
-});
-
-export { actions as positionsActions };
-export { reducer as positionsReducer };
diff --git a/modern/src/store/session.js b/modern/src/store/session.js
index 88d1eb44..74dc29a0 100644
--- a/modern/src/store/session.js
+++ b/modern/src/store/session.js
@@ -6,6 +6,7 @@ const { reducer, actions } = createSlice({
server: null,
user: null,
socket: null,
+ positions: {},
},
reducers: {
updateServer(state, action) {
@@ -17,6 +18,9 @@ const { reducer, actions } = createSlice({
updateSocket(state, action) {
state.socket = action.payload;
},
+ updatePositions(state, action) {
+ action.payload.forEach((position) => state.positions[position.deviceId] = position);
+ },
},
});