@@ -7,11 +7,16 @@ import api from '../../../api';
|
||||
import { createLocalId } from '../../../utils/local-id';
|
||||
|
||||
export function* createLabel(boardId, data) {
|
||||
const nextData = {
|
||||
...data,
|
||||
position: yield select(selectors.selectNextLabelPosition, boardId),
|
||||
};
|
||||
|
||||
const localId = yield call(createLocalId);
|
||||
|
||||
yield put(
|
||||
actions.createLabel({
|
||||
...data,
|
||||
...nextData,
|
||||
boardId,
|
||||
id: localId,
|
||||
}),
|
||||
@@ -19,7 +24,7 @@ export function* createLabel(boardId, data) {
|
||||
|
||||
let label;
|
||||
try {
|
||||
({ item: label } = yield call(request, api.createLabel, boardId, data));
|
||||
({ item: label } = yield call(request, api.createLabel, boardId, nextData));
|
||||
} catch (error) {
|
||||
yield put(actions.createLabel.failure(localId, error));
|
||||
return;
|
||||
@@ -56,6 +61,15 @@ export function* handleLabelUpdate(label) {
|
||||
yield put(actions.handleLabelUpdate(label));
|
||||
}
|
||||
|
||||
export function* moveLabel(id, index) {
|
||||
const { boardId } = yield select(selectors.selectLabelById, id);
|
||||
const position = yield select(selectors.selectNextLabelPosition, boardId, index, id);
|
||||
|
||||
yield call(updateLabel, id, {
|
||||
position,
|
||||
});
|
||||
}
|
||||
|
||||
export function* deleteLabel(id) {
|
||||
yield put(actions.deleteLabel(id));
|
||||
|
||||
@@ -150,6 +164,7 @@ export default {
|
||||
handleLabelCreate,
|
||||
updateLabel,
|
||||
handleLabelUpdate,
|
||||
moveLabel,
|
||||
deleteLabel,
|
||||
handleLabelDelete,
|
||||
addLabelToCard,
|
||||
|
||||
@@ -17,6 +17,9 @@ export default function* labelsWatchers() {
|
||||
takeEvery(EntryActionTypes.LABEL_UPDATE_HANDLE, ({ payload: { label } }) =>
|
||||
services.handleLabelUpdate(label),
|
||||
),
|
||||
takeEvery(EntryActionTypes.LABEL_MOVE, ({ payload: { id, index } }) =>
|
||||
services.moveLabel(id, index),
|
||||
),
|
||||
takeEvery(EntryActionTypes.LABEL_DELETE, ({ payload: { id } }) => services.deleteLabel(id)),
|
||||
takeEvery(EntryActionTypes.LABEL_DELETE_HANDLE, ({ payload: { label } }) =>
|
||||
services.handleLabelDelete(label),
|
||||
|
||||
Reference in New Issue
Block a user