1
0
Fork 0
mirror of https://github.com/plankanban/planka.git synced 2025-08-05 13:35:27 +02:00

ref: Little refactoring

This commit is contained in:
Maksim Eltyshev 2025-07-14 14:54:06 +02:00
parent 70cadcd974
commit 3aba4d4a56
14 changed files with 123 additions and 52 deletions

View file

@ -20,14 +20,14 @@ const TaskList = React.memo(({ id }) => {
const tasks = useSelector((state) => selectTasksByTaskListId(state, id));
const [isOpened, toggleOpened] = useToggle();
// TODO: move to selector?
const completedTasksTotal = useMemo(
() => tasks.reduce((result, task) => (task.isCompleted ? result + 1 : result), 0),
[tasks],
);
const [isOpened, toggleOpened] = useToggle();
const handleToggleClick = useCallback(
(event) => {
event.stopPropagation();

View file

@ -71,6 +71,11 @@ export const ListTypes = {
TRASH: 'trash',
};
export const ListTypeStates = {
OPENED: 'opened',
CLOSED: 'closed',
};
export const ListSortFieldNames = {
NAME: 'name',
DUE_DATE: 'dueDate',

View file

@ -0,0 +1,11 @@
/*!
* Copyright (c) 2024 PLANKA Software GmbH
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
*/
import { ListTypes, ListTypeStates } from './Enums';
export default {
[ListTypes.ACTIVE]: ListTypeStates.OPENED,
[ListTypes.CLOSED]: ListTypeStates.CLOSED,
};

View file

@ -10,7 +10,8 @@ import buildSearchParts from '../utils/build-search-parts';
import { isListFinite } from '../utils/record-helpers';
import ActionTypes from '../constants/ActionTypes';
import Config from '../constants/Config';
import { ListSortFieldNames, ListTypes, SortOrders } from '../constants/Enums';
import { ListSortFieldNames, ListTypes, ListTypeStates, SortOrders } from '../constants/Enums';
import LIST_TYPE_STATE_BY_TYPE from '../constants/ListTypeStateByType';
const POSITION_BY_LIST_TYPE = {
[ListTypes.ARCHIVE]: Number.MAX_SAFE_INTEGER - 1,
@ -28,6 +29,21 @@ const prepareList = (list) => {
};
};
const getChangedTypeState = (prevList, list) => {
const prevTypeState = LIST_TYPE_STATE_BY_TYPE[prevList.type];
const typeState = LIST_TYPE_STATE_BY_TYPE[list.type];
if (prevTypeState === ListTypeStates.OPENED && typeState === ListTypeStates.CLOSED) {
return ListTypeStates.CLOSED;
}
if (prevTypeState === ListTypeStates.CLOSED && typeState === ListTypeStates.OPENED) {
return ListTypeStates.OPENED;
}
return null;
};
export default class extends BaseModel {
static modelName = 'List';
@ -121,12 +137,12 @@ export default class extends BaseModel {
let isClosed;
if (payload.data.type) {
if (payload.data.type === ListTypes.CLOSED) {
if (listModel.type === ListTypes.ACTIVE) {
isClosed = true;
}
} else if (listModel.type === ListTypes.CLOSED) {
const changedTypeState = getChangedTypeState(listModel, payload.data);
if (changedTypeState === ListTypeStates.OPENED) {
isClosed = false;
} else if (changedTypeState === ListTypeStates.CLOSED) {
isClosed = true;
}
}
@ -150,13 +166,13 @@ export default class extends BaseModel {
const listModel = List.withId(payload.list.id);
if (listModel) {
const changedTypeState = getChangedTypeState(listModel, payload.list);
let isClosed;
if (payload.list.type === ListTypes.CLOSED) {
if (listModel.type === ListTypes.ACTIVE) {
isClosed = true;
}
} else if (listModel.type === ListTypes.CLOSED) {
if (changedTypeState === ListTypeStates.OPENED) {
isClosed = false;
} else if (changedTypeState === ListTypeStates.CLOSED) {
isClosed = true;
}
listModel.update(prepareList(payload.list));

View file

@ -14,7 +14,8 @@ import api from '../../../api';
import { createLocalId } from '../../../utils/local-id';
import { isListArchiveOrTrash, isListFinite } from '../../../utils/record-helpers';
import ActionTypes from '../../../constants/ActionTypes';
import { BoardViews, ListTypes } from '../../../constants/Enums';
import { BoardViews, ListTypes, ListTypeStates } from '../../../constants/Enums';
import LIST_TYPE_STATE_BY_TYPE from '../../../constants/ListTypeStateByType';
// eslint-disable-next-line no-underscore-dangle
const _preloadImage = (url) =>
@ -137,7 +138,7 @@ export function* createCard(listId, data, autoOpen) {
id: localId,
boardId: list.boardId,
creatorUserId: currentUserMembership.userId,
isClosed: list.type === ListTypes.CLOSED,
isClosed: LIST_TYPE_STATE_BY_TYPE[list.type] === ListTypeStates.CLOSED,
},
autoOpen,
),
@ -242,11 +243,13 @@ export function* updateCard(id, data) {
prevListId = null;
}
const typeState = LIST_TYPE_STATE_BY_TYPE[list.type];
if (card.isClosed) {
if (list.type === ListTypes.ACTIVE) {
if (typeState === ListTypeStates.OPENED) {
isClosed = false;
}
} else if (list.type === ListTypes.CLOSED) {
} else if (typeState === ListTypeStates.CLOSED) {
isClosed = true;
}
}