import { BmsState } from "@/constants/types"; import { createSlice, PayloadAction, createAsyncThunk } from "@reduxjs/toolkit"; interface TelemetryState { SoH: number | null; SoC: number | null; chargingState: BmsState | null; lat: number | null; lon: number | null; loading: boolean; error: string | null; totalDistance: number | null; } const initialState: TelemetryState = { SoH: null, SoC: null, chargingState: null, lat: null, lon: null, loading: false, error: null, totalDistance: null, }; export const telemetrySlice = createSlice({ name: "telemetry", initialState, reducers: { updateTelemetry: (state, action: PayloadAction) => { return { ...state, ...action.payload }; }, setTelemetryLoading: (state) => { state.loading = true; }, setTelemetryError: (state, action: PayloadAction) => { state.loading = false; state.error = action.payload; }, clearTelemetry: () => initialState, }, }); export const { updateTelemetry, setTelemetryLoading, clearTelemetry, setTelemetryError, } = telemetrySlice.actions; export default telemetrySlice.reducer;