2021-06-24 01:05:22 +05:00
|
|
|
import { call, put, select, take } from 'redux-saga/effects';
|
2019-08-31 04:07:25 +05:00
|
|
|
import { push } from 'connected-react-router';
|
|
|
|
|
2021-06-24 01:05:22 +05:00
|
|
|
import request from '../request';
|
2019-08-31 04:07:25 +05:00
|
|
|
import {
|
|
|
|
currentBoardSelector,
|
2020-05-29 19:31:19 +05:00
|
|
|
isCoreInitializingSelector,
|
2021-06-24 01:05:22 +05:00
|
|
|
notificationIdsForCurrentCardSelector,
|
2019-08-31 04:07:25 +05:00
|
|
|
pathsMatchSelector,
|
|
|
|
} from '../../../selectors';
|
2021-06-24 01:05:22 +05:00
|
|
|
import { handleLocationChange } from '../../../actions';
|
|
|
|
import api from '../../../api';
|
|
|
|
import ActionTypes from '../../../constants/ActionTypes';
|
2019-08-31 04:07:25 +05:00
|
|
|
import Paths from '../../../constants/Paths';
|
|
|
|
|
|
|
|
export function* goToRootService() {
|
|
|
|
yield put(push(Paths.ROOT));
|
|
|
|
}
|
|
|
|
|
|
|
|
export function* goToProjectService(projectId) {
|
|
|
|
yield put(push(Paths.PROJECTS.replace(':id', projectId)));
|
|
|
|
}
|
|
|
|
|
|
|
|
export function* goToBoardService(boardId) {
|
|
|
|
yield put(push(Paths.BOARDS.replace(':id', boardId)));
|
|
|
|
}
|
|
|
|
|
|
|
|
export function* goToCardService(cardId) {
|
|
|
|
yield put(push(Paths.CARDS.replace(':id', cardId)));
|
|
|
|
}
|
|
|
|
|
2021-06-24 01:05:22 +05:00
|
|
|
export function* handleLocationChangeService() {
|
|
|
|
const pathsMatch = yield select(pathsMatchSelector);
|
|
|
|
|
2019-08-31 04:07:25 +05:00
|
|
|
if (!pathsMatch) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-06-24 01:05:22 +05:00
|
|
|
switch (pathsMatch.path) {
|
|
|
|
case Paths.LOGIN:
|
|
|
|
yield call(goToRootService);
|
|
|
|
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
}
|
|
|
|
|
|
|
|
const isCoreInitializing = yield select(isCoreInitializingSelector);
|
|
|
|
|
|
|
|
if (isCoreInitializing) {
|
|
|
|
yield take(ActionTypes.CORE_INITIALIZE);
|
|
|
|
}
|
|
|
|
|
|
|
|
let board;
|
|
|
|
let users;
|
|
|
|
let projects;
|
|
|
|
let boardMemberships;
|
|
|
|
let labels;
|
|
|
|
let lists;
|
|
|
|
let cards;
|
|
|
|
let cardMemberships;
|
|
|
|
let cardLabels;
|
|
|
|
let tasks;
|
|
|
|
let attachments;
|
|
|
|
let notifications;
|
|
|
|
|
2019-08-31 04:07:25 +05:00
|
|
|
switch (pathsMatch.path) {
|
|
|
|
case Paths.BOARDS:
|
|
|
|
case Paths.CARDS: {
|
2021-06-24 01:05:22 +05:00
|
|
|
const currentBoard = yield select(currentBoardSelector);
|
2019-08-31 04:07:25 +05:00
|
|
|
|
|
|
|
if (currentBoard && currentBoard.isFetching === null) {
|
2021-06-24 01:05:22 +05:00
|
|
|
yield put(handleLocationChange.fetchBoard(currentBoard.id));
|
|
|
|
|
|
|
|
try {
|
|
|
|
({
|
|
|
|
item: board,
|
|
|
|
included: {
|
|
|
|
users,
|
|
|
|
projects,
|
|
|
|
boardMemberships,
|
|
|
|
labels,
|
|
|
|
lists,
|
|
|
|
cards,
|
|
|
|
cardMemberships,
|
|
|
|
cardLabels,
|
|
|
|
tasks,
|
|
|
|
attachments,
|
|
|
|
},
|
|
|
|
} = yield call(request, api.getBoard, currentBoard.id));
|
|
|
|
} catch (error) {} // eslint-disable-line no-empty
|
2019-08-31 04:07:25 +05:00
|
|
|
}
|
|
|
|
|
|
|
|
if (pathsMatch.path === Paths.CARDS) {
|
2021-06-24 01:05:22 +05:00
|
|
|
const notificationIds = yield select(notificationIdsForCurrentCardSelector);
|
|
|
|
|
|
|
|
if (notificationIds && notificationIds.length > 0) {
|
|
|
|
try {
|
|
|
|
({ items: notifications } = yield call(
|
|
|
|
request,
|
|
|
|
api.updateNotifications,
|
|
|
|
notificationIds,
|
|
|
|
{
|
|
|
|
isRead: true,
|
|
|
|
},
|
|
|
|
));
|
|
|
|
} catch (error) {} // eslint-disable-line no-empty
|
|
|
|
}
|
2019-08-31 04:07:25 +05:00
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
}
|
|
|
|
|
2021-06-24 01:05:22 +05:00
|
|
|
yield put(
|
|
|
|
handleLocationChange(
|
|
|
|
board,
|
|
|
|
users,
|
|
|
|
projects,
|
|
|
|
boardMemberships,
|
|
|
|
labels,
|
|
|
|
lists,
|
|
|
|
cards,
|
|
|
|
cardMemberships,
|
|
|
|
cardLabels,
|
|
|
|
tasks,
|
|
|
|
attachments,
|
|
|
|
notifications,
|
|
|
|
),
|
|
|
|
);
|
2019-08-31 04:07:25 +05:00
|
|
|
}
|