From bc976fd58e74a3d1c6290b823a0919f3815f926b Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Fri, 5 Dec 2025 16:24:41 -0600 Subject: [PATCH] Let me create a label directly from the Project Details dialog --- src/components/labels/LabelSelector.tsx | 101 ++++++++++++++++++++---- 1 file changed, 86 insertions(+), 15 deletions(-) diff --git a/src/components/labels/LabelSelector.tsx b/src/components/labels/LabelSelector.tsx index cec82beb..fcfe25a7 100644 --- a/src/components/labels/LabelSelector.tsx +++ b/src/components/labels/LabelSelector.tsx @@ -1,6 +1,6 @@ import { useState } from 'react'; import { useTranslation } from 'react-i18next'; -import { Check, Plus, Tag } from 'lucide-react'; +import { Check, Plus, Tag, X } from 'lucide-react'; import { Button } from '@/components/ui/button'; import { Popover, @@ -9,7 +9,8 @@ import { } from '@/components/ui/popover'; import { ScrollArea } from '@/components/ui/scroll-area'; import { Separator } from '@/components/ui/separator'; -import { useLabels, getLabelColor, type Label } from '@/hooks/useLabels'; +import { Input } from '@/components/ui/input'; +import { useLabels, getLabelColor, LABEL_COLORS, type Label, type LabelColorName } from '@/hooks/useLabels'; import { useProjectLabels } from '@/hooks/useProjectLabels'; import { LabelsManageDialog } from './LabelsManageDialog'; import { cn } from '@/lib/utils'; @@ -22,10 +23,13 @@ interface LabelSelectorProps { export function LabelSelector({ projectId, compact }: LabelSelectorProps) { const { t } = useTranslation(); - const { labels } = useLabels(); + const { labels, createLabel } = useLabels(); const { getProjectLabels, addLabelToProject, removeLabelFromProject } = useProjectLabels(); const [open, setOpen] = useState(false); const [manageDialogOpen, setManageDialogOpen] = useState(false); + const [showCreateForm, setShowCreateForm] = useState(false); + const [newLabelName, setNewLabelName] = useState(''); + const [selectedColor, setSelectedColor] = useState('blue'); const projectLabelIds = getProjectLabels(projectId); const projectLabels = labels.filter(label => projectLabelIds.includes(label.id)); @@ -38,6 +42,24 @@ export function LabelSelector({ projectId, compact }: LabelSelectorProps) { } }; + const handleCreateLabel = () => { + if (!newLabelName.trim()) return; + + const newLabel = createLabel(newLabelName.trim(), selectedColor); + addLabelToProject(projectId, newLabel.id); + + // Reset form + setNewLabelName(''); + setSelectedColor('blue'); + setShowCreateForm(false); + }; + + const handleCancelCreate = () => { + setNewLabelName(''); + setSelectedColor('blue'); + setShowCreateForm(false); + }; + if (compact) { return (
@@ -95,7 +117,7 @@ export function LabelSelector({ projectId, compact }: LabelSelectorProps) { {t('selectLabels')}

- + {labels.length > 0 ? (
@@ -127,18 +149,67 @@ export function LabelSelector({ projectId, compact }: LabelSelectorProps) { )} - +
- + {showCreateForm ? ( +
+
+ setNewLabelName(e.target.value)} + onKeyDown={(e) => { + if (e.key === 'Enter') { + handleCreateLabel(); + } else if (e.key === 'Escape') { + handleCancelCreate(); + } + }} + className="flex-1 h-8" + autoFocus + /> + +
+ +
+ {LABEL_COLORS.map((color) => ( +
+ + +
+ ) : ( + + )}