-
Notifications
You must be signed in to change notification settings - Fork 1
/
FocusTask.tsx
53 lines (50 loc) · 1.75 KB
/
FocusTask.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import React, { ReactElement } from 'react';
import { Draggable } from 'react-beautiful-dnd';
import { connect } from 'react-redux';
import InlineTaskEditor from '../../Util/TaskEditors/InlineTaskEditor';
import styles from './FocusTask.module.css';
import { State, Task } from '../../../store/store-types';
import { error } from '../../../util/general-util';
import {
getFilteredNotCompletedInFocusTask,
getFilteredCompletedInFocusTask,
} from '../../../util/task-util';
import { TaskWithSubTasks } from '../../Util/TaskEditors/editors-types';
type OwnProps = {
readonly id: string;
readonly order: number;
readonly filterCompleted: boolean;
};
type Props = OwnProps & {
readonly original: Task;
readonly filtered: TaskWithSubTasks | null;
};
function FocusTask({ id, order, filterCompleted, original, filtered }: Props): ReactElement {
if (filtered === null) {
throw new Error(`The filtered task should not be null! id: ${id}, order: ${order}`);
}
return (
<Draggable draggableId={`${id}-${filterCompleted}`} index={order}>
{(provided) => (
<div ref={provided.innerRef} {...provided.draggableProps} {...provided.dragHandleProps}>
<InlineTaskEditor
className={styles.FocusTask}
calendarPosition="bottom"
original={original}
filtered={filtered}
/>
</div>
)}
</Draggable>
);
}
const Connected = connect(
({ tasks, subTasks }: State, { id, filterCompleted }: OwnProps) => {
const original = tasks.get(id) || error();
const filtered = filterCompleted
? getFilteredCompletedInFocusTask(original, subTasks)
: getFilteredNotCompletedInFocusTask(original, subTasks);
return { original, filtered };
},
)(FocusTask);
export default Connected;