Major update
This commit is contained in:
50
app/src/components/divisions/reducer.ts
Normal file
50
app/src/components/divisions/reducer.ts
Normal file
@@ -0,0 +1,50 @@
|
||||
import { IDivisionsState } from './IDivisionsState';
|
||||
import { IDivision } from '../../models/IDivision';
|
||||
|
||||
export type Action =
|
||||
| { type: 'SET_ITEMS'; payload: IDivision[] }
|
||||
| { type: 'SET_CURRENT_PAGE_NUMBER'; payload: number }
|
||||
| { type: 'SET_PAGE_SIZE'; payload: number }
|
||||
| { type: 'SET_IS_PANEL_OPEN'; payload: boolean };
|
||||
|
||||
export const initialState: IDivisionsState = {
|
||||
items: [],
|
||||
currentPageNumber: 1,
|
||||
pageSize: 10,
|
||||
isPanelOpen: false
|
||||
};
|
||||
|
||||
export const reducer = (
|
||||
state: IDivisionsState,
|
||||
action: Action
|
||||
): IDivisionsState => {
|
||||
switch (action.type) {
|
||||
case 'SET_ITEMS': {
|
||||
return {
|
||||
...state,
|
||||
items: action.payload
|
||||
};
|
||||
}
|
||||
case 'SET_CURRENT_PAGE_NUMBER': {
|
||||
return {
|
||||
...state,
|
||||
currentPageNumber: action.payload
|
||||
};
|
||||
}
|
||||
case 'SET_PAGE_SIZE': {
|
||||
return {
|
||||
...state,
|
||||
pageSize: action.payload
|
||||
};
|
||||
}
|
||||
case 'SET_IS_PANEL_OPEN': {
|
||||
return {
|
||||
...state,
|
||||
isPanelOpen: action.payload
|
||||
};
|
||||
}
|
||||
default: {
|
||||
return state;
|
||||
}
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user