forked from BasedHardware/omi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTaskGroup.tsx
More file actions
137 lines (126 loc) · 3.96 KB
/
Copy pathTaskGroup.tsx
File metadata and controls
137 lines (126 loc) · 3.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
'use client';
import { useState } from 'react';
import { ChevronDown, ChevronRight } from 'lucide-react';
import { cn } from '@/lib/utils';
import { TaskCard, TaskCardSkeleton } from './TaskCard';
import type { ActionItem } from '@/types/conversation';
interface TaskGroupProps {
title: string;
icon: string;
tasks: ActionItem[];
collapsible?: boolean;
defaultCollapsed?: boolean;
maxVisible?: number;
onToggleComplete: (id: string, completed: boolean) => void;
onSnooze: (id: string, days: number) => void;
onDelete: (id: string) => void;
onUpdateDescription?: (id: string, description: string) => void;
onSetDueDate?: (id: string, date: Date | null) => void;
selectedIds?: Set<string>;
onSelect?: (id: string, selected: boolean) => void;
// Double-click to enter selection mode
onEnterSelectionMode?: (id: string) => void;
}
export function TaskGroup({
title,
icon,
tasks,
collapsible = false,
defaultCollapsed = false,
maxVisible,
onToggleComplete,
onSnooze,
onDelete,
onUpdateDescription,
onSetDueDate,
selectedIds,
onSelect,
onEnterSelectionMode,
}: TaskGroupProps) {
const [isCollapsed, setIsCollapsed] = useState(defaultCollapsed);
const [showAll, setShowAll] = useState(false);
if (tasks.length === 0) return null;
const visibleTasks = maxVisible && !showAll ? tasks.slice(0, maxVisible) : tasks;
const hasMore = maxVisible && tasks.length > maxVisible && !showAll;
return (
<section className="space-y-2">
{/* Header */}
<button
onClick={() => collapsible && setIsCollapsed(!isCollapsed)}
disabled={!collapsible}
className={cn(
'flex items-center gap-2 w-full',
'text-left',
collapsible && 'cursor-pointer hover:opacity-80',
)}
>
{collapsible && (
<span className="text-text-quaternary">
{isCollapsed ? (
<ChevronRight className="w-4 h-4" />
) : (
<ChevronDown className="w-4 h-4" />
)}
</span>
)}
<span className="text-base">{icon}</span>
<h3 className="text-sm font-medium text-text-secondary">{title}</h3>
<span className="text-xs text-text-quaternary">({tasks.length})</span>
</button>
{/* Tasks */}
{!isCollapsed && (
<div className="space-y-1.5">
{visibleTasks.map((task) => (
<TaskCard
key={task.id}
task={task}
onToggleComplete={onToggleComplete}
onSnooze={onSnooze}
onDelete={onDelete}
onUpdateDescription={onUpdateDescription}
onSetDueDate={onSetDueDate}
isSelected={selectedIds?.has(task.id)}
onSelect={onSelect}
onEnterSelectionMode={onEnterSelectionMode}
/>
))}
{/* Show more button */}
{hasMore && (
<button
onClick={() => setShowAll(true)}
className={cn(
'w-full py-2 text-sm text-text-tertiary',
'hover:text-white transition-colors',
'text-center',
)}
>
Show {tasks.length - maxVisible} more
</button>
)}
</div>
)}
</section>
);
}
// Skeleton loader
interface TaskGroupSkeletonProps {
count?: number;
}
export function TaskGroupSkeleton({ count = 3 }: TaskGroupSkeletonProps) {
return (
<div className="space-y-2">
{/* Header skeleton */}
<div className="flex items-center gap-2">
<div className="w-4 h-4 bg-bg-quaternary rounded animate-pulse" />
<div className="h-4 w-24 bg-bg-quaternary rounded animate-pulse" />
<div className="h-3 w-6 bg-bg-quaternary rounded animate-pulse" />
</div>
{/* Card skeletons */}
<div className="space-y-1.5">
{Array.from({ length: count }).map((_, i) => (
<TaskCardSkeleton key={i} />
))}
</div>
</div>
);
}