aboutsummaryrefslogtreecommitdiff
path: root/modern/src/store
diff options
context:
space:
mode:
authorAnton Tananaev <anton@traccar.org>2024-04-06 09:22:10 -0700
committerAnton Tananaev <anton@traccar.org>2024-04-06 09:22:10 -0700
commitf418231b6b2f5e030a0d2dcc390c314602b1f740 (patch)
tree10326adf3792bc2697e06bb5f2b8ef2a8f7e55fe /modern/src/store
parentb392a4af78e01c8e0f50aad5468e9583675b24be (diff)
downloadtrackermap-web-f418231b6b2f5e030a0d2dcc390c314602b1f740.tar.gz
trackermap-web-f418231b6b2f5e030a0d2dcc390c314602b1f740.tar.bz2
trackermap-web-f418231b6b2f5e030a0d2dcc390c314602b1f740.zip
Move modern to the top
Diffstat (limited to 'modern/src/store')
-rw-r--r--modern/src/store/calendars.js17
-rw-r--r--modern/src/store/devices.js36
-rw-r--r--modern/src/store/drivers.js17
-rw-r--r--modern/src/store/errors.js21
-rw-r--r--modern/src/store/events.js23
-rw-r--r--modern/src/store/geofences.js20
-rw-r--r--modern/src/store/groups.js17
-rw-r--r--modern/src/store/index.js42
-rw-r--r--modern/src/store/maintenances.js17
-rw-r--r--modern/src/store/reports.js29
-rw-r--r--modern/src/store/session.js53
-rw-r--r--modern/src/store/throttleMiddleware.js36
12 files changed, 0 insertions, 328 deletions
diff --git a/modern/src/store/calendars.js b/modern/src/store/calendars.js
deleted file mode 100644
index 2d92c004..00000000
--- a/modern/src/store/calendars.js
+++ /dev/null
@@ -1,17 +0,0 @@
-import { createSlice } from '@reduxjs/toolkit';
-
-const { reducer, actions } = createSlice({
- name: 'calendars',
- initialState: {
- items: {},
- },
- reducers: {
- refresh(state, action) {
- state.items = {};
- action.payload.forEach((item) => state.items[item.id] = item);
- },
- },
-});
-
-export { actions as calendarsActions };
-export { reducer as calendarsReducer };
diff --git a/modern/src/store/devices.js b/modern/src/store/devices.js
deleted file mode 100644
index f2f6263b..00000000
--- a/modern/src/store/devices.js
+++ /dev/null
@@ -1,36 +0,0 @@
-import { createSlice } from '@reduxjs/toolkit';
-
-const { reducer, actions } = createSlice({
- name: 'devices',
- initialState: {
- items: {},
- selectedId: null,
- selectedIds: [],
- },
- reducers: {
- refresh(state, action) {
- state.items = {};
- action.payload.forEach((item) => state.items[item.id] = item);
- },
- update(state, action) {
- action.payload.forEach((item) => state.items[item.id] = item);
- },
- select(state, action) {
- state.selectedId = action.payload;
- },
- selectId(state, action) {
- state.selectedId = action.payload;
- state.selectedIds = state.selectedId ? [state.selectedId] : [];
- },
- selectIds(state, action) {
- state.selectedIds = action.payload;
- [state.selectedId] = state.selectedIds;
- },
- remove(state, action) {
- delete state.items[action.payload];
- },
- },
-});
-
-export { actions as devicesActions };
-export { reducer as devicesReducer };
diff --git a/modern/src/store/drivers.js b/modern/src/store/drivers.js
deleted file mode 100644
index d62bd476..00000000
--- a/modern/src/store/drivers.js
+++ /dev/null
@@ -1,17 +0,0 @@
-import { createSlice } from '@reduxjs/toolkit';
-
-const { reducer, actions } = createSlice({
- name: 'drivers',
- initialState: {
- items: {},
- },
- reducers: {
- refresh(state, action) {
- state.items = {};
- action.payload.forEach((item) => state.items[item.uniqueId] = item);
- },
- },
-});
-
-export { actions as driversActions };
-export { reducer as driversReducer };
diff --git a/modern/src/store/errors.js b/modern/src/store/errors.js
deleted file mode 100644
index a484239a..00000000
--- a/modern/src/store/errors.js
+++ /dev/null
@@ -1,21 +0,0 @@
-import { createSlice } from '@reduxjs/toolkit';
-
-const { reducer, actions } = createSlice({
- name: 'errors',
- initialState: {
- errors: [],
- },
- reducers: {
- push(state, action) {
- state.errors.push(action.payload);
- },
- pop(state) {
- if (state.errors.length) {
- state.errors.shift();
- }
- },
- },
-});
-
-export { actions as errorsActions };
-export { reducer as errorsReducer };
diff --git a/modern/src/store/events.js b/modern/src/store/events.js
deleted file mode 100644
index 35e7081e..00000000
--- a/modern/src/store/events.js
+++ /dev/null
@@ -1,23 +0,0 @@
-import { createSlice } from '@reduxjs/toolkit';
-
-const { reducer, actions } = createSlice({
- name: 'events',
- initialState: {
- items: [],
- },
- reducers: {
- add(state, action) {
- state.items.unshift(...action.payload);
- state.items.splice(50);
- },
- delete(state, action) {
- state.items = state.items.filter((item) => item.id !== action.payload.id);
- },
- deleteAll(state) {
- state.items = [];
- },
- },
-});
-
-export { actions as eventsActions };
-export { reducer as eventsReducer };
diff --git a/modern/src/store/geofences.js b/modern/src/store/geofences.js
deleted file mode 100644
index f2b7666a..00000000
--- a/modern/src/store/geofences.js
+++ /dev/null
@@ -1,20 +0,0 @@
-import { createSlice } from '@reduxjs/toolkit';
-
-const { reducer, actions } = createSlice({
- name: 'geofences',
- initialState: {
- items: {},
- },
- reducers: {
- refresh(state, action) {
- state.items = {};
- action.payload.forEach((item) => state.items[item.id] = item);
- },
- update(state, action) {
- action.payload.forEach((item) => state.items[item.id] = item);
- },
- },
-});
-
-export { actions as geofencesActions };
-export { reducer as geofencesReducer };
diff --git a/modern/src/store/groups.js b/modern/src/store/groups.js
deleted file mode 100644
index 607b8609..00000000
--- a/modern/src/store/groups.js
+++ /dev/null
@@ -1,17 +0,0 @@
-import { createSlice } from '@reduxjs/toolkit';
-
-const { reducer, actions } = createSlice({
- name: 'groups',
- initialState: {
- items: {},
- },
- reducers: {
- refresh(state, action) {
- state.items = {};
- action.payload.forEach((item) => state.items[item.id] = item);
- },
- },
-});
-
-export { actions as groupsActions };
-export { reducer as groupsReducer };
diff --git a/modern/src/store/index.js b/modern/src/store/index.js
deleted file mode 100644
index ea685ff3..00000000
--- a/modern/src/store/index.js
+++ /dev/null
@@ -1,42 +0,0 @@
-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 { eventsReducer as events } from './events';
-import { geofencesReducer as geofences } from './geofences';
-import { groupsReducer as groups } from './groups';
-import { driversReducer as drivers } from './drivers';
-import { maintenancesReducer as maintenances } from './maintenances';
-import { calendarsReducer as calendars } from './calendars';
-import { reportsReducer as reports } from './reports';
-import throttleMiddleware from './throttleMiddleware';
-
-const reducer = combineReducers({
- errors,
- session,
- devices,
- events,
- geofences,
- groups,
- drivers,
- maintenances,
- calendars,
- reports,
-});
-
-export { errorsActions } from './errors';
-export { sessionActions } from './session';
-export { devicesActions } from './devices';
-export { eventsActions } from './events';
-export { geofencesActions } from './geofences';
-export { groupsActions } from './groups';
-export { driversActions } from './drivers';
-export { maintenancesActions } from './maintenances';
-export { calendarsActions } from './calendars';
-export { reportsActions } from './reports';
-
-export default configureStore({
- reducer,
- middleware: (getDefaultMiddleware) => getDefaultMiddleware().concat(throttleMiddleware),
-});
diff --git a/modern/src/store/maintenances.js b/modern/src/store/maintenances.js
deleted file mode 100644
index 0f5e41d1..00000000
--- a/modern/src/store/maintenances.js
+++ /dev/null
@@ -1,17 +0,0 @@
-import { createSlice } from '@reduxjs/toolkit';
-
-const { reducer, actions } = createSlice({
- name: 'maintenances',
- initialState: {
- items: {},
- },
- reducers: {
- refresh(state, action) {
- state.items = {};
- action.payload.forEach((item) => state.items[item.id] = item);
- },
- },
-});
-
-export { actions as maintenancesActions };
-export { reducer as maintenancesReducer };
diff --git a/modern/src/store/reports.js b/modern/src/store/reports.js
deleted file mode 100644
index d0c1f6dd..00000000
--- a/modern/src/store/reports.js
+++ /dev/null
@@ -1,29 +0,0 @@
-import { createSlice } from '@reduxjs/toolkit';
-import dayjs from 'dayjs';
-
-const { reducer, actions } = createSlice({
- name: 'reports',
- initialState: {
- groupIds: [],
- period: 'today',
- from: dayjs().subtract(1, 'hour').locale('en').format('YYYY-MM-DDTHH:mm'),
- to: dayjs().locale('en').format('YYYY-MM-DDTHH:mm'),
- },
- reducers: {
- updateGroupIds(state, action) {
- state.groupIds = action.payload;
- },
- updatePeriod(state, action) {
- state.period = action.payload;
- },
- updateFrom(state, action) {
- state.from = action.payload;
- },
- updateTo(state, action) {
- state.to = action.payload;
- },
- },
-});
-
-export { actions as reportsActions };
-export { reducer as reportsReducer };
diff --git a/modern/src/store/session.js b/modern/src/store/session.js
deleted file mode 100644
index bfe94a41..00000000
--- a/modern/src/store/session.js
+++ /dev/null
@@ -1,53 +0,0 @@
-import { createSlice } from '@reduxjs/toolkit';
-
-const { reducer, actions } = createSlice({
- name: 'session',
- initialState: {
- server: null,
- user: null,
- socket: null,
- includeLogs: false,
- logs: [],
- positions: {},
- history: {},
- },
- reducers: {
- updateServer(state, action) {
- state.server = action.payload;
- },
- updateUser(state, action) {
- state.user = action.payload;
- },
- updateSocket(state, action) {
- state.socket = action.payload;
- },
- enableLogs(state, action) {
- state.includeLogs = action.payload;
- if (!action.payload) {
- state.logs = [];
- }
- },
- updateLogs(state, action) {
- state.logs.push(...action.payload);
- },
- updatePositions(state, action) {
- const liveRoutes = state.user.attributes.mapLiveRoutes || state.server.attributes.mapLiveRoutes || 'none';
- const liveRoutesLimit = state.user.attributes['web.liveRouteLength'] || state.server.attributes['web.liveRouteLength'] || 10;
- action.payload.forEach((position) => {
- state.positions[position.deviceId] = position;
- if (liveRoutes !== 'none') {
- const route = state.history[position.deviceId] || [];
- const last = route.at(-1);
- if (!last || (last[0] !== position.longitude && last[1] !== position.latitude)) {
- state.history[position.deviceId] = [...route.slice(1 - liveRoutesLimit), [position.longitude, position.latitude]];
- }
- } else {
- state.history = {};
- }
- });
- },
- },
-});
-
-export { actions as sessionActions };
-export { reducer as sessionReducer };
diff --git a/modern/src/store/throttleMiddleware.js b/modern/src/store/throttleMiddleware.js
deleted file mode 100644
index d5a98add..00000000
--- a/modern/src/store/throttleMiddleware.js
+++ /dev/null
@@ -1,36 +0,0 @@
-import { batch } from 'react-redux';
-
-const threshold = 3;
-const interval = 1500;
-
-export default () => (next) => {
- const buffer = [];
- let throttle = false;
- let counter = 0;
-
- setInterval(() => {
- if (throttle) {
- if (buffer.length < threshold) {
- throttle = false;
- }
- batch(() => buffer.splice(0, buffer.length).forEach((action) => next(action)));
- } else {
- if (counter > threshold) {
- throttle = true;
- }
- counter = 0;
- }
- }, interval);
-
- return (action) => {
- if (action.type === 'devices/update' || action.type === 'positions/update') {
- if (throttle) {
- buffer.push(action);
- return null;
- }
- counter += 1;
- return next(action);
- }
- return next(action);
- };
-};