github.com/wfusion/gofusion@v1.1.14/common/infra/asynq/asynqmon/ui/src/reducers/serversReducer.ts (about)

     1  import {
     2    LIST_SERVERS_BEGIN,
     3    LIST_SERVERS_ERROR,
     4    LIST_SERVERS_SUCCESS,
     5    ServersActionTypes,
     6  } from "../actions/serversActions";
     7  import { ServerInfo } from "../api";
     8  
     9  interface ServersState {
    10    loading: boolean;
    11    error: string;
    12    data: ServerInfo[];
    13  }
    14  
    15  const initialState: ServersState = {
    16    loading: false,
    17    error: "",
    18    data: [],
    19  };
    20  
    21  export default function serversReducer(
    22    state = initialState,
    23    action: ServersActionTypes
    24  ): ServersState {
    25    switch (action.type) {
    26      case LIST_SERVERS_BEGIN:
    27        return {
    28          ...state,
    29          loading: true,
    30        };
    31  
    32      case LIST_SERVERS_SUCCESS:
    33        return {
    34          loading: false,
    35          error: "",
    36          data: action.payload.servers,
    37        };
    38  
    39      case LIST_SERVERS_ERROR:
    40        return {
    41          ...state,
    42          error: action.error,
    43          loading: false,
    44        };
    45  
    46      default:
    47        return state;
    48    }
    49  }