diff --git a/src/components/ProjectDetailsDialog.tsx b/src/components/ProjectDetailsDialog.tsx
index 6ce4a5fe..106f35f1 100644
--- a/src/components/ProjectDetailsDialog.tsx
+++ b/src/components/ProjectDetailsDialog.tsx
@@ -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
)}
+ {/* Labels */}
+
diff --git a/src/components/ProjectSidebar.tsx b/src/components/ProjectSidebar.tsx
index f2cd9c7d..ff68dca7 100644
--- a/src/components/ProjectSidebar.tsx
+++ b/src/components/ProjectSidebar.tsx
@@ -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
= ({ project, isSelected, onSelect, isFavorite }) => {
+const ProjectItem: React.FC = ({
+ project,
+ isSelected,
+ onSelect,
+ isFavorite,
+ labelColor,
+ showColoredIcon = false,
+}) => {
const navigate = useNavigate();
const { hasRunningSessions } = useProjectSessionStatus(project.id);
@@ -31,6 +43,15 @@ const ProjectItem: React.FC = ({ project, isSelected, onSelect
navigate(`/project/${project.id}`);
};
+ // Determine folder icon color
+ const getFolderColorClass = () => {
+ if (showColoredIcon && labelColor) {
+ const colorConfig = getLabelColor(labelColor as Parameters[0]);
+ return colorConfig.text;
+ }
+ return 'text-primary';
+ };
+
return (
= ({ project, isSelected, onSelect
{hasRunningSessions ? (
) : (
-
+
)}
@@ -75,6 +96,41 @@ const ProjectItem: React.FC
= ({ 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 = ({
+ labelName,
+ labelColor,
+ isCollapsed,
+ onToggle,
+ projectCount,
+}) => {
+ const colorConfig = getLabelColor(labelColor as Parameters[0]);
+
+ return (
+
+ );
+};
+
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('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 = 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({
{t('noProjectsFound')}
{t('tryDifferentSearch')}
+ ) : showGroupedView && groupedProjects ? (
+ // Grouped view by labels
+
+ {/* Render each label group */}
+ {labels.map((label) => {
+ const groupProjects = groupedProjects.groups.get(label.id) || [];
+ if (groupProjects.length === 0) return null;
+
+ return (
+
toggleLabelCollapsed(label.id)}
+ >
+
+
+ toggleLabelCollapsed(label.id)}
+ projectCount={groupProjects.length}
+ />
+
+
+
+
+ {groupProjects.map((project) => (
+
+ ))}
+
+
+
+ );
+ })}
+
+ {/* Unlabeled projects */}
+ {groupedProjects.unlabeled.length > 0 && (
+
+ {labels.some(l => (groupedProjects.groups.get(l.id)?.length || 0) > 0) && (
+
+ {t('unlabeled')}
+
+ )}
+ {groupedProjects.unlabeled.map((project) => (
+
+ ))}
+
+ )}
+
) : (
+ // Flat view (default)
{filteredProjects.map((project) => (
))}
diff --git a/src/components/labels/LabelSelector.tsx b/src/components/labels/LabelSelector.tsx
new file mode 100644
index 00000000..cec82beb
--- /dev/null
+++ b/src/components/labels/LabelSelector.tsx
@@ -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 (
+
+ {projectLabels.map((label) => {
+ const colorConfig = getLabelColor(label.color);
+ return (
+
+ {label.name}
+
+ );
+ })}
+
+ );
+ }
+
+ return (
+ <>
+
+
+
+
+
+
+
+ {t('selectLabels')}
+
+
+
+ {labels.length > 0 ? (
+
+
+ {labels.map((label) => {
+ const colorConfig = getLabelColor(label.color);
+ const isSelected = projectLabelIds.includes(label.id);
+ return (
+
+ );
+ })}
+
+
+ ) : (
+
+ {t('noLabelsCreated')}
+
+ )}
+
+
+
+
+
+
+
+
+
+
+ >
+ );
+}
diff --git a/src/components/labels/LabelsManageDialog.tsx b/src/components/labels/LabelsManageDialog.tsx
new file mode 100644
index 00000000..db5e08dd
--- /dev/null
+++ b/src/components/labels/LabelsManageDialog.tsx
@@ -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 (
+
+
+
+
{label.name}
+
+ {projectCount} {projectCount === 1 ? 'project' : 'projects'}
+
+
+
+
+ );
+}
+
+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(initialColor);
+
+ const handleSubmit = (e: React.FormEvent) => {
+ e.preventDefault();
+ if (name.trim()) {
+ onSave(name.trim(), color);
+ }
+ };
+
+ return (
+
+ );
+}
+
+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(null);
+ const [deletingLabel, setDeletingLabel] = useState(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 (
+ <>
+
+
+ {/* Delete confirmation dialog */}
+ setDeletingLabel(null)}>
+
+
+ {t('deleteLabel')}
+
+ {t('deleteLabelConfirmation', { name: deletingLabel?.name })}
+
+
+
+ {t('cancel')}
+
+ {t('delete')}
+
+
+
+
+ >
+ );
+}
diff --git a/src/components/labels/index.ts b/src/components/labels/index.ts
new file mode 100644
index 00000000..ce8a2a70
--- /dev/null
+++ b/src/components/labels/index.ts
@@ -0,0 +1,2 @@
+export { LabelsManageDialog } from './LabelsManageDialog';
+export { LabelSelector } from './LabelSelector';
diff --git a/src/hooks/useLabels.ts b/src/hooks/useLabels.ts
new file mode 100644
index 00000000..ff9787f7
--- /dev/null
+++ b/src/hooks/useLabels.ts
@@ -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
);
}