mirror of
https://github.com/plankanban/planka.git
synced 2025-07-19 13:19:44 +02:00
ref: Refactoring
This commit is contained in:
parent
aa4723d7fe
commit
3f8216dca8
189 changed files with 3781 additions and 3486 deletions
173
client/src/sagas/core/services/boards.js
Normal file
173
client/src/sagas/core/services/boards.js
Normal file
|
@ -0,0 +1,173 @@
|
|||
import { call, put, select } from 'redux-saga/effects';
|
||||
|
||||
import { goToBoard, goToProject } from './router';
|
||||
import request from '../request';
|
||||
import selectors from '../../../selectors';
|
||||
import actions from '../../../actions';
|
||||
import api from '../../../api';
|
||||
import { createLocalId } from '../../../utils/local-id';
|
||||
|
||||
export function* createBoard(projectId, data) {
|
||||
const nextData = {
|
||||
...data,
|
||||
position: yield select(selectors.selectNextBoardPosition, projectId),
|
||||
};
|
||||
|
||||
const localId = yield call(createLocalId);
|
||||
|
||||
yield put(
|
||||
actions.createBoard({
|
||||
...nextData,
|
||||
projectId,
|
||||
id: localId,
|
||||
}),
|
||||
);
|
||||
|
||||
let board;
|
||||
let boardMemberships;
|
||||
|
||||
try {
|
||||
({
|
||||
item: board,
|
||||
included: { boardMemberships },
|
||||
} = yield call(request, api.createBoard, projectId, nextData));
|
||||
} catch (error) {
|
||||
yield put(actions.createBoard.failure(localId, error));
|
||||
return;
|
||||
}
|
||||
|
||||
yield put(actions.createBoard.success(localId, board, boardMemberships));
|
||||
yield call(goToBoard, board.id);
|
||||
}
|
||||
|
||||
export function* createBoardInCurrentProject(data) {
|
||||
const { projectId } = yield select(selectors.selectPath);
|
||||
|
||||
yield call(createBoard, projectId, data);
|
||||
}
|
||||
|
||||
export function* handleBoardCreate(board) {
|
||||
yield put(actions.handleBoardCreate(board));
|
||||
}
|
||||
|
||||
export function* fetchBoard(id) {
|
||||
yield put(actions.fetchBoard(id));
|
||||
|
||||
let board;
|
||||
let users;
|
||||
let projects;
|
||||
let boardMemberships;
|
||||
let labels;
|
||||
let lists;
|
||||
let cards;
|
||||
let cardMemberships;
|
||||
let cardLabels;
|
||||
let tasks;
|
||||
let attachments;
|
||||
|
||||
try {
|
||||
({
|
||||
item: board,
|
||||
included: {
|
||||
users,
|
||||
projects,
|
||||
boardMemberships,
|
||||
labels,
|
||||
lists,
|
||||
cards,
|
||||
cardMemberships,
|
||||
cardLabels,
|
||||
tasks,
|
||||
attachments,
|
||||
},
|
||||
} = yield call(request, api.getBoard, id));
|
||||
} catch (error) {
|
||||
yield put(actions.fetchBoard.failure(id, error));
|
||||
return;
|
||||
}
|
||||
|
||||
yield put(
|
||||
actions.fetchBoard.success(
|
||||
board,
|
||||
users,
|
||||
projects,
|
||||
boardMemberships,
|
||||
labels,
|
||||
lists,
|
||||
cards,
|
||||
cardMemberships,
|
||||
cardLabels,
|
||||
tasks,
|
||||
attachments,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
export function* updateBoard(id, data) {
|
||||
yield put(actions.updateBoard(id, data));
|
||||
|
||||
let board;
|
||||
try {
|
||||
({ item: board } = yield call(request, api.updateBoard, id, data));
|
||||
} catch (error) {
|
||||
yield put(actions.updateBoard.failure(id, error));
|
||||
return;
|
||||
}
|
||||
|
||||
yield put(actions.updateBoard.success(board));
|
||||
}
|
||||
|
||||
export function* handleBoardUpdate(board) {
|
||||
yield put(actions.handleBoardUpdate(board));
|
||||
}
|
||||
|
||||
export function* moveBoard(id, index) {
|
||||
const { projectId } = yield select(selectors.selectBoardById, id);
|
||||
const position = yield select(selectors.selectNextBoardPosition, projectId, index, id);
|
||||
|
||||
yield call(updateBoard, id, {
|
||||
position,
|
||||
});
|
||||
}
|
||||
|
||||
export function* deleteBoard(id) {
|
||||
const { boardId, projectId } = yield select(selectors.selectPath);
|
||||
|
||||
if (id === boardId) {
|
||||
yield call(goToProject, projectId);
|
||||
}
|
||||
|
||||
yield put(actions.deleteBoard(id));
|
||||
|
||||
let board;
|
||||
try {
|
||||
({ item: board } = yield call(request, api.deleteBoard, id));
|
||||
} catch (error) {
|
||||
yield put(actions.deleteBoard.failure(id, error));
|
||||
return;
|
||||
}
|
||||
|
||||
yield put(actions.deleteBoard.success(board));
|
||||
}
|
||||
|
||||
export function* handleBoardDelete(board) {
|
||||
const { boardId, projectId } = yield select(selectors.selectPath);
|
||||
|
||||
if (board.id === boardId) {
|
||||
yield call(goToProject, projectId);
|
||||
}
|
||||
|
||||
yield put(actions.handleBoardDelete(board));
|
||||
}
|
||||
|
||||
export default {
|
||||
createBoard,
|
||||
createBoardInCurrentProject,
|
||||
handleBoardCreate,
|
||||
fetchBoard,
|
||||
updateBoard,
|
||||
handleBoardUpdate,
|
||||
moveBoard,
|
||||
deleteBoard,
|
||||
handleBoardDelete,
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue