mirror of
https://github.com/astuto/astuto.git
synced 2025-12-15 11:17:49 +01:00
Add Boards management to sitesettings (#107)
This commit is contained in:
committed by
GitHub
parent
7b8a4d6709
commit
6be2394dc5
116
app/javascript/reducers/boardsReducer.ts
Normal file
116
app/javascript/reducers/boardsReducer.ts
Normal file
@@ -0,0 +1,116 @@
|
||||
import {
|
||||
BoardsRequestActionTypes,
|
||||
BOARDS_REQUEST_START,
|
||||
BOARDS_REQUEST_SUCCESS,
|
||||
BOARDS_REQUEST_FAILURE,
|
||||
} from '../actions/Board/requestBoards';
|
||||
|
||||
import {
|
||||
BoardSubmitActionTypes,
|
||||
BOARD_SUBMIT_SUCCESS,
|
||||
} from '../actions/Board/submitBoard';
|
||||
|
||||
import {
|
||||
BoardUpdateActionTypes,
|
||||
BOARD_UPDATE_SUCCESS
|
||||
} from '../actions/Board/updateBoard';
|
||||
|
||||
import {
|
||||
BoardOrderUpdateActionTypes,
|
||||
BOARD_ORDER_UPDATE_START,
|
||||
BOARD_ORDER_UPDATE_FAILURE,
|
||||
} from '../actions/Board/updateBoardOrder';
|
||||
|
||||
import {
|
||||
BoardDeleteActionTypes,
|
||||
BOARD_DELETE_SUCCESS,
|
||||
} from '../actions/Board/deleteBoard';
|
||||
|
||||
import IBoard from "../interfaces/IBoard";
|
||||
|
||||
export interface BoardsState {
|
||||
items: Array<IBoard>;
|
||||
areLoading: boolean;
|
||||
error: string;
|
||||
}
|
||||
|
||||
const initialState: BoardsState = {
|
||||
items: [],
|
||||
areLoading: false,
|
||||
error: '',
|
||||
}
|
||||
|
||||
const boardsReducer = (
|
||||
state = initialState,
|
||||
action:
|
||||
BoardsRequestActionTypes |
|
||||
BoardSubmitActionTypes |
|
||||
BoardUpdateActionTypes |
|
||||
BoardOrderUpdateActionTypes |
|
||||
BoardDeleteActionTypes
|
||||
) => {
|
||||
switch (action.type) {
|
||||
case BOARDS_REQUEST_START:
|
||||
return {
|
||||
...state,
|
||||
areLoading: true,
|
||||
};
|
||||
|
||||
case BOARDS_REQUEST_SUCCESS:
|
||||
return {
|
||||
...state,
|
||||
items: action.boards.map(board => ({
|
||||
id: board.id,
|
||||
name: board.name,
|
||||
description: board.description,
|
||||
})),
|
||||
areLoading: false,
|
||||
error: '',
|
||||
};
|
||||
|
||||
case BOARDS_REQUEST_FAILURE:
|
||||
return {
|
||||
...state,
|
||||
areLoading: false,
|
||||
error: action.error,
|
||||
};
|
||||
|
||||
case BOARD_SUBMIT_SUCCESS:
|
||||
return {
|
||||
...state,
|
||||
items: [...state.items, action.board],
|
||||
};
|
||||
|
||||
case BOARD_UPDATE_SUCCESS:
|
||||
return {
|
||||
...state,
|
||||
items: state.items.map(board => {
|
||||
if (board.id !== action.board.id) return board;
|
||||
return {...board, name: action.board.name, description: action.board.description};
|
||||
}),
|
||||
};
|
||||
|
||||
case BOARD_ORDER_UPDATE_START:
|
||||
return {
|
||||
...state,
|
||||
items: action.newOrder,
|
||||
};
|
||||
|
||||
case BOARD_ORDER_UPDATE_FAILURE:
|
||||
return {
|
||||
...state,
|
||||
items: action.oldOrder,
|
||||
};
|
||||
|
||||
case BOARD_DELETE_SUCCESS:
|
||||
return {
|
||||
...state,
|
||||
items: state.items.filter(board => board.id !== action.id),
|
||||
};
|
||||
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
}
|
||||
|
||||
export default boardsReducer;
|
||||
Reference in New Issue
Block a user