mirror of
https://github.com/hibiken/asynqmon.git
synced 2025-09-16 19:51:38 +08:00
Add redux actions and reducer for scheduler entries
This commit is contained in:
49
ui/src/reducers/schedulerEntriesReducer.ts
Normal file
49
ui/src/reducers/schedulerEntriesReducer.ts
Normal file
@@ -0,0 +1,49 @@
|
||||
import {
|
||||
LIST_SCHEDULER_ENTRIES_BEGIN,
|
||||
LIST_SCHEDULER_ENTRIES_ERROR,
|
||||
LIST_SCHEDULER_ENTRIES_SUCCESS,
|
||||
SchedulerEntriesActionTypes,
|
||||
} from "../actions/schedulerEntriesActions";
|
||||
import { SchedulerEntry } from "../api";
|
||||
|
||||
interface SchedulerEntriesState {
|
||||
loading: boolean;
|
||||
data: SchedulerEntry[];
|
||||
error: string; // error description
|
||||
}
|
||||
|
||||
const initialState: SchedulerEntriesState = {
|
||||
loading: false,
|
||||
data: [],
|
||||
error: "",
|
||||
};
|
||||
|
||||
function schedulerEntriesReducer(
|
||||
state = initialState,
|
||||
action: SchedulerEntriesActionTypes
|
||||
): SchedulerEntriesState {
|
||||
switch (action.type) {
|
||||
case LIST_SCHEDULER_ENTRIES_BEGIN:
|
||||
return {
|
||||
...state,
|
||||
loading: true,
|
||||
};
|
||||
case LIST_SCHEDULER_ENTRIES_SUCCESS:
|
||||
return {
|
||||
error: "",
|
||||
loading: false,
|
||||
data: action.payload.entries,
|
||||
};
|
||||
case LIST_SCHEDULER_ENTRIES_ERROR:
|
||||
// TODO: set error state
|
||||
return {
|
||||
...state,
|
||||
loading: false,
|
||||
error: action.error,
|
||||
};
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
}
|
||||
|
||||
export default schedulerEntriesReducer;
|
Reference in New Issue
Block a user