mirror of
https://github.com/Athou/commafeed.git
synced 2026-03-21 21:37:29 +00:00
33 lines
1.0 KiB
TypeScript
33 lines
1.0 KiB
TypeScript
import { createSlice, type PayloadAction } from "@reduxjs/toolkit"
|
|
import { client } from "app/client"
|
|
import { createAppAsyncThunk } from "app/thunk"
|
|
import { type ServerInfo } from "app/types"
|
|
|
|
interface ServerState {
|
|
serverInfos?: ServerInfo
|
|
webSocketConnected: boolean
|
|
}
|
|
|
|
const initialState: ServerState = {
|
|
webSocketConnected: false,
|
|
}
|
|
|
|
export const reloadServerInfos = createAppAsyncThunk("server/infos", async () => await client.server.getServerInfos().then(r => r.data))
|
|
export const serverSlice = createSlice({
|
|
name: "server",
|
|
initialState,
|
|
reducers: {
|
|
setWebSocketConnected: (state, action: PayloadAction<boolean>) => {
|
|
state.webSocketConnected = action.payload
|
|
},
|
|
},
|
|
extraReducers: builder => {
|
|
builder.addCase(reloadServerInfos.fulfilled, (state, action) => {
|
|
state.serverInfos = action.payload
|
|
})
|
|
},
|
|
})
|
|
|
|
export const { setWebSocketConnected } = serverSlice.actions
|
|
export default serverSlice.reducer
|