mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-05 16:23:36 +00:00
Add project labels feature similar to Gmail labels
Features: - Create and manage labels with customizable colors (18 color options) - Assign multiple labels to projects via Project Details dialog - Display settings in Preferences (only shown when labels exist): - Colored folder icons: Show project folder icons in label color - Group by label: Organize sidebar projects into collapsible groups - Labels work alongside existing favorites (starred) system: - Favorites still sort to top within label groups - Star indicator remains visible in all display modes - Collapsible label groups in sidebar (state persists) - Unlabeled projects shown at bottom when grouping is enabled - No UI changes for users without labels (settings hidden until first label) Technical: - useLabels hook: Manage labels CRUD and display settings - useProjectLabels hook: Manage project-label assignments - LabelSelector component: Assign labels to projects - LabelsManageDialog: Create, edit, delete labels - Full i18n support for EN, PT, ZH, HA, YO, IG
This commit is contained in:
1 parent
a2ffc7bf9c
commit
63d23f5510
14 files changed
+1009
-11
No files matched your search
@@ -36,10 +36,12 @@ import {
|
||||
DollarSign,
|
||||
ExternalLink,
|
||||
FileCode,
|
||||
Tag,
|
||||
} from 'lucide-react';
|
||||
import JSZip from 'jszip';
|
||||
import { Separator } from './ui/separator';
|
||||
import { DotAI } from '@/lib/DotAI';
|
||||
import { LabelSelector } from '@/components/labels/LabelSelector';
|
||||
|
||||
interface ProjectDetailsDialogProps {
|
||||
project: Project;
|
||||
@@ -283,6 +285,15 @@ export function ProjectDetailsDialog({ project, open, onOpenChange, onProjectDel
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Labels */}
|
||||
<div className="space-y-2">
|
||||
<Label className="flex items-center gap-2">
|
||||
<Tag className="h-4 w-4 text-muted-foreground" />
|
||||
Labels
|
||||
</Label>
|
||||
<LabelSelector projectId={project.id} />
|
||||
</div>
|
||||
|
||||
{/* Project Name */}
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="project-name">Project Name</Label>
|
||||
|
||||
@@ -1,15 +1,18 @@
|
||||
import React, { useEffect, useState, useMemo } from 'react';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { Plus, Folder, GitBranch, Loader2, ChevronDown, Star, Columns2, X, Settings, HelpCircle, Search } from 'lucide-react';
|
||||
import { Plus, Folder, GitBranch, Loader2, ChevronDown, ChevronRight, Star, Columns2, X, Settings, HelpCircle, Search } from 'lucide-react';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Skeleton } from '@/components/ui/skeleton';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from '@/components/ui/dropdown-menu';
|
||||
import { Collapsible, CollapsibleContent, CollapsibleTrigger } from '@/components/ui/collapsible';
|
||||
import { useProjects } from '@/hooks/useProjects';
|
||||
import { useProjectSessionStatus } from '@/hooks/useProjectSessionStatus';
|
||||
import { useLocalStorage } from '@/hooks/useLocalStorage';
|
||||
import { useIsMobile } from '@/hooks/useIsMobile';
|
||||
import { useLabels, getLabelColor } from '@/hooks/useLabels';
|
||||
import { useProjectLabels } from '@/hooks/useProjectLabels';
|
||||
import type { Project } from '@/lib/ProjectsManager';
|
||||
import { cn } from '@/lib/utils';
|
||||
import { useQueryClient } from '@tanstack/react-query';
|
||||
@@ -20,9 +23,18 @@ interface ProjectItemProps {
|
||||
isSelected: boolean;
|
||||
onSelect: (project: Project) => void;
|
||||
isFavorite?: boolean;
|
||||
labelColor?: string;
|
||||
showColoredIcon?: boolean;
|
||||
}
|
||||
|
||||
const ProjectItem: React.FC<ProjectItemProps> = ({ project, isSelected, onSelect, isFavorite }) => {
|
||||
const ProjectItem: React.FC<ProjectItemProps> = ({
|
||||
project,
|
||||
isSelected,
|
||||
onSelect,
|
||||
isFavorite,
|
||||
labelColor,
|
||||
showColoredIcon = false,
|
||||
}) => {
|
||||
const navigate = useNavigate();
|
||||
const { hasRunningSessions } = useProjectSessionStatus(project.id);
|
||||
|
||||
@@ -31,6 +43,15 @@ const ProjectItem: React.FC<ProjectItemProps> = ({ project, isSelected, onSelect
|
||||
navigate(`/project/${project.id}`);
|
||||
};
|
||||
|
||||
// Determine folder icon color
|
||||
const getFolderColorClass = () => {
|
||||
if (showColoredIcon && labelColor) {
|
||||
const colorConfig = getLabelColor(labelColor as Parameters<typeof getLabelColor>[0]);
|
||||
return colorConfig.text;
|
||||
}
|
||||
return 'text-primary';
|
||||
};
|
||||
|
||||
return (
|
||||
<div
|
||||
className={cn(
|
||||
@@ -48,7 +69,7 @@ const ProjectItem: React.FC<ProjectItemProps> = ({ project, isSelected, onSelect
|
||||
{hasRunningSessions ? (
|
||||
<Loader2 className="h-4 w-4 animate-spin text-blue-600 dark:text-blue-400" />
|
||||
) : (
|
||||
<Folder className="h-4 w-4 text-primary" />
|
||||
<Folder className={cn("h-4 w-4", getFolderColorClass())} />
|
||||
)}
|
||||
</div>
|
||||
<div className="flex justify-between gap-2 flex-1 min-w-0">
|
||||
@@ -75,6 +96,41 @@ const ProjectItem: React.FC<ProjectItemProps> = ({ project, isSelected, onSelect
|
||||
|
||||
ProjectItem.displayName = 'ProjectItem';
|
||||
|
||||
/** Label group header component */
|
||||
interface LabelGroupHeaderProps {
|
||||
labelName: string;
|
||||
labelColor: string;
|
||||
isCollapsed: boolean;
|
||||
onToggle: () => void;
|
||||
projectCount: number;
|
||||
}
|
||||
|
||||
const LabelGroupHeader: React.FC<LabelGroupHeaderProps> = ({
|
||||
labelName,
|
||||
labelColor,
|
||||
isCollapsed,
|
||||
onToggle,
|
||||
projectCount,
|
||||
}) => {
|
||||
const colorConfig = getLabelColor(labelColor as Parameters<typeof getLabelColor>[0]);
|
||||
|
||||
return (
|
||||
<button
|
||||
onClick={onToggle}
|
||||
className="w-full flex items-center gap-2 px-3 py-1.5 text-xs font-medium text-muted-foreground hover:text-foreground transition-colors"
|
||||
>
|
||||
{isCollapsed ? (
|
||||
<ChevronRight className="h-3 w-3" />
|
||||
) : (
|
||||
<ChevronDown className="h-3 w-3" />
|
||||
)}
|
||||
<div className={cn('w-2 h-2 rounded-full', colorConfig.bg)} />
|
||||
<span className="flex-1 text-left truncate">{labelName}</span>
|
||||
<span className="text-[10px] opacity-60">{projectCount}</span>
|
||||
</button>
|
||||
);
|
||||
};
|
||||
|
||||
interface ProjectSidebarProps {
|
||||
selectedProject: Project | null;
|
||||
onSelectProject: (project: Project | null) => void;
|
||||
@@ -95,10 +151,15 @@ export function ProjectSidebar({
|
||||
const { data: projects = [], isLoading, error } = useProjects();
|
||||
const [favorites] = useLocalStorage<string[]>('project-favorites', []);
|
||||
const [searchQuery, setSearchQuery] = useState('');
|
||||
const { labels, displaySettings, toggleLabelCollapsed } = useLabels();
|
||||
const { getProjectLabels, hasAnyLabels } = useProjectLabels();
|
||||
|
||||
const isMobile = useIsMobile();
|
||||
const navigate = useNavigate();
|
||||
|
||||
// Determine if we should show grouped view
|
||||
const showGroupedView = displaySettings.groupByLabel && labels.length > 0 && hasAnyLabels();
|
||||
|
||||
// Fast in-memory search filtering
|
||||
const filteredProjects = useMemo(() => {
|
||||
if (!searchQuery.trim()) {
|
||||
@@ -112,6 +173,65 @@ export function ProjectSidebar({
|
||||
);
|
||||
}, [projects, searchQuery]);
|
||||
|
||||
// Group projects by label for grouped view
|
||||
const groupedProjects = useMemo(() => {
|
||||
if (!showGroupedView) return null;
|
||||
|
||||
const groups: Map<string, Project[]> = new Map();
|
||||
const unlabeled: Project[] = [];
|
||||
|
||||
// Initialize groups for each label in order
|
||||
for (const label of labels) {
|
||||
groups.set(label.id, []);
|
||||
}
|
||||
|
||||
// Sort projects into groups
|
||||
for (const project of filteredProjects) {
|
||||
const projectLabelIds = getProjectLabels(project.id);
|
||||
if (projectLabelIds.length === 0) {
|
||||
unlabeled.push(project);
|
||||
} else {
|
||||
// Add project to the first label group (primary label)
|
||||
const primaryLabelId = projectLabelIds[0];
|
||||
const group = groups.get(primaryLabelId);
|
||||
if (group) {
|
||||
group.push(project);
|
||||
} else {
|
||||
// Label might have been deleted
|
||||
unlabeled.push(project);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Sort each group: favorites first, then by lastModified
|
||||
const sortGroup = (projectList: Project[]) => {
|
||||
return projectList.sort((a, b) => {
|
||||
const aIsFavorite = favorites.includes(a.id);
|
||||
const bIsFavorite = favorites.includes(b.id);
|
||||
if (aIsFavorite && !bIsFavorite) return -1;
|
||||
if (!aIsFavorite && bIsFavorite) return 1;
|
||||
return b.lastModified.getTime() - a.lastModified.getTime();
|
||||
});
|
||||
};
|
||||
|
||||
for (const [labelId, projectList] of groups) {
|
||||
groups.set(labelId, sortGroup(projectList));
|
||||
}
|
||||
|
||||
return {
|
||||
groups,
|
||||
unlabeled: sortGroup(unlabeled),
|
||||
};
|
||||
}, [showGroupedView, labels, filteredProjects, getProjectLabels, favorites]);
|
||||
|
||||
// Get the first label color for a project (for colored icon display)
|
||||
const getProjectLabelColor = (projectId: string): string | undefined => {
|
||||
const projectLabelIds = getProjectLabels(projectId);
|
||||
if (projectLabelIds.length === 0) return undefined;
|
||||
const label = labels.find(l => l.id === projectLabelIds[0]);
|
||||
return label?.color;
|
||||
};
|
||||
|
||||
// Custom navigate function that closes sidebar on mobile
|
||||
const navigateAndClose = (path: string) => {
|
||||
navigate(path);
|
||||
@@ -249,7 +369,72 @@ export function ProjectSidebar({
|
||||
<p className="text-sm">{t('noProjectsFound')}</p>
|
||||
<p className="text-xs">{t('tryDifferentSearch')}</p>
|
||||
</div>
|
||||
) : showGroupedView && groupedProjects ? (
|
||||
// Grouped view by labels
|
||||
<div className="space-y-1">
|
||||
{/* Render each label group */}
|
||||
{labels.map((label) => {
|
||||
const groupProjects = groupedProjects.groups.get(label.id) || [];
|
||||
if (groupProjects.length === 0) return null;
|
||||
|
||||
return (
|
||||
<Collapsible
|
||||
key={label.id}
|
||||
open={!label.collapsed}
|
||||
onOpenChange={() => toggleLabelCollapsed(label.id)}
|
||||
>
|
||||
<CollapsibleTrigger asChild>
|
||||
<div>
|
||||
<LabelGroupHeader
|
||||
labelName={label.name}
|
||||
labelColor={label.color}
|
||||
isCollapsed={!!label.collapsed}
|
||||
onToggle={() => toggleLabelCollapsed(label.id)}
|
||||
projectCount={groupProjects.length}
|
||||
/>
|
||||
</div>
|
||||
</CollapsibleTrigger>
|
||||
<CollapsibleContent>
|
||||
<div className="space-y-0.5 ml-2">
|
||||
{groupProjects.map((project) => (
|
||||
<ProjectItem
|
||||
key={project.id}
|
||||
project={project}
|
||||
isSelected={selectedProject?.id === project.id}
|
||||
onSelect={onSelectProject}
|
||||
isFavorite={favorites.includes(project.id)}
|
||||
labelColor={label.color}
|
||||
showColoredIcon={displaySettings.showColoredIcons}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
</CollapsibleContent>
|
||||
</Collapsible>
|
||||
);
|
||||
})}
|
||||
|
||||
{/* Unlabeled projects */}
|
||||
{groupedProjects.unlabeled.length > 0 && (
|
||||
<div className="space-y-0.5 mt-2">
|
||||
{labels.some(l => (groupedProjects.groups.get(l.id)?.length || 0) > 0) && (
|
||||
<div className="px-3 py-1.5 text-xs font-medium text-muted-foreground">
|
||||
{t('unlabeled')}
|
||||
</div>
|
||||
)}
|
||||
{groupedProjects.unlabeled.map((project) => (
|
||||
<ProjectItem
|
||||
key={project.id}
|
||||
project={project}
|
||||
isSelected={selectedProject?.id === project.id}
|
||||
onSelect={onSelectProject}
|
||||
isFavorite={favorites.includes(project.id)}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
) : (
|
||||
// Flat view (default)
|
||||
<div className="space-y-1">
|
||||
{filteredProjects.map((project) => (
|
||||
<ProjectItem
|
||||
@@ -258,6 +443,8 @@ export function ProjectSidebar({
|
||||
isSelected={selectedProject?.id === project.id}
|
||||
onSelect={onSelectProject}
|
||||
isFavorite={favorites.includes(project.id)}
|
||||
labelColor={getProjectLabelColor(project.id)}
|
||||
showColoredIcon={displaySettings.showColoredIcons}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
|
||||
@@ -0,0 +1,152 @@
|
||||
import { useState } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { Check, Plus, Tag } from 'lucide-react';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import {
|
||||
Popover,
|
||||
PopoverContent,
|
||||
PopoverTrigger,
|
||||
} 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 { useProjectLabels } from '@/hooks/useProjectLabels';
|
||||
import { LabelsManageDialog } from './LabelsManageDialog';
|
||||
import { cn } from '@/lib/utils';
|
||||
|
||||
interface LabelSelectorProps {
|
||||
projectId: string;
|
||||
/** Render as a compact badge list (for inline display) */
|
||||
compact?: boolean;
|
||||
}
|
||||
|
||||
export function LabelSelector({ projectId, compact }: LabelSelectorProps) {
|
||||
const { t } = useTranslation();
|
||||
const { labels } = useLabels();
|
||||
const { getProjectLabels, addLabelToProject, removeLabelFromProject } = useProjectLabels();
|
||||
const [open, setOpen] = useState(false);
|
||||
const [manageDialogOpen, setManageDialogOpen] = useState(false);
|
||||
|
||||
const projectLabelIds = getProjectLabels(projectId);
|
||||
const projectLabels = labels.filter(label => projectLabelIds.includes(label.id));
|
||||
|
||||
const handleToggleLabel = (label: Label) => {
|
||||
if (projectLabelIds.includes(label.id)) {
|
||||
removeLabelFromProject(projectId, label.id);
|
||||
} else {
|
||||
addLabelToProject(projectId, label.id);
|
||||
}
|
||||
};
|
||||
|
||||
if (compact) {
|
||||
return (
|
||||
<div className="flex flex-wrap gap-1">
|
||||
{projectLabels.map((label) => {
|
||||
const colorConfig = getLabelColor(label.color);
|
||||
return (
|
||||
<span
|
||||
key={label.id}
|
||||
className={cn(
|
||||
'inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-xs font-medium',
|
||||
colorConfig.bg,
|
||||
'text-white'
|
||||
)}
|
||||
>
|
||||
{label.name}
|
||||
</span>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<Popover open={open} onOpenChange={setOpen}>
|
||||
<PopoverTrigger asChild>
|
||||
<Button variant="outline" className="w-full justify-start gap-2">
|
||||
<Tag className="h-4 w-4" />
|
||||
{projectLabels.length > 0 ? (
|
||||
<div className="flex flex-wrap gap-1 flex-1">
|
||||
{projectLabels.map((label) => {
|
||||
const colorConfig = getLabelColor(label.color);
|
||||
return (
|
||||
<span
|
||||
key={label.id}
|
||||
className={cn(
|
||||
'inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-xs font-medium',
|
||||
colorConfig.bg,
|
||||
'text-white'
|
||||
)}
|
||||
>
|
||||
{label.name}
|
||||
</span>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
) : (
|
||||
<span className="text-muted-foreground">{t('addLabel')}</span>
|
||||
)}
|
||||
</Button>
|
||||
</PopoverTrigger>
|
||||
<PopoverContent className="w-64 p-0" align="start">
|
||||
<div className="p-2">
|
||||
<p className="text-xs font-medium text-muted-foreground px-2 py-1">
|
||||
{t('selectLabels')}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
{labels.length > 0 ? (
|
||||
<ScrollArea className="max-h-[200px]">
|
||||
<div className="p-1">
|
||||
{labels.map((label) => {
|
||||
const colorConfig = getLabelColor(label.color);
|
||||
const isSelected = projectLabelIds.includes(label.id);
|
||||
return (
|
||||
<button
|
||||
key={label.id}
|
||||
onClick={() => handleToggleLabel(label)}
|
||||
className={cn(
|
||||
'w-full flex items-center gap-2 px-2 py-1.5 rounded-md text-sm',
|
||||
'hover:bg-muted transition-colors',
|
||||
isSelected && 'bg-muted'
|
||||
)}
|
||||
>
|
||||
<div className={cn('w-3 h-3 rounded-full', colorConfig.bg)} />
|
||||
<span className="flex-1 text-left">{label.name}</span>
|
||||
{isSelected && <Check className="h-4 w-4 text-primary" />}
|
||||
</button>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</ScrollArea>
|
||||
) : (
|
||||
<div className="p-4 text-center text-sm text-muted-foreground">
|
||||
{t('noLabelsCreated')}
|
||||
</div>
|
||||
)}
|
||||
|
||||
<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>
|
||||
</div>
|
||||
</PopoverContent>
|
||||
</Popover>
|
||||
|
||||
<LabelsManageDialog
|
||||
open={manageDialogOpen}
|
||||
onOpenChange={setManageDialogOpen}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,251 @@
|
||||
import { useState } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { Plus, Trash2, GripVertical, Pencil, Check, X } from 'lucide-react';
|
||||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
} from '@/components/ui/dialog';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { Label } from '@/components/ui/label';
|
||||
import { ScrollArea } from '@/components/ui/scroll-area';
|
||||
import {
|
||||
AlertDialog,
|
||||
AlertDialogAction,
|
||||
AlertDialogCancel,
|
||||
AlertDialogContent,
|
||||
AlertDialogDescription,
|
||||
AlertDialogFooter,
|
||||
AlertDialogHeader,
|
||||
AlertDialogTitle,
|
||||
} from '@/components/ui/alert-dialog';
|
||||
import { useLabels, LABEL_COLORS, getLabelColor, type LabelColorName, type Label as LabelType } from '@/hooks/useLabels';
|
||||
import { useProjectLabels } from '@/hooks/useProjectLabels';
|
||||
import { cn } from '@/lib/utils';
|
||||
|
||||
interface LabelsManageDialogProps {
|
||||
open: boolean;
|
||||
onOpenChange: (open: boolean) => void;
|
||||
}
|
||||
|
||||
interface LabelItemProps {
|
||||
label: LabelType;
|
||||
onEdit: (label: LabelType) => void;
|
||||
onDelete: (label: LabelType) => void;
|
||||
projectCount: number;
|
||||
}
|
||||
|
||||
function LabelItem({ label, onEdit, onDelete, projectCount }: LabelItemProps) {
|
||||
const colorConfig = getLabelColor(label.color);
|
||||
|
||||
return (
|
||||
<div className="flex items-center gap-2 p-2 rounded-lg hover:bg-muted/50 group">
|
||||
<GripVertical className="h-4 w-4 text-muted-foreground opacity-0 group-hover:opacity-100 cursor-grab" />
|
||||
<div className={cn('w-3 h-3 rounded-full', colorConfig.bg)} />
|
||||
<span className="flex-1 text-sm font-medium">{label.name}</span>
|
||||
<span className="text-xs text-muted-foreground">
|
||||
{projectCount} {projectCount === 1 ? 'project' : 'projects'}
|
||||
</span>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
className="h-7 w-7 p-0 opacity-0 group-hover:opacity-100"
|
||||
onClick={() => onEdit(label)}
|
||||
>
|
||||
<Pencil className="h-3.5 w-3.5" />
|
||||
</Button>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
className="h-7 w-7 p-0 opacity-0 group-hover:opacity-100 hover:text-destructive"
|
||||
onClick={() => onDelete(label)}
|
||||
>
|
||||
<Trash2 className="h-3.5 w-3.5" />
|
||||
</Button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
interface LabelFormProps {
|
||||
initialName?: string;
|
||||
initialColor?: LabelColorName;
|
||||
onSave: (name: string, color: LabelColorName) => void;
|
||||
onCancel: () => void;
|
||||
isEditing?: boolean;
|
||||
}
|
||||
|
||||
function LabelForm({ initialName = '', initialColor = 'blue', onSave, onCancel, isEditing }: LabelFormProps) {
|
||||
const { t } = useTranslation();
|
||||
const [name, setName] = useState(initialName);
|
||||
const [color, setColor] = useState<LabelColorName>(initialColor);
|
||||
|
||||
const handleSubmit = (e: React.FormEvent) => {
|
||||
e.preventDefault();
|
||||
if (name.trim()) {
|
||||
onSave(name.trim(), color);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<form onSubmit={handleSubmit} className="space-y-4 p-4 border rounded-lg bg-muted/30">
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="label-name">{t('labelName')}</Label>
|
||||
<Input
|
||||
id="label-name"
|
||||
value={name}
|
||||
onChange={(e) => setName(e.target.value)}
|
||||
placeholder={t('enterLabelName')}
|
||||
autoFocus
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="space-y-2">
|
||||
<Label>{t('labelColor')}</Label>
|
||||
<div className="flex flex-wrap gap-2">
|
||||
{LABEL_COLORS.map((colorOption) => (
|
||||
<button
|
||||
key={colorOption.name}
|
||||
type="button"
|
||||
onClick={() => setColor(colorOption.name)}
|
||||
className={cn(
|
||||
'w-6 h-6 rounded-full transition-all',
|
||||
colorOption.bg,
|
||||
color === colorOption.name && 'ring-2 ring-offset-2 ring-primary'
|
||||
)}
|
||||
title={colorOption.name}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="flex justify-end gap-2">
|
||||
<Button type="button" variant="ghost" size="sm" onClick={onCancel}>
|
||||
<X className="h-4 w-4 mr-1" />
|
||||
{t('cancel')}
|
||||
</Button>
|
||||
<Button type="submit" size="sm" disabled={!name.trim()}>
|
||||
<Check className="h-4 w-4 mr-1" />
|
||||
{isEditing ? t('save') : t('create')}
|
||||
</Button>
|
||||
</div>
|
||||
</form>
|
||||
);
|
||||
}
|
||||
|
||||
export function LabelsManageDialog({ open, onOpenChange }: LabelsManageDialogProps) {
|
||||
const { t } = useTranslation();
|
||||
const { labels, createLabel, updateLabel, deleteLabel } = useLabels();
|
||||
const { getProjectsByLabel, removeLabel: removeLabelFromProjects } = useProjectLabels();
|
||||
|
||||
const [showCreateForm, setShowCreateForm] = useState(false);
|
||||
const [editingLabel, setEditingLabel] = useState<LabelType | null>(null);
|
||||
const [deletingLabel, setDeletingLabel] = useState<LabelType | null>(null);
|
||||
|
||||
const handleCreateLabel = (name: string, color: LabelColorName) => {
|
||||
createLabel(name, color);
|
||||
setShowCreateForm(false);
|
||||
};
|
||||
|
||||
const handleUpdateLabel = (name: string, color: LabelColorName) => {
|
||||
if (editingLabel) {
|
||||
updateLabel(editingLabel.id, { name, color });
|
||||
setEditingLabel(null);
|
||||
}
|
||||
};
|
||||
|
||||
const handleConfirmDelete = () => {
|
||||
if (deletingLabel) {
|
||||
// Remove label from all projects first
|
||||
removeLabelFromProjects(deletingLabel.id);
|
||||
// Then delete the label itself
|
||||
deleteLabel(deletingLabel.id);
|
||||
setDeletingLabel(null);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<Dialog open={open} onOpenChange={onOpenChange}>
|
||||
<DialogContent className="max-w-md">
|
||||
<DialogHeader>
|
||||
<DialogTitle className="flex items-center gap-2">
|
||||
{t('manageLabels')}
|
||||
</DialogTitle>
|
||||
</DialogHeader>
|
||||
|
||||
<div className="space-y-4">
|
||||
{/* Create new label button/form */}
|
||||
{showCreateForm ? (
|
||||
<LabelForm
|
||||
onSave={handleCreateLabel}
|
||||
onCancel={() => setShowCreateForm(false)}
|
||||
/>
|
||||
) : editingLabel ? (
|
||||
<LabelForm
|
||||
initialName={editingLabel.name}
|
||||
initialColor={editingLabel.color}
|
||||
onSave={handleUpdateLabel}
|
||||
onCancel={() => setEditingLabel(null)}
|
||||
isEditing
|
||||
/>
|
||||
) : (
|
||||
<Button
|
||||
variant="outline"
|
||||
className="w-full justify-start gap-2"
|
||||
onClick={() => setShowCreateForm(true)}
|
||||
>
|
||||
<Plus className="h-4 w-4" />
|
||||
{t('createLabel')}
|
||||
</Button>
|
||||
)}
|
||||
|
||||
{/* Labels list */}
|
||||
{labels.length > 0 ? (
|
||||
<ScrollArea className="h-[300px]">
|
||||
<div className="space-y-1">
|
||||
{labels.map((label) => (
|
||||
<LabelItem
|
||||
key={label.id}
|
||||
label={label}
|
||||
onEdit={setEditingLabel}
|
||||
onDelete={setDeletingLabel}
|
||||
projectCount={getProjectsByLabel(label.id).length}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
</ScrollArea>
|
||||
) : !showCreateForm && (
|
||||
<div className="text-center py-8 text-muted-foreground">
|
||||
<p className="text-sm">{t('noLabelsYet')}</p>
|
||||
<p className="text-xs mt-1">{t('createLabelToOrganize')}</p>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
|
||||
{/* Delete confirmation dialog */}
|
||||
<AlertDialog open={!!deletingLabel} onOpenChange={() => setDeletingLabel(null)}>
|
||||
<AlertDialogContent>
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogTitle>{t('deleteLabel')}</AlertDialogTitle>
|
||||
<AlertDialogDescription>
|
||||
{t('deleteLabelConfirmation', { name: deletingLabel?.name })}
|
||||
</AlertDialogDescription>
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogCancel>{t('cancel')}</AlertDialogCancel>
|
||||
<AlertDialogAction
|
||||
onClick={handleConfirmDelete}
|
||||
className="bg-destructive text-destructive-foreground hover:bg-destructive/90"
|
||||
>
|
||||
{t('delete')}
|
||||
</AlertDialogAction>
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogContent>
|
||||
</AlertDialog>
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
export { LabelsManageDialog } from './LabelsManageDialog';
|
||||
export { LabelSelector } from './LabelSelector';
|
||||
@@ -0,0 +1,118 @@
|
||||
import { useLocalStorage } from '@/hooks/useLocalStorage';
|
||||
|
||||
/** Predefined label colors */
|
||||
export const LABEL_COLORS = [
|
||||
{ name: 'red', bg: 'bg-red-500', text: 'text-red-500', hover: 'hover:bg-red-500/20' },
|
||||
{ name: 'orange', bg: 'bg-orange-500', text: 'text-orange-500', hover: 'hover:bg-orange-500/20' },
|
||||
{ name: 'amber', bg: 'bg-amber-500', text: 'text-amber-500', hover: 'hover:bg-amber-500/20' },
|
||||
{ name: 'yellow', bg: 'bg-yellow-500', text: 'text-yellow-500', hover: 'hover:bg-yellow-500/20' },
|
||||
{ name: 'lime', bg: 'bg-lime-500', text: 'text-lime-500', hover: 'hover:bg-lime-500/20' },
|
||||
{ name: 'green', bg: 'bg-green-500', text: 'text-green-500', hover: 'hover:bg-green-500/20' },
|
||||
{ name: 'emerald', bg: 'bg-emerald-500', text: 'text-emerald-500', hover: 'hover:bg-emerald-500/20' },
|
||||
{ name: 'teal', bg: 'bg-teal-500', text: 'text-teal-500', hover: 'hover:bg-teal-500/20' },
|
||||
{ name: 'cyan', bg: 'bg-cyan-500', text: 'text-cyan-500', hover: 'hover:bg-cyan-500/20' },
|
||||
{ name: 'sky', bg: 'bg-sky-500', text: 'text-sky-500', hover: 'hover:bg-sky-500/20' },
|
||||
{ name: 'blue', bg: 'bg-blue-500', text: 'text-blue-500', hover: 'hover:bg-blue-500/20' },
|
||||
{ name: 'indigo', bg: 'bg-indigo-500', text: 'text-indigo-500', hover: 'hover:bg-indigo-500/20' },
|
||||
{ name: 'violet', bg: 'bg-violet-500', text: 'text-violet-500', hover: 'hover:bg-violet-500/20' },
|
||||
{ name: 'purple', bg: 'bg-purple-500', text: 'text-purple-500', hover: 'hover:bg-purple-500/20' },
|
||||
{ name: 'fuchsia', bg: 'bg-fuchsia-500', text: 'text-fuchsia-500', hover: 'hover:bg-fuchsia-500/20' },
|
||||
{ name: 'pink', bg: 'bg-pink-500', text: 'text-pink-500', hover: 'hover:bg-pink-500/20' },
|
||||
{ name: 'rose', bg: 'bg-rose-500', text: 'text-rose-500', hover: 'hover:bg-rose-500/20' },
|
||||
{ name: 'gray', bg: 'bg-gray-500', text: 'text-gray-500', hover: 'hover:bg-gray-500/20' },
|
||||
] as const;
|
||||
|
||||
export type LabelColorName = typeof LABEL_COLORS[number]['name'];
|
||||
|
||||
export interface Label {
|
||||
id: string;
|
||||
name: string;
|
||||
color: LabelColorName;
|
||||
order: number;
|
||||
collapsed?: boolean;
|
||||
}
|
||||
|
||||
export interface LabelDisplaySettings {
|
||||
/** Show colored folder icons for labeled projects */
|
||||
showColoredIcons: boolean;
|
||||
/** Group projects by label in sidebar */
|
||||
groupByLabel: boolean;
|
||||
}
|
||||
|
||||
const DEFAULT_DISPLAY_SETTINGS: LabelDisplaySettings = {
|
||||
showColoredIcons: false,
|
||||
groupByLabel: false,
|
||||
};
|
||||
|
||||
/** Get the color config for a label color name */
|
||||
export function getLabelColor(colorName: LabelColorName) {
|
||||
return LABEL_COLORS.find(c => c.name === colorName) || LABEL_COLORS[0];
|
||||
}
|
||||
|
||||
/** Generate a unique label ID */
|
||||
function generateLabelId(): string {
|
||||
return `label-${Date.now()}-${Math.random().toString(36).substring(2, 7)}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Hook for managing labels (creating, editing, deleting labels)
|
||||
*/
|
||||
export function useLabels() {
|
||||
const [labels, setLabels] = useLocalStorage<Label[]>('project-labels', []);
|
||||
const [displaySettings, setDisplaySettings] = useLocalStorage<LabelDisplaySettings>(
|
||||
'project-labels-display',
|
||||
DEFAULT_DISPLAY_SETTINGS
|
||||
);
|
||||
|
||||
const createLabel = (name: string, color: LabelColorName): Label => {
|
||||
const maxOrder = labels.length > 0 ? Math.max(...labels.map(l => l.order)) : -1;
|
||||
const newLabel: Label = {
|
||||
id: generateLabelId(),
|
||||
name,
|
||||
color,
|
||||
order: maxOrder + 1,
|
||||
};
|
||||
setLabels([...labels, newLabel]);
|
||||
return newLabel;
|
||||
};
|
||||
|
||||
const updateLabel = (labelId: string, updates: Partial<Omit<Label, 'id'>>) => {
|
||||
setLabels(labels.map(label =>
|
||||
label.id === labelId ? { ...label, ...updates } : label
|
||||
));
|
||||
};
|
||||
|
||||
const deleteLabel = (labelId: string) => {
|
||||
setLabels(labels.filter(label => label.id !== labelId));
|
||||
};
|
||||
|
||||
const reorderLabels = (orderedIds: string[]) => {
|
||||
setLabels(labels.map(label => ({
|
||||
...label,
|
||||
order: orderedIds.indexOf(label.id),
|
||||
})).sort((a, b) => a.order - b.order));
|
||||
};
|
||||
|
||||
const toggleLabelCollapsed = (labelId: string) => {
|
||||
setLabels(labels.map(label =>
|
||||
label.id === labelId ? { ...label, collapsed: !label.collapsed } : label
|
||||
));
|
||||
};
|
||||
|
||||
const updateDisplaySettings = (updates: Partial<LabelDisplaySettings>) => {
|
||||
setDisplaySettings({ ...displaySettings, ...updates });
|
||||
};
|
||||
|
||||
const sortedLabels = [...labels].sort((a, b) => a.order - b.order);
|
||||
|
||||
return {
|
||||
labels: sortedLabels,
|
||||
displaySettings,
|
||||
createLabel,
|
||||
updateLabel,
|
||||
deleteLabel,
|
||||
reorderLabels,
|
||||
toggleLabelCollapsed,
|
||||
updateDisplaySettings,
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
import { useLocalStorage } from '@/hooks/useLocalStorage';
|
||||
|
||||
/** Map of project IDs to their assigned label IDs */
|
||||
type ProjectLabelsMap = Record<string, string[]>;
|
||||
|
||||
/**
|
||||
* Hook for managing project-label associations
|
||||
*/
|
||||
export function useProjectLabels() {
|
||||
const [projectLabels, setProjectLabels] = useLocalStorage<ProjectLabelsMap>('project-label-assignments', {});
|
||||
|
||||
const getProjectLabels = (projectId: string): string[] => {
|
||||
return projectLabels[projectId] || [];
|
||||
};
|
||||
|
||||
const addLabelToProject = (projectId: string, labelId: string) => {
|
||||
const currentLabels = projectLabels[projectId] || [];
|
||||
if (!currentLabels.includes(labelId)) {
|
||||
setProjectLabels({
|
||||
...projectLabels,
|
||||
[projectId]: [...currentLabels, labelId],
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
const removeLabelFromProject = (projectId: string, labelId: string) => {
|
||||
const currentLabels = projectLabels[projectId] || [];
|
||||
const newLabels = currentLabels.filter(id => id !== labelId);
|
||||
if (newLabels.length === 0) {
|
||||
const { [projectId]: _, ...rest } = projectLabels;
|
||||
setProjectLabels(rest);
|
||||
} else {
|
||||
setProjectLabels({
|
||||
...projectLabels,
|
||||
[projectId]: newLabels,
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
const setProjectLabelsList = (projectId: string, labelIds: string[]) => {
|
||||
if (labelIds.length === 0) {
|
||||
const { [projectId]: _, ...rest } = projectLabels;
|
||||
setProjectLabels(rest);
|
||||
} else {
|
||||
setProjectLabels({
|
||||
...projectLabels,
|
||||
[projectId]: labelIds,
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
const getProjectsByLabel = (labelId: string): string[] => {
|
||||
return Object.entries(projectLabels)
|
||||
.filter(([_, labels]) => labels.includes(labelId))
|
||||
.map(([projectId]) => projectId);
|
||||
};
|
||||
|
||||
const hasAnyLabels = (): boolean => {
|
||||
return Object.keys(projectLabels).length > 0;
|
||||
};
|
||||
|
||||
const removeLabel = (labelId: string) => {
|
||||
const newProjectLabels: ProjectLabelsMap = {};
|
||||
for (const [projectId, labels] of Object.entries(projectLabels)) {
|
||||
const filtered = labels.filter(id => id !== labelId);
|
||||
if (filtered.length > 0) {
|
||||
newProjectLabels[projectId] = filtered;
|
||||
}
|
||||
}
|
||||
setProjectLabels(newProjectLabels);
|
||||
};
|
||||
|
||||
return {
|
||||
projectLabels,
|
||||
getProjectLabels,
|
||||
addLabelToProject,
|
||||
removeLabelFromProject,
|
||||
setProjectLabelsList,
|
||||
getProjectsByLabel,
|
||||
hasAnyLabels,
|
||||
removeLabel,
|
||||
};
|
||||
}
|
||||
+20
-1
@@ -524,5 +524,24 @@
|
||||
"templateDeleted": "Template Deleted",
|
||||
"templateDeletedDescription": "Project template '{{name}}' has been deleted.",
|
||||
"noTemplatesConfigured": "No project templates configured yet. Add a template to get started.",
|
||||
"atLeastOneTemplateRequired": "At least one template is required"
|
||||
"atLeastOneTemplateRequired": "At least one template is required",
|
||||
"projectLabels": "Project Labels",
|
||||
"manageLabels": "Manage Labels",
|
||||
"createLabel": "Create Label",
|
||||
"labelName": "Label Name",
|
||||
"enterLabelName": "Enter label name",
|
||||
"labelColor": "Color",
|
||||
"deleteLabel": "Delete Label",
|
||||
"deleteLabelConfirmation": "Are you sure you want to delete the label \"{{name}}\"? This will remove the label from all projects.",
|
||||
"noLabelsYet": "No labels yet",
|
||||
"createLabelToOrganize": "Create a label to organize your projects",
|
||||
"addLabel": "Add label",
|
||||
"selectLabels": "Select labels",
|
||||
"noLabelsCreated": "No labels created yet",
|
||||
"createNewLabel": "Create new label",
|
||||
"showColoredIcons": "Colored folder icons",
|
||||
"showColoredIconsDescription": "Show the folder icon in the label's color for labeled projects.",
|
||||
"groupByLabel": "Group by label",
|
||||
"groupByLabelDescription": "Organize projects into collapsible groups based on their labels.",
|
||||
"unlabeled": "Unlabeled"
|
||||
}
|
||||
+20
-1
@@ -431,5 +431,24 @@
|
||||
"modified": "An Canza",
|
||||
"restoreToDefault": "Mayar da asali",
|
||||
"restoredToDefault": "An Mayar da Asali",
|
||||
"terminal": "Terminal"
|
||||
"terminal": "Terminal",
|
||||
"projectLabels": "Lakabi na Aiki",
|
||||
"manageLabels": "Sarrafa Lakabi",
|
||||
"createLabel": "Ƙirƙiri Lakabi",
|
||||
"labelName": "Sunan Lakabi",
|
||||
"enterLabelName": "Shigar da sunan lakabi",
|
||||
"labelColor": "Launi",
|
||||
"deleteLabel": "Goge Lakabi",
|
||||
"deleteLabelConfirmation": "Ka tabbata kana son goge lakabi \"{{name}}\"? Wannan zai cire lakabi daga duk ayyuka.",
|
||||
"noLabelsYet": "Babu lakabi tukuna",
|
||||
"createLabelToOrganize": "Ƙirƙiri lakabi don tsara ayyukanka",
|
||||
"addLabel": "Ƙara lakabi",
|
||||
"selectLabels": "Zaɓi lakabi",
|
||||
"noLabelsCreated": "Ba a ƙirƙiri lakabi tukuna ba",
|
||||
"createNewLabel": "Ƙirƙiri sabon lakabi",
|
||||
"showColoredIcons": "Alamomin fayil masu launi",
|
||||
"showColoredIconsDescription": "Nuna alamar fayil a launin lakabi don ayyukan da aka yi musu lakabi.",
|
||||
"groupByLabel": "Haɗa da lakabi",
|
||||
"groupByLabelDescription": "Tsara ayyuka cikin ƙungiyoyi masu rufewa dangane da lakabin su.",
|
||||
"unlabeled": "Babu lakabi"
|
||||
}
|
||||
+20
-1
@@ -428,5 +428,24 @@
|
||||
"modified": "Gbanwere",
|
||||
"restoreToDefault": "Weghachi na nke mbụ",
|
||||
"restoredToDefault": "Weghachiri na Nke Mbụ",
|
||||
"terminal": "Terminal"
|
||||
"terminal": "Terminal",
|
||||
"projectLabels": "Akara Ọrụ",
|
||||
"manageLabels": "Jikwaa Akara",
|
||||
"createLabel": "Mepụta Akara",
|
||||
"labelName": "Aha Akara",
|
||||
"enterLabelName": "Tinye aha akara",
|
||||
"labelColor": "Agba",
|
||||
"deleteLabel": "Hichapụ Akara",
|
||||
"deleteLabelConfirmation": "Ị jiri n'ezie chọrọ ihichapụ akara \"{{name}}\"? Nke a ga-ewepụ akara ahụ n'ọrụ niile.",
|
||||
"noLabelsYet": "Enweghị akara ugbu a",
|
||||
"createLabelToOrganize": "Mepụta akara iji hazie ọrụ gị",
|
||||
"addLabel": "Tinye akara",
|
||||
"selectLabels": "Họrọ akara",
|
||||
"noLabelsCreated": "Emepụtaghị akara ọ bụla",
|
||||
"createNewLabel": "Mepụta akara ọhụrụ",
|
||||
"showColoredIcons": "Akara nchekwa nwere agba",
|
||||
"showColoredIconsDescription": "Gosi akara nchekwa n'agba akara maka ọrụ nwere akara.",
|
||||
"groupByLabel": "Kekọta site n'akara",
|
||||
"groupByLabelDescription": "Hazie ọrụ n'ime otu ndị a pụrụ imechi dabere n'akara ha.",
|
||||
"unlabeled": "Enweghị akara"
|
||||
}
|
||||
+20
-1
@@ -440,5 +440,24 @@
|
||||
"modified": "Modificado",
|
||||
"restoreToDefault": "Restaurar para padrão",
|
||||
"restoredToDefault": "Restaurado para Padrão",
|
||||
"terminal": "Terminal"
|
||||
"terminal": "Terminal",
|
||||
"projectLabels": "Etiquetas de Projeto",
|
||||
"manageLabels": "Gerenciar Etiquetas",
|
||||
"createLabel": "Criar Etiqueta",
|
||||
"labelName": "Nome da Etiqueta",
|
||||
"enterLabelName": "Digite o nome da etiqueta",
|
||||
"labelColor": "Cor",
|
||||
"deleteLabel": "Excluir Etiqueta",
|
||||
"deleteLabelConfirmation": "Tem certeza de que deseja excluir a etiqueta \"{{name}}\"? Isso removerá a etiqueta de todos os projetos.",
|
||||
"noLabelsYet": "Nenhuma etiqueta ainda",
|
||||
"createLabelToOrganize": "Crie uma etiqueta para organizar seus projetos",
|
||||
"addLabel": "Adicionar etiqueta",
|
||||
"selectLabels": "Selecionar etiquetas",
|
||||
"noLabelsCreated": "Nenhuma etiqueta criada ainda",
|
||||
"createNewLabel": "Criar nova etiqueta",
|
||||
"showColoredIcons": "Ícones de pasta coloridos",
|
||||
"showColoredIconsDescription": "Mostrar o ícone da pasta na cor da etiqueta para projetos etiquetados.",
|
||||
"groupByLabel": "Agrupar por etiqueta",
|
||||
"groupByLabelDescription": "Organizar projetos em grupos recolhíveis com base em suas etiquetas.",
|
||||
"unlabeled": "Sem etiqueta"
|
||||
}
|
||||
+20
-1
@@ -428,5 +428,24 @@
|
||||
"modified": "Ti Yipada",
|
||||
"restoreToDefault": "Pada si atilẹwa",
|
||||
"restoredToDefault": "Ti Pada si Atilẹwa",
|
||||
"terminal": "Terminal"
|
||||
"terminal": "Terminal",
|
||||
"projectLabels": "Àmì Ìṣẹ́",
|
||||
"manageLabels": "Ṣàkóso Àmì",
|
||||
"createLabel": "Ṣẹ̀dá Àmì",
|
||||
"labelName": "Orúkọ Àmì",
|
||||
"enterLabelName": "Tẹ orúkọ àmì",
|
||||
"labelColor": "Àwọ̀",
|
||||
"deleteLabel": "Pa Àmì rẹ́",
|
||||
"deleteLabelConfirmation": "Ṣé o dá a lójú pé o fẹ́ pa àmì \"{{name}}\" rẹ́? Èyí yóò yọ àmì náà kúrò nínú gbogbo iṣẹ́.",
|
||||
"noLabelsYet": "Kò sí àmì síbẹ̀",
|
||||
"createLabelToOrganize": "Ṣẹ̀dá àmì láti ṣètò àwọn iṣẹ́ rẹ",
|
||||
"addLabel": "Fi àmì kún",
|
||||
"selectLabels": "Yan àmì",
|
||||
"noLabelsCreated": "A kò tí ì ṣẹ̀dá àmì kankan",
|
||||
"createNewLabel": "Ṣẹ̀dá àmì tuntun",
|
||||
"showColoredIcons": "Àwọn ìkọ́ fáìlì oníàwọ̀",
|
||||
"showColoredIconsDescription": "Fi ìkọ́ fáìlì hàn ní àwọ̀ àmì fún àwọn iṣẹ́ tí wọ́n ní àmì.",
|
||||
"groupByLabel": "Ṣàkójọ nípa àmì",
|
||||
"groupByLabelDescription": "Ṣètò àwọn iṣẹ́ sí ẹgbẹ́ tí wọ́n lè pa mọ́ dà lórí àmì wọn.",
|
||||
"unlabeled": "Kò ní àmì"
|
||||
}
|
||||
+20
-1
@@ -440,5 +440,24 @@
|
||||
"modified": "已修改",
|
||||
"restoreToDefault": "恢复默认值",
|
||||
"restoredToDefault": "已恢复默认值",
|
||||
"terminal": "终端"
|
||||
"terminal": "终端",
|
||||
"projectLabels": "项目标签",
|
||||
"manageLabels": "管理标签",
|
||||
"createLabel": "创建标签",
|
||||
"labelName": "标签名称",
|
||||
"enterLabelName": "输入标签名称",
|
||||
"labelColor": "颜色",
|
||||
"deleteLabel": "删除标签",
|
||||
"deleteLabelConfirmation": "确定要删除标签 \"{{name}}\" 吗?这将从所有项目中移除该标签。",
|
||||
"noLabelsYet": "暂无标签",
|
||||
"createLabelToOrganize": "创建标签来组织您的项目",
|
||||
"addLabel": "添加标签",
|
||||
"selectLabels": "选择标签",
|
||||
"noLabelsCreated": "尚未创建标签",
|
||||
"createNewLabel": "创建新标签",
|
||||
"showColoredIcons": "彩色文件夹图标",
|
||||
"showColoredIconsDescription": "为有标签的项目显示标签颜色的文件夹图标。",
|
||||
"groupByLabel": "按标签分组",
|
||||
"groupByLabelDescription": "根据标签将项目组织成可折叠的分组。",
|
||||
"unlabeled": "无标签"
|
||||
}
|
||||
@@ -1,7 +1,8 @@
|
||||
import { Settings2, ArrowLeft } from "lucide-react";
|
||||
import { useState } from "react";
|
||||
import { Settings2, ArrowLeft, Tag } from "lucide-react";
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Card, CardContent } from "@/components/ui/card";
|
||||
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
|
||||
import { ThemePicker } from "@/components/ThemePicker";
|
||||
import { LanguagePicker } from "@/components/LanguagePicker";
|
||||
import { Switch } from "@/components/ui/switch";
|
||||
@@ -9,12 +10,21 @@ import { Label } from "@/components/ui/label";
|
||||
import { useIsMobile } from "@/hooks/useIsMobile";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
import { useAppContext } from "@/hooks/useAppContext";
|
||||
import { useLabels } from "@/hooks/useLabels";
|
||||
import { useProjectLabels } from "@/hooks/useProjectLabels";
|
||||
import { LabelsManageDialog } from "@/components/labels/LabelsManageDialog";
|
||||
|
||||
export function Preferences() {
|
||||
const { t } = useTranslation();
|
||||
const isMobile = useIsMobile();
|
||||
const navigate = useNavigate();
|
||||
const { config, updateConfig } = useAppContext();
|
||||
const { labels, displaySettings, updateDisplaySettings } = useLabels();
|
||||
const { hasAnyLabels } = useProjectLabels();
|
||||
const [labelsDialogOpen, setLabelsDialogOpen] = useState(false);
|
||||
|
||||
// Only show label settings if user has created labels or assigned labels to projects
|
||||
const showLabelSettings = labels.length > 0 || hasAnyLabels();
|
||||
|
||||
return (
|
||||
<div className="p-6 space-y-6">
|
||||
@@ -101,6 +111,76 @@ export function Preferences() {
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
{/* Labels Settings - Only shown when user has labels */}
|
||||
{showLabelSettings && (
|
||||
<Card className="max-w-md">
|
||||
<CardHeader className="pb-4">
|
||||
<CardTitle className="flex items-center gap-2 text-lg">
|
||||
<Tag className="h-5 w-5 text-primary" />
|
||||
{t('projectLabels')}
|
||||
</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<div className="space-y-6">
|
||||
<div className="space-y-2">
|
||||
<div className="flex items-center justify-between">
|
||||
<div className="space-y-0.5">
|
||||
<Label htmlFor="colored-icons" className="text-sm font-medium">
|
||||
{t('showColoredIcons')}
|
||||
</Label>
|
||||
</div>
|
||||
<Switch
|
||||
id="colored-icons"
|
||||
checked={displaySettings.showColoredIcons}
|
||||
onCheckedChange={(checked) => {
|
||||
updateDisplaySettings({ showColoredIcons: checked });
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
<p className="text-sm text-muted-foreground">
|
||||
{t('showColoredIconsDescription')}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div className="space-y-2">
|
||||
<div className="flex items-center justify-between">
|
||||
<div className="space-y-0.5">
|
||||
<Label htmlFor="group-by-label" className="text-sm font-medium">
|
||||
{t('groupByLabel')}
|
||||
</Label>
|
||||
</div>
|
||||
<Switch
|
||||
id="group-by-label"
|
||||
checked={displaySettings.groupByLabel}
|
||||
onCheckedChange={(checked) => {
|
||||
updateDisplaySettings({ groupByLabel: checked });
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
<p className="text-sm text-muted-foreground">
|
||||
{t('groupByLabelDescription')}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div className="pt-2">
|
||||
<Button
|
||||
variant="outline"
|
||||
className="w-full"
|
||||
onClick={() => setLabelsDialogOpen(true)}
|
||||
>
|
||||
{t('manageLabels')}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
)}
|
||||
|
||||
<LabelsManageDialog
|
||||
open={labelsDialogOpen}
|
||||
onOpenChange={setLabelsDialogOpen}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user