mirror of
https://github.com/plankanban/planka.git
synced 2025-08-06 05:55:27 +02:00
Initial commit
This commit is contained in:
commit
36fe34e8e1
583 changed files with 91539 additions and 0 deletions
70
client/src/sagas/app/services/board.js
Normal file
70
client/src/sagas/app/services/board.js
Normal file
|
@ -0,0 +1,70 @@
|
|||
import { call, put, select } from 'redux-saga/effects';
|
||||
|
||||
import { goToBoardService, goToProjectService } from './router';
|
||||
import { createBoardRequest, deleteBoardRequest, updateBoardRequest } from '../requests';
|
||||
import {
|
||||
boardByIdSelector,
|
||||
maxIdSelector,
|
||||
nextBoardPositionSelector,
|
||||
pathSelector,
|
||||
} from '../../../selectors';
|
||||
import { createBoard, deleteBoard, updateBoard } from '../../../actions';
|
||||
import { nextLocalId } from '../../../utils/local-id';
|
||||
import { Board } from '../../../models';
|
||||
|
||||
export function* createBoardService(projectId, data) {
|
||||
const nextData = {
|
||||
...data,
|
||||
position: yield select(nextBoardPositionSelector, projectId),
|
||||
};
|
||||
|
||||
const localId = nextLocalId(yield select(maxIdSelector, Board.modelName));
|
||||
|
||||
yield put(
|
||||
createBoard({
|
||||
...nextData,
|
||||
projectId,
|
||||
id: localId,
|
||||
}),
|
||||
);
|
||||
|
||||
const {
|
||||
success,
|
||||
payload: { board },
|
||||
} = yield call(createBoardRequest, projectId, localId, nextData);
|
||||
|
||||
if (success) {
|
||||
yield call(goToBoardService, board.id);
|
||||
}
|
||||
}
|
||||
|
||||
export function* createBoardInCurrentProjectService(data) {
|
||||
const { projectId } = yield select(pathSelector);
|
||||
|
||||
yield call(createBoardService, projectId, data);
|
||||
}
|
||||
|
||||
export function* updateBoardService(id, data) {
|
||||
yield put(updateBoard(id, data));
|
||||
yield call(updateBoardRequest, id, data);
|
||||
}
|
||||
|
||||
export function* moveBoardService(id, index) {
|
||||
const { projectId } = yield select(boardByIdSelector, id);
|
||||
const position = yield select(nextBoardPositionSelector, projectId, index, id);
|
||||
|
||||
yield call(updateBoardService, id, {
|
||||
position,
|
||||
});
|
||||
}
|
||||
|
||||
export function* deleteBoardService(id) {
|
||||
const { boardId, projectId } = yield select(pathSelector);
|
||||
|
||||
if (id === boardId) {
|
||||
yield call(goToProjectService, projectId);
|
||||
}
|
||||
|
||||
yield put(deleteBoard(id));
|
||||
yield call(deleteBoardRequest, id);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue