2023-09-12 20:14:17 +02:00
|
|
|
import { PayloadAction, createAsyncThunk, createSlice } from "@reduxjs/toolkit"
|
2022-08-13 10:56:07 +02:00
|
|
|
import { client } from "app/client"
|
|
|
|
|
import { ServerInfo } from "app/types"
|
|
|
|
|
|
|
|
|
|
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 reloadServerInfos = createAsyncThunk("server/infos", () => client.server.getServerInfos().then(r => r.data))
|
|
|
|
|
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
|
2022-08-13 10:56:07 +02:00
|
|
|
export default serverSlice.reducer
|