refactor: fetchLocationDevices.js entfernt – Nutzung über Thunk + Service strukturiert neu aufgesetzt
This commit is contained in:
21
CHANGELOG.md
21
CHANGELOG.md
@@ -4,6 +4,27 @@ Alle bedeutenden Änderungen an diesem Projekt werden in dieser Datei dokumentie
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
## [1.1.127] – 2025-05-21
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
|
||||||
|
- 🧱 `fetchLocationDevices.js` wurde vollständig entfernt (lag zuvor unter `/redux/api/fromDB/`)
|
||||||
|
- Stattdessen wird der neue Service `fetchLocationDevicesService.js` in `/services/database/` verwendet
|
||||||
|
- Neuer Thunk `fetchLocationDevicesThunk.js` unter `/redux/thunks/database/` eingeführt
|
||||||
|
- `locationDevicesFromDBSlice.js` ersetzt durch `locationDevicesSlice.js` mit Anbindung an den neuen Thunk
|
||||||
|
- `MapComponent.js` nutzt jetzt `dispatch(fetchLocationDevicesThunk())` zur Initialisierung der Geräte
|
||||||
|
|
||||||
|
### Cleanup
|
||||||
|
|
||||||
|
- ❌ Alle direkten Service-Imports aus Slices entfernt (Schnittstelle liegt nun nur noch im Thunk)
|
||||||
|
- 🧼 Zugriff auf `fetchLocationDevicesFromDB()` ersetzt durch `fetchLocationDevicesThunk()`
|
||||||
|
|
||||||
|
### Version
|
||||||
|
|
||||||
|
- 📦 Version erhöht auf **1.1.127**
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
## [1.1.126] – 2025-05-21
|
## [1.1.126] – 2025-05-21
|
||||||
|
|
||||||
### Cleanup
|
### Cleanup
|
||||||
|
|||||||
@@ -38,13 +38,9 @@ import CoordinatePopup from "../CoordinatePopup.js";
|
|||||||
//------------------------Daten aus API--------------------
|
//------------------------Daten aus API--------------------
|
||||||
import { fetchPoiDataService } from "../../services/database/fetchPoiDataService.js";
|
import { fetchPoiDataService } from "../../services/database/fetchPoiDataService.js";
|
||||||
import { selectPolylineVisible, setPolylineVisible } from "../../redux/slices/polylineLayerVisibleSlice.js";
|
import { selectPolylineVisible, setPolylineVisible } from "../../redux/slices/polylineLayerVisibleSlice.js";
|
||||||
import { fetchLocationDevicesFromDB } from "../../redux/slices/database/locationDevicesFromDBSlice";
|
|
||||||
|
|
||||||
import { selectGisStationsStaticDistrict } from "../../redux/slices/webService/gisStationsStaticDistrictSlice";
|
import { selectGisStationsStaticDistrict } from "../../redux/slices/webService/gisStationsStaticDistrictSlice";
|
||||||
|
|
||||||
import { selectGisSystemStatic, setGisSystemStatic } from "../../redux/slices/webService/gisSystemStaticSlice";
|
import { selectGisSystemStatic, setGisSystemStatic } from "../../redux/slices/webService/gisSystemStaticSlice";
|
||||||
import ShowAddStationPopup from "../AddPOIModal.js";
|
import ShowAddStationPopup from "../AddPOIModal.js";
|
||||||
|
|
||||||
import AddPOIOnPolyline from "../AddPOIOnPolyline";
|
import AddPOIOnPolyline from "../AddPOIOnPolyline";
|
||||||
import { enablePolylineEvents, disablePolylineEvents } from "../../utils/polylines/eventHandlers";
|
import { enablePolylineEvents, disablePolylineEvents } from "../../utils/polylines/eventHandlers";
|
||||||
import { updateCountdown, closePolylineContextMenu } from "../../redux/slices/polylineContextMenuSlice";
|
import { updateCountdown, closePolylineContextMenu } from "../../redux/slices/polylineContextMenuSlice";
|
||||||
@@ -57,11 +53,12 @@ import { setSelectedPoi } from "../../redux/slices/selectedPoiSlice";
|
|||||||
import { setDisabled } from "../../redux/slices/polylineEventsDisabledSlice";
|
import { setDisabled } from "../../redux/slices/polylineEventsDisabledSlice";
|
||||||
import { setMapId, setUserId } from "../../redux/slices/urlParameterSlice";
|
import { setMapId, setUserId } from "../../redux/slices/urlParameterSlice";
|
||||||
import { fetchPoiTypes } from "../../redux/slices/database/poiTypesSlice";
|
import { fetchPoiTypes } from "../../redux/slices/database/poiTypesSlice";
|
||||||
|
//-----------Redux-Thunks-------------------
|
||||||
import { fetchGisStationsMeasurementsThunk } from "../../redux/thunks/webservice/fetchGisStationsMeasurementsThunk";
|
import { fetchGisStationsMeasurementsThunk } from "../../redux/thunks/webservice/fetchGisStationsMeasurementsThunk";
|
||||||
import { fetchGisSystemStaticThunk } from "../../redux/thunks/webservice/fetchGisSystemStaticThunk";
|
import { fetchGisSystemStaticThunk } from "../../redux/thunks/webservice/fetchGisSystemStaticThunk";
|
||||||
import { fetchGisStationsStaticDistrictThunk } from "../../redux/thunks/webservice/fetchGisStationsStaticDistrictThunk";
|
import { fetchGisStationsStaticDistrictThunk } from "../../redux/thunks/webservice/fetchGisStationsStaticDistrictThunk";
|
||||||
import { fetchGisStationsStatusDistrictThunk } from "../../redux/thunks/webservice/fetchGisStationsStatusDistrictThunk";
|
import { fetchGisStationsStatusDistrictThunk } from "../../redux/thunks/webservice/fetchGisStationsStatusDistrictThunk";
|
||||||
|
import { fetchLocationDevicesThunk } from "../../redux/thunks/database/fetchLocationDevicesThunk";
|
||||||
|
|
||||||
const MapComponent = ({ locations, onLocationUpdate, lineCoordinates }) => {
|
const MapComponent = ({ locations, onLocationUpdate, lineCoordinates }) => {
|
||||||
const dispatch = useDispatch();
|
const dispatch = useDispatch();
|
||||||
@@ -912,7 +909,7 @@ const MapComponent = ({ locations, onLocationUpdate, lineCoordinates }) => {
|
|||||||
// speichere location devices in redux store
|
// speichere location devices in redux store
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
dispatch(fetchLocationDevicesFromDB());
|
dispatch(fetchLocationDevicesThunk());
|
||||||
}, [dispatch]);
|
}, [dispatch]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|||||||
@@ -1,2 +1,2 @@
|
|||||||
// /config/appVersion
|
// /config/appVersion
|
||||||
export const APP_VERSION = "1.1.127";
|
export const APP_VERSION = "1.1.128";
|
||||||
|
|||||||
@@ -1,8 +0,0 @@
|
|||||||
// /redux/api/fromDB/fetchLocationDevices.js
|
|
||||||
export const fetchLocationDevices = async () => {
|
|
||||||
const response = await fetch("/api/talas_v5_DB/locationDevice/locationDevices");
|
|
||||||
if (!response.ok) {
|
|
||||||
throw new Error("Geräteliste konnte nicht geladen werden");
|
|
||||||
}
|
|
||||||
return await response.json();
|
|
||||||
};
|
|
||||||
@@ -1,29 +0,0 @@
|
|||||||
// /redux/websocketMiddleware.js
|
|
||||||
const websocketMiddleware = () => {
|
|
||||||
let socket;
|
|
||||||
|
|
||||||
return ({ dispatch }) =>
|
|
||||||
(next) =>
|
|
||||||
(action) => {
|
|
||||||
if (action.type === "WS_CONNECT") {
|
|
||||||
socket = new WebSocket(action.payload.url);
|
|
||||||
|
|
||||||
socket.onmessage = (event) => {
|
|
||||||
const data = JSON.parse(event.data);
|
|
||||||
dispatch({ type: "WS_MESSAGE_RECEIVED", payload: data });
|
|
||||||
};
|
|
||||||
|
|
||||||
socket.onclose = () => {
|
|
||||||
dispatch({ type: "WS_DISCONNECTED" });
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
if (action.type === "WS_DISCONNECT" && socket) {
|
|
||||||
socket.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
return next(action);
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
export default websocketMiddleware;
|
|
||||||
@@ -1,10 +1,5 @@
|
|||||||
// /redux/slices/database/locationDevicesFromDBSlice.js
|
import { createSlice } from "@reduxjs/toolkit";
|
||||||
import { createSlice, createAsyncThunk } from "@reduxjs/toolkit";
|
import { fetchLocationDevicesThunk } from "../../thunks/database/fetchLocationDevicesThunk";
|
||||||
import { fetchLocationDevices } from "../../api/fromDB/fetchLocationDevices";
|
|
||||||
|
|
||||||
export const fetchLocationDevicesFromDB = createAsyncThunk("locationDevicesFromDB/fetchLocationDevicesFromDB", async () => {
|
|
||||||
return fetchLocationDevices();
|
|
||||||
});
|
|
||||||
|
|
||||||
const locationDevicesFromDBSlice = createSlice({
|
const locationDevicesFromDBSlice = createSlice({
|
||||||
name: "locationDevicesFromDB",
|
name: "locationDevicesFromDB",
|
||||||
@@ -16,14 +11,14 @@ const locationDevicesFromDBSlice = createSlice({
|
|||||||
reducers: {},
|
reducers: {},
|
||||||
extraReducers: (builder) => {
|
extraReducers: (builder) => {
|
||||||
builder
|
builder
|
||||||
.addCase(fetchLocationDevicesFromDB.pending, (state) => {
|
.addCase(fetchLocationDevicesThunk.pending, (state) => {
|
||||||
state.status = "loading";
|
state.status = "loading";
|
||||||
})
|
})
|
||||||
.addCase(fetchLocationDevicesFromDB.fulfilled, (state, action) => {
|
.addCase(fetchLocationDevicesThunk.fulfilled, (state, action) => {
|
||||||
state.status = "succeeded";
|
state.status = "succeeded";
|
||||||
state.devices = action.payload; // <-- Hier landen die Daten
|
state.devices = action.payload;
|
||||||
})
|
})
|
||||||
.addCase(fetchLocationDevicesFromDB.rejected, (state, action) => {
|
.addCase(fetchLocationDevicesThunk.rejected, (state, action) => {
|
||||||
state.status = "failed";
|
state.status = "failed";
|
||||||
state.error = action.error.message;
|
state.error = action.error.message;
|
||||||
});
|
});
|
||||||
@@ -31,3 +26,4 @@ const locationDevicesFromDBSlice = createSlice({
|
|||||||
});
|
});
|
||||||
|
|
||||||
export default locationDevicesFromDBSlice.reducer;
|
export default locationDevicesFromDBSlice.reducer;
|
||||||
|
export const selectLocationDevices = (state) => state.locationDevicesFromDB.devices;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// /redux/thunks/fetchLocationDevicesThunk.js
|
// /redux/thunks/database/fetchLocationDevicesThunk.js
|
||||||
import { createAsyncThunk } from "@reduxjs/toolkit";
|
import { createAsyncThunk } from "@reduxjs/toolkit";
|
||||||
import { fetchLocationDevicesService } from "../../../services/database/fetchLocationDevicesService";
|
import { fetchLocationDevicesService } from "../../../services/database/fetchLocationDevicesService";
|
||||||
|
|
||||||
|
|||||||
@@ -1,24 +0,0 @@
|
|||||||
const WebSocket = require("ws");
|
|
||||||
|
|
||||||
// Starte den WebSocket-Server auf Port 3001
|
|
||||||
const wss = new WebSocket.Server({ port: 3001 });
|
|
||||||
|
|
||||||
wss.on("connection", (ws) => {
|
|
||||||
console.log("New WebSocket connection");
|
|
||||||
|
|
||||||
ws.on("message", (message) => {
|
|
||||||
console.log("Received:", message);
|
|
||||||
const parsedMessage = JSON.parse(message);
|
|
||||||
|
|
||||||
// Beispielnachricht an den Client zurücksenden
|
|
||||||
if (parsedMessage.type === "test") {
|
|
||||||
ws.send(JSON.stringify({ message: `Hallo zurück, ${parsedMessage.message}` }));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
ws.on("close", () => {
|
|
||||||
console.log("WebSocket connection closed");
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
console.log("WebSocket-Server läuft auf ws://localhost:3001");
|
|
||||||
Reference in New Issue
Block a user