2023-12-28 21:45:17 +01:00
|
|
|
import { createSlice, type PayloadAction } from "@reduxjs/toolkit"
|
2023-12-28 22:11:03 +01:00
|
|
|
import { reloadServerInfos } from "app/server/thunks"
|
2023-12-28 19:54:51 +01:00
|
|
|
import { type ServerInfo } from "app/types"
|
2022-08-13 10:56:07 +02:00
|
|
|
|
|
|
|
|
interface ServerState {
|
|
|
|
|
serverInfos?: ServerInfo
|
2023-09-12 20:14:17 +02:00
|
|
|
webSocketConnected: boolean
|
2022-08-13 10:56:07 +02:00
|
|
|
}
|
|
|
|
|
|
2023-09-12 20:14:17 +02:00
|
|
|
const initialState: ServerState = {
|
|
|
|
|
webSocketConnected: false,
|
|
|
|
|
}
|
2022-08-13 10:56:07 +02:00
|
|
|
|
|
|
|
|
export const serverSlice = createSlice({
|
|
|
|
|
name: "server",
|
|
|
|
|
initialState,
|
2023-09-12 20:14:17 +02:00
|
|
|
reducers: {
|
|
|
|
|
setWebSocketConnected: (state, action: PayloadAction<boolean>) => {
|
|
|
|
|
state.webSocketConnected = action.payload
|
|
|
|
|
},
|
|
|
|
|
},
|
2022-08-13 10:56:07 +02:00
|
|
|
extraReducers: builder => {
|
|
|
|
|
builder.addCase(reloadServerInfos.fulfilled, (state, action) => {
|
|
|
|
|
state.serverInfos = action.payload
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
|
2023-09-12 20:14:17 +02:00
|
|
|
export const { setWebSocketConnected } = serverSlice.actions
|