-
Notifications
You must be signed in to change notification settings - Fork 78
feat: add annotations field to Add Task Panel #266
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| import { useState, useEffect } from 'react'; | ||
| import { Badge } from '@/components/ui/badge'; | ||
| import { Button } from '@/components/ui/button'; | ||
| import { DatePicker } from '@/components/ui/date-picker'; | ||
|
|
@@ -35,6 +36,40 @@ export const AddTaskdialog = ({ | |
| setIsCreatingNewProject, | ||
| uniqueProjects = [], | ||
| }: AddTaskDialogProps) => { | ||
| const [annotationInput, setAnnotationInput] = useState(''); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it seems this takes only one Annotation as an input, please fix this as there can be many annotations!
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. updated , task can have multiple annotations like tags |
||
|
|
||
| useEffect(() => { | ||
| if (!isOpen) { | ||
| setAnnotationInput(''); | ||
| } | ||
| }, [isOpen]); | ||
|
|
||
| const handleAddAnnotation = () => { | ||
| if (annotationInput.trim()) { | ||
| const newAnnotation = { | ||
| entry: new Date().toISOString(), | ||
| description: annotationInput.trim(), | ||
| }; | ||
| setNewTask({ | ||
| ...newTask, | ||
| annotations: [...newTask.annotations, newAnnotation], | ||
| }); | ||
| setAnnotationInput(''); | ||
| } | ||
| }; | ||
|
|
||
| const handleRemoveAnnotation = (annotationToRemove: { | ||
| entry: string; | ||
| description: string; | ||
| }) => { | ||
| setNewTask({ | ||
| ...newTask, | ||
| annotations: newTask.annotations.filter( | ||
| (annotation) => annotation !== annotationToRemove | ||
| ), | ||
| }); | ||
| }; | ||
|
|
||
| const handleAddTag = () => { | ||
| if (tagInput && !newTask.tags.includes(tagInput, 0)) { | ||
| setNewTask({ ...newTask, tags: [...newTask.tags, tagInput] }); | ||
|
|
@@ -228,6 +263,42 @@ export const AddTaskdialog = ({ | |
| </div> | ||
| )} | ||
| </div> | ||
| <div className="grid grid-cols-4 items-center gap-4"> | ||
| <Label htmlFor="annotations" className="text-right"> | ||
| Annotations | ||
| </Label> | ||
| <Input | ||
| id="annotations" | ||
| name="annotations" | ||
| placeholder="Add an annotation" | ||
| value={annotationInput} | ||
| onChange={(e) => setAnnotationInput(e.target.value)} | ||
| onKeyDown={(e) => e.key === 'Enter' && handleAddAnnotation()} | ||
| className="col-span-3" | ||
| /> | ||
| </div> | ||
|
|
||
| <div className="mt-2"> | ||
| {newTask.annotations.length > 0 && ( | ||
| <div className="grid grid-cols-4 items-center"> | ||
| <div> </div> | ||
| <div className="flex flex-wrap gap-2 col-span-3"> | ||
| {newTask.annotations.map((annotation, index) => ( | ||
| <Badge key={index}> | ||
| <span>{annotation.description}</span> | ||
| <button | ||
| type="button" | ||
| className="ml-2 text-red-500" | ||
| onClick={() => handleRemoveAnnotation(annotation)} | ||
| > | ||
| ✖ | ||
| </button> | ||
| </Badge> | ||
| ))} | ||
| </div> | ||
| </div> | ||
| )} | ||
| </div> | ||
| </div> | ||
| <DialogFooter> | ||
| <Button | ||
|
|
@@ -240,7 +311,9 @@ export const AddTaskdialog = ({ | |
| <Button | ||
| className="mb-1" | ||
| variant="default" | ||
| onClick={() => onSubmit(newTask)} | ||
| onClick={() => { | ||
| onSubmit(newTask); | ||
| }} | ||
| > | ||
| Add Task | ||
| </Button> | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This annotation logic retrieves the actual task ID after creation instead of using
newestfilter, which ensures reliable annotation attachment to the correct task in Taskwarrior.