mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-06 00:27:24 +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
@@ -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,
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user