@@ -7,6 +7,7 @@ import remarkGfm from "remark-gfm";
7
7
import { useGlobalState } from "utils/context" ;
8
8
import styles from "./task.module.scss" ;
9
9
import { vscode } from "utils/vscode" ;
10
+ import { ColorSelector } from "components/color-selector" ;
10
11
11
12
function resizeTextArea ( textareaRef : RefObject < HTMLTextAreaElement > ) {
12
13
const target = textareaRef . current ;
@@ -18,6 +19,7 @@ function resizeTextArea(textareaRef: RefObject<HTMLTextAreaElement>) {
18
19
export default function Task ( { task, index } : { task : TaskType ; index : number } ) {
19
20
const { state, setState } = useGlobalState ( ) ;
20
21
const [ isEditing , setIsEditing ] = useState ( false ) ;
22
+ const [ showColorSelector , setShowColorSelector ] = useState ( false ) ;
21
23
const textareaRef = useRef < HTMLTextAreaElement > ( null ) ;
22
24
const id = useId ( ) ;
23
25
@@ -32,58 +34,75 @@ export default function Task({ task, index }: { task: TaskType; index: number })
32
34
setState ( { ...state , tasks, columns } ) ;
33
35
vscode . toast ( "Task deleted!" , "success" ) ;
34
36
} ;
37
+
38
+ const setColor = ( color : string ) => {
39
+ task . color = color ;
40
+ setState ( { ...state , tasks : { ...state . tasks } } ) ;
41
+ setShowColorSelector ( false ) ;
42
+ } ;
35
43
return (
36
- < Draggable draggableId = { task . id } index = { index } >
37
- { ( provided , snapshot ) => {
38
- if ( snapshot . isDragging && provided . draggableProps . style ?. transform )
39
- provided . draggableProps . style . transform += " rotate(5deg)" ;
40
- return (
41
- < label
42
- htmlFor = { id }
43
- ref = { provided . innerRef }
44
- { ...provided . draggableProps }
45
- className = { [ styles . task , isEditing ? styles . active : "" ] . join ( " " ) } >
46
- < header { ...provided . dragHandleProps } >
47
- < span > ∘∘∘</ span >
48
- < button
49
- onClick = { ( ) => {
50
- setIsEditing ( true ) ;
51
- if ( textareaRef . current ?. value ) {
52
- textareaRef . current . value = "hk" ;
53
- textareaRef . current . value = task . description ;
54
- }
55
- setTimeout ( ( ) => resizeTextArea ( textareaRef ) , 100 ) ;
56
- } } >
57
- 🖉
58
- </ button >
59
- < button className = { styles . close } onClick = { removeTask } >
60
- ✖
61
- </ button >
62
- </ header >
63
- < textarea
64
- id = { id }
65
- value = { task . description }
66
- ref = { textareaRef }
67
- onChange = { ( e ) => {
68
- task . description = e . target . value . replace ( / + / , " " ) . replace ( / \n \n + / g, "\n\n" ) ;
69
- setState ( { ...state , tasks : { ...state . tasks } } ) ;
70
- resizeTextArea ( textareaRef ) ;
71
- } }
72
- onBlur = { ( ) => setIsEditing ( false ) }
73
- placeholder = "Enter task description in Markdown format"
74
- hidden = { ! isEditing }
75
- />
76
- { ! isEditing &&
77
- ( task . description . trim ( ) ? (
78
- < ReactMarkdown rehypePlugins = { [ rehypeRaw ] } remarkPlugins = { [ remarkGfm ] } >
79
- { task . description . replace ( / \n + / g, "\n\n" ) }
80
- </ ReactMarkdown >
81
- ) : (
82
- < p className = { styles . placeholder } > Enter task description in Markdown format.</ p >
83
- ) ) }
84
- </ label >
85
- ) ;
86
- } }
87
- </ Draggable >
44
+ < >
45
+ < Draggable draggableId = { task . id } index = { index } >
46
+ { ( provided , snapshot ) => {
47
+ if ( snapshot . isDragging && provided . draggableProps . style ?. transform )
48
+ provided . draggableProps . style . transform += " rotate(5deg)" ;
49
+
50
+ return (
51
+ < div ref = { provided . innerRef } { ...provided . draggableProps } >
52
+ < label
53
+ htmlFor = { id }
54
+ className = { [ styles . task , isEditing ? styles . active : "" ] . join ( " " ) }
55
+ style = { { background : task . color } } >
56
+ < header { ...provided . dragHandleProps } >
57
+ < span > ∘∘∘</ span >
58
+ < button onClick = { ( ) => setShowColorSelector ( true ) } > 🖌</ button >
59
+ < button
60
+ onClick = { ( ) => {
61
+ setIsEditing ( true ) ;
62
+ if ( textareaRef . current ?. value ) {
63
+ textareaRef . current . value = "hk" ;
64
+ textareaRef . current . value = task . description ;
65
+ }
66
+ setTimeout ( ( ) => {
67
+ textareaRef . current && textareaRef . current . focus ( ) ;
68
+ resizeTextArea ( textareaRef ) ;
69
+ } , 100 ) ;
70
+ } } >
71
+ 🖉
72
+ </ button >
73
+ < button className = { styles . close } onClick = { removeTask } >
74
+ ✖
75
+ </ button >
76
+ </ header >
77
+ < textarea
78
+ id = { id }
79
+ value = { task . description }
80
+ ref = { textareaRef }
81
+ onChange = { ( e ) => {
82
+ task . description = e . target . value . replace ( / + / , " " ) . replace ( / \n \n + / g, "\n\n" ) ;
83
+ setState ( { ...state , tasks : { ...state . tasks } } ) ;
84
+ resizeTextArea ( textareaRef ) ;
85
+ } }
86
+ onBlur = { ( ) => setIsEditing ( false ) }
87
+ placeholder = "Enter task description in Markdown format"
88
+ hidden = { ! isEditing }
89
+ />
90
+ { ! isEditing &&
91
+ ( task . description . trim ( ) ? (
92
+ < ReactMarkdown rehypePlugins = { [ rehypeRaw ] } remarkPlugins = { [ remarkGfm ] } >
93
+ { task . description . replace ( / \n + / g, "\n\n" ) }
94
+ </ ReactMarkdown >
95
+ ) : (
96
+ < p className = { styles . placeholder } > Enter task description in Markdown format.</ p >
97
+ ) ) }
98
+ </ label >
99
+ </ div >
100
+ ) ;
101
+ } }
102
+ </ Draggable >
103
+ { showColorSelector && (
104
+ < ColorSelector color = { task . color } setColor = { setColor } onClose = { ( ) => setShowColorSelector ( false ) } />
105
+ ) }
106
+ </ >
88
107
) ;
89
108
}
0 commit comments