import React, { useCallback, useRef } from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import { Button, Icon } from 'semantic-ui-react';
import { Link } from 'react-router-dom';
import { Draggable } from 'react-beautiful-dnd';
import { usePopup } from '../../lib/popup';
import { startStopwatch, stopStopwatch } from '../../utils/stopwatch';
import Paths from '../../constants/Paths';
import Tasks from './Tasks';
import NameEdit from './NameEdit';
import ActionsStep from './ActionsStep';
import User from '../User';
import Label from '../Label';
import DueDate from '../DueDate';
import Stopwatch from '../Stopwatch';
import styles from './Card.module.scss';
const Card = React.memo(
({
id,
index,
name,
dueDate,
dueCompleted,
stopwatch,
coverUrl,
boardId,
listId,
projectId,
isPersisted,
notificationsTotal,
users,
labels,
tasks,
allProjectsToLists,
allBoardMemberships,
allLabels,
canEdit,
onUpdate,
onMove,
onTransfer,
onDuplicate,
onDelete,
onUserAdd,
onUserRemove,
onBoardFetch,
onLabelAdd,
onLabelRemove,
onLabelCreate,
onLabelUpdate,
onLabelMove,
onLabelDelete,
}) => {
const nameEdit = useRef(null);
const handleClick = useCallback(() => {
if (document.activeElement) {
document.activeElement.blur();
}
}, []);
const handleToggleStopwatchClick = useCallback(
(event) => {
event.preventDefault();
onUpdate({
stopwatch: stopwatch.startedAt ? stopStopwatch(stopwatch) : startStopwatch(stopwatch),
});
},
[stopwatch, onUpdate],
);
const handleNameUpdate = useCallback(
(newName) => {
onUpdate({
name: newName,
});
},
[onUpdate],
);
const handleDueDateCompletionUpdate = useCallback(
(dueDateCompleted) => {
onUpdate({
dueDateCompleted,
});
},
[onUpdate],
);
const handleNameEdit = useCallback(() => {
nameEdit.current.open();
}, []);
const ActionsPopup = usePopup(ActionsStep);
const contentNode = (
<>
{coverUrl && }