1
0
Fork 0
mirror of https://github.com/plankanban/planka.git synced 2025-07-26 00:29:48 +02:00

Project managers, board members, auto-update after reconnection, refactoring

This commit is contained in:
Maksim Eltyshev 2021-06-24 01:05:22 +05:00
parent d6cb1f6683
commit b39119ace4
478 changed files with 21226 additions and 19495 deletions

View file

@ -1,13 +1,16 @@
import { call, put, select } from 'redux-saga/effects';
import { call, put, select, take } from 'redux-saga/effects';
import { push } from 'connected-react-router';
import { deleteNotificationsInCurrentCardService } from './notifications';
import { fetchBoardRequest } from '../requests';
import request from '../request';
import {
currentBoardSelector,
isCoreInitializingSelector,
notificationIdsForCurrentCardSelector,
pathsMatchSelector,
} from '../../../selectors';
import { handleLocationChange } from '../../../actions';
import api from '../../../api';
import ActionTypes from '../../../constants/ActionTypes';
import Paths from '../../../constants/Paths';
export function* goToRootService() {
@ -26,46 +29,103 @@ export function* goToCardService(cardId) {
yield put(push(Paths.CARDS.replace(':id', cardId)));
}
export function* runPathActionsService(pathsMatch) {
export function* handleLocationChangeService() {
const pathsMatch = yield select(pathsMatchSelector);
if (!pathsMatch) {
return;
}
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;
switch (pathsMatch.path) {
case Paths.BOARDS:
case Paths.CARDS: {
const currentBoard = yield select(currentBoardSelector); // TODO: move to services
const currentBoard = yield select(currentBoardSelector);
if (currentBoard && currentBoard.isFetching === null) {
yield call(fetchBoardRequest, currentBoard.id);
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
}
if (pathsMatch.path === Paths.CARDS) {
yield call(deleteNotificationsInCurrentCardService);
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
}
}
break;
}
default:
}
}
export function* locationChangedService() {
const pathsMatch = yield select(pathsMatchSelector);
if (pathsMatch) {
switch (pathsMatch.path) {
case Paths.LOGIN:
yield call(goToRootService);
break;
default:
}
}
const isCoreInitializing = yield select(isCoreInitializingSelector);
if (!isCoreInitializing) {
yield call(runPathActionsService, pathsMatch);
}
yield put(
handleLocationChange(
board,
users,
projects,
boardMemberships,
labels,
lists,
cards,
cardMemberships,
cardLabels,
tasks,
attachments,
notifications,
),
);
}