1+ import { useState , useEffect } from 'react' ;
12import { Badge } from '@/components/ui/badge' ;
23import { Button } from '@/components/ui/button' ;
34import { DatePicker } from '@/components/ui/date-picker' ;
@@ -35,6 +36,40 @@ export const AddTaskdialog = ({
3536 setIsCreatingNewProject,
3637 uniqueProjects = [ ] ,
3738} : AddTaskDialogProps ) => {
39+ const [ annotationInput , setAnnotationInput ] = useState ( '' ) ;
40+
41+ useEffect ( ( ) => {
42+ if ( ! isOpen ) {
43+ setAnnotationInput ( '' ) ;
44+ }
45+ } , [ isOpen ] ) ;
46+
47+ const handleAddAnnotation = ( ) => {
48+ if ( annotationInput . trim ( ) ) {
49+ const newAnnotation = {
50+ entry : new Date ( ) . toISOString ( ) ,
51+ description : annotationInput . trim ( ) ,
52+ } ;
53+ setNewTask ( {
54+ ...newTask ,
55+ annotations : [ ...newTask . annotations , newAnnotation ] ,
56+ } ) ;
57+ setAnnotationInput ( '' ) ;
58+ }
59+ } ;
60+
61+ const handleRemoveAnnotation = ( annotationToRemove : {
62+ entry : string ;
63+ description : string ;
64+ } ) => {
65+ setNewTask ( {
66+ ...newTask ,
67+ annotations : newTask . annotations . filter (
68+ ( annotation ) => annotation !== annotationToRemove
69+ ) ,
70+ } ) ;
71+ } ;
72+
3873 const handleAddTag = ( ) => {
3974 if ( tagInput && ! newTask . tags . includes ( tagInput , 0 ) ) {
4075 setNewTask ( { ...newTask , tags : [ ...newTask . tags , tagInput ] } ) ;
@@ -228,6 +263,42 @@ export const AddTaskdialog = ({
228263 </ div >
229264 ) }
230265 </ div >
266+ < div className = "grid grid-cols-4 items-center gap-4" >
267+ < Label htmlFor = "annotations" className = "text-right" >
268+ Annotations
269+ </ Label >
270+ < Input
271+ id = "annotations"
272+ name = "annotations"
273+ placeholder = "Add an annotation"
274+ value = { annotationInput }
275+ onChange = { ( e ) => setAnnotationInput ( e . target . value ) }
276+ onKeyDown = { ( e ) => e . key === 'Enter' && handleAddAnnotation ( ) }
277+ className = "col-span-3"
278+ />
279+ </ div >
280+
281+ < div className = "mt-2" >
282+ { newTask . annotations . length > 0 && (
283+ < div className = "grid grid-cols-4 items-center" >
284+ < div > </ div >
285+ < div className = "flex flex-wrap gap-2 col-span-3" >
286+ { newTask . annotations . map ( ( annotation , index ) => (
287+ < Badge key = { index } >
288+ < span > { annotation . description } </ span >
289+ < button
290+ type = "button"
291+ className = "ml-2 text-red-500"
292+ onClick = { ( ) => handleRemoveAnnotation ( annotation ) }
293+ >
294+ ✖
295+ </ button >
296+ </ Badge >
297+ ) ) }
298+ </ div >
299+ </ div >
300+ ) }
301+ </ div >
231302 </ div >
232303 < DialogFooter >
233304 < Button
@@ -240,7 +311,9 @@ export const AddTaskdialog = ({
240311 < Button
241312 className = "mb-1"
242313 variant = "default"
243- onClick = { ( ) => onSubmit ( newTask ) }
314+ onClick = { ( ) => {
315+ onSubmit ( newTask ) ;
316+ } }
244317 >
245318 Add Task
246319 </ Button >
0 commit comments