mirror of
https://github.com/plankanban/planka.git
synced 2025-07-20 13:49:43 +02:00
ref: Refactoring
This commit is contained in:
parent
5e073a3648
commit
cf52a00bd7
6 changed files with 101 additions and 80 deletions
|
@ -28,19 +28,22 @@ import styles from './Task.module.scss';
|
|||
|
||||
const Task = React.memo(({ id, index }) => {
|
||||
const selectTaskById = useMemo(() => selectors.makeSelectTaskById(), []);
|
||||
const selectListById = useMemo(() => selectors.makeSelectListById(), []);
|
||||
const selectCardById = useMemo(() => selectors.makeSelectCardById(), []);
|
||||
const selectListById = useMemo(() => selectors.makeSelectListById(), []);
|
||||
|
||||
const task = useSelector((state) => selectTaskById(state, id));
|
||||
|
||||
const isLinkedCardCompleted = useSelector((state) => {
|
||||
const regex = /\/cards\/([^/]+)/g;
|
||||
const matches = task.name.matchAll(regex);
|
||||
|
||||
// eslint-disable-next-line no-restricted-syntax
|
||||
for (const [, cardId] of matches) {
|
||||
const card = selectCardById(state, cardId);
|
||||
|
||||
if (card) {
|
||||
const list = selectListById(state, card.listId);
|
||||
|
||||
if (list && list.type === ListTypes.CLOSED) {
|
||||
return true;
|
||||
}
|
||||
|
@ -73,21 +76,13 @@ const Task = React.memo(({ id, index }) => {
|
|||
const [isEditNameOpened, setIsEditNameOpened] = useState(false);
|
||||
const [, , setIsClosableActive] = useContext(ClosableContext);
|
||||
|
||||
const isEditable = task.isPersisted && canEdit;
|
||||
const isCompleted = task.isCompleted || isLinkedCardCompleted;
|
||||
const isToggleDisabled = !task.isPersisted || !canToggle || isLinkedCardCompleted;
|
||||
|
||||
const handleToggleChange = useCallback(() => {
|
||||
if (isToggleDisabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
dispatch(
|
||||
entryActions.updateTask(id, {
|
||||
isCompleted: !task.isCompleted,
|
||||
}),
|
||||
);
|
||||
}, [id, task.isCompleted, dispatch, isToggleDisabled]);
|
||||
}, [id, task.isCompleted, dispatch]);
|
||||
|
||||
const handleUserSelect = useCallback(
|
||||
(userId) => {
|
||||
|
@ -108,6 +103,10 @@ const Task = React.memo(({ id, index }) => {
|
|||
);
|
||||
}, [id, dispatch]);
|
||||
|
||||
const isEditable = task.isPersisted && canEdit;
|
||||
const isCompleted = task.isCompleted || isLinkedCardCompleted;
|
||||
const isToggleDisabled = !task.isPersisted || !canToggle || isLinkedCardCompleted;
|
||||
|
||||
const handleClick = useCallback(() => {
|
||||
if (isEditable) {
|
||||
setIsEditNameOpened(true);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue