mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-05 16:23:36 +00:00
Let me create a label directly from the Project Details dialog
This commit is contained in:
1 file changed
+86
-15
@@ -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<LabelColorName>('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 (
|
||||
<div className="flex flex-wrap gap-1">
|
||||
@@ -95,7 +117,7 @@ export function LabelSelector({ projectId, compact }: LabelSelectorProps) {
|
||||
{t('selectLabels')}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
|
||||
{labels.length > 0 ? (
|
||||
<ScrollArea className="max-h-[200px]">
|
||||
<div className="p-1">
|
||||
@@ -127,18 +149,67 @@ export function LabelSelector({ projectId, compact }: LabelSelectorProps) {
|
||||
)}
|
||||
|
||||
<Separator />
|
||||
|
||||
|
||||
<div className="p-1">
|
||||
<button
|
||||
onClick={() => {
|
||||
setOpen(false);
|
||||
setManageDialogOpen(true);
|
||||
}}
|
||||
className="w-full flex items-center gap-2 px-2 py-1.5 rounded-md text-sm hover:bg-muted transition-colors"
|
||||
>
|
||||
<Plus className="h-4 w-4" />
|
||||
{t('createNewLabel')}
|
||||
</button>
|
||||
{showCreateForm ? (
|
||||
<div className="p-2 space-y-2">
|
||||
<div className="flex items-center gap-2">
|
||||
<Input
|
||||
placeholder={t('labelName')}
|
||||
value={newLabelName}
|
||||
onChange={(e) => setNewLabelName(e.target.value)}
|
||||
onKeyDown={(e) => {
|
||||
if (e.key === 'Enter') {
|
||||
handleCreateLabel();
|
||||
} else if (e.key === 'Escape') {
|
||||
handleCancelCreate();
|
||||
}
|
||||
}}
|
||||
className="flex-1 h-8"
|
||||
autoFocus
|
||||
/>
|
||||
<button
|
||||
onClick={handleCancelCreate}
|
||||
className="p-1 hover:bg-muted rounded-md transition-colors"
|
||||
title="Cancel"
|
||||
>
|
||||
<X className="h-4 w-4" />
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div className="flex flex-wrap gap-1.5">
|
||||
{LABEL_COLORS.map((color) => (
|
||||
<button
|
||||
key={color.name}
|
||||
onClick={() => setSelectedColor(color.name)}
|
||||
className={cn(
|
||||
'w-6 h-6 rounded-full transition-all',
|
||||
color.bg,
|
||||
selectedColor === color.name && 'ring-2 ring-offset-2 ring-primary'
|
||||
)}
|
||||
title={color.name}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
|
||||
<Button
|
||||
onClick={handleCreateLabel}
|
||||
disabled={!newLabelName.trim()}
|
||||
className="w-full h-8"
|
||||
size="sm"
|
||||
>
|
||||
{t('create')}
|
||||
</Button>
|
||||
</div>
|
||||
) : (
|
||||
<button
|
||||
onClick={() => setShowCreateForm(true)}
|
||||
className="w-full flex items-center gap-2 px-2 py-1.5 rounded-md text-sm hover:bg-muted transition-colors"
|
||||
>
|
||||
<Plus className="h-4 w-4" />
|
||||
{t('createNewLabel')}
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
</PopoverContent>
|
||||
</Popover>
|
||||
|
||||
Reference in new issue
Block a user