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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
|
import React from 'react';
import {
View,
Text,
StyleSheet,
ScrollView,
TouchableOpacity,
useColorScheme,
RefreshControl,
} from 'react-native';
import { useRouter } from 'expo-router';
import { Ionicons } from '@expo/vector-icons';
import { Colors, TaskStatusColors } from '../../constants/Colors';
import { useTasks, getTaskCounts } from '../../hooks/useTasks';
import { usePendingQuestions } from '../../hooks/useQuestions';
import { TaskStatusBadge } from '../../components/TaskStatusBadge';
import type { TaskSummary } from '../../lib/api';
interface StatCardProps {
title: string;
value: number;
icon: keyof typeof Ionicons.glyphMap;
color: string;
onPress?: () => void;
}
function StatCard({ title, value, icon, color, onPress }: StatCardProps) {
const colorScheme = useColorScheme() ?? 'light';
const colors = Colors[colorScheme];
return (
<TouchableOpacity
style={[styles.statCard, { backgroundColor: colors.card }]}
onPress={onPress}
activeOpacity={onPress ? 0.7 : 1}
disabled={!onPress}
>
<View style={[styles.iconContainer, { backgroundColor: color + '20' }]}>
<Ionicons name={icon} size={24} color={color} />
</View>
<Text style={[styles.statValue, { color: colors.text }]}>{value}</Text>
<Text style={[styles.statTitle, { color: colors.secondaryText }]}>
{title}
</Text>
</TouchableOpacity>
);
}
interface QuickTaskItemProps {
task: TaskSummary;
onPress: () => void;
}
function QuickTaskItem({ task, onPress }: QuickTaskItemProps) {
const colorScheme = useColorScheme() ?? 'light';
const colors = Colors[colorScheme];
return (
<TouchableOpacity
style={[styles.quickTaskItem, { backgroundColor: colors.card }]}
onPress={onPress}
activeOpacity={0.7}
>
<TaskStatusBadge status={task.status} size="small" />
<View style={styles.quickTaskContent}>
<Text
style={[styles.quickTaskName, { color: colors.text }]}
numberOfLines={1}
>
{task.name}
</Text>
{task.progressSummary && (
<Text
style={[styles.quickTaskSummary, { color: colors.secondaryText }]}
numberOfLines={1}
>
{task.progressSummary}
</Text>
)}
</View>
<Ionicons name="chevron-forward" size={16} color={colors.secondaryText} />
</TouchableOpacity>
);
}
export default function DashboardScreen() {
const colorScheme = useColorScheme() ?? 'light';
const colors = Colors[colorScheme];
const router = useRouter();
const {
data: tasks,
isLoading: isLoadingTasks,
refetch: refetchTasks,
isRefetching: isRefetchingTasks,
} = useTasks();
const {
data: questions,
isLoading: isLoadingQuestions,
refetch: refetchQuestions,
isRefetching: isRefetchingQuestions,
} = usePendingQuestions();
const isRefreshing = isRefetchingTasks || isRefetchingQuestions;
const handleRefresh = () => {
refetchTasks();
refetchQuestions();
};
// Calculate counts
const counts = tasks ? getTaskCounts(tasks) : null;
const questionCount = questions?.length ?? 0;
// Get running tasks for quick access
const runningTasks = tasks?.filter((t) =>
['running', 'initializing', 'starting'].includes(t.status)
) ?? [];
// Get tasks needing attention (blocked, paused, or with questions)
const attentionTasks = tasks?.filter((t) =>
['blocked', 'paused'].includes(t.status)
) ?? [];
return (
<ScrollView
style={[styles.container, { backgroundColor: colors.background }]}
contentContainerStyle={styles.content}
refreshControl={
<RefreshControl
refreshing={isRefreshing}
onRefresh={handleRefresh}
tintColor={colors.tint}
/>
}
>
{/* Stats Grid */}
<View style={styles.statsGrid}>
<StatCard
title="Running"
value={counts?.running ?? 0}
icon="play-circle"
color={TaskStatusColors.running.dot}
onPress={() => router.push('/(tabs)/tasks')}
/>
<StatCard
title="Questions"
value={questionCount}
icon="help-circle"
color="#f59e0b"
onPress={questionCount > 0 ? () => router.push('/(tabs)/tasks') : undefined}
/>
<StatCard
title="Completed"
value={counts?.completed ?? 0}
icon="checkmark-circle"
color={TaskStatusColors.done.dot}
onPress={() => router.push('/(tabs)/tasks')}
/>
<StatCard
title="Failed"
value={counts?.failed ?? 0}
icon="alert-circle"
color={TaskStatusColors.failed.dot}
onPress={counts?.failed ? () => router.push('/(tabs)/tasks') : undefined}
/>
</View>
{/* Pending Questions Alert */}
{questionCount > 0 && (
<TouchableOpacity
style={[styles.alertBanner, { backgroundColor: '#fef3c7' }]}
onPress={() => router.push('/(tabs)/tasks')}
activeOpacity={0.7}
>
<Ionicons name="help-circle" size={24} color="#92400e" />
<View style={styles.alertContent}>
<Text style={[styles.alertTitle, { color: '#92400e' }]}>
{questionCount} Question{questionCount !== 1 ? 's' : ''} Waiting
</Text>
<Text style={[styles.alertSubtitle, { color: '#b45309' }]}>
Tap to review and respond
</Text>
</View>
<Ionicons name="chevron-forward" size={20} color="#92400e" />
</TouchableOpacity>
)}
{/* Running Tasks */}
{runningTasks.length > 0 && (
<View style={styles.section}>
<View style={styles.sectionHeader}>
<Text style={[styles.sectionTitle, { color: colors.text }]}>
Running Tasks
</Text>
<TouchableOpacity onPress={() => router.push('/(tabs)/tasks')}>
<Text style={[styles.seeAllButton, { color: colors.tint }]}>
See All
</Text>
</TouchableOpacity>
</View>
<View style={styles.taskList}>
{runningTasks.slice(0, 3).map((task) => (
<QuickTaskItem
key={task.id}
task={task}
onPress={() => router.push(`/task/${task.id}`)}
/>
))}
</View>
</View>
)}
{/* Needs Attention */}
{attentionTasks.length > 0 && (
<View style={styles.section}>
<View style={styles.sectionHeader}>
<Text style={[styles.sectionTitle, { color: colors.text }]}>
Needs Attention
</Text>
<TouchableOpacity onPress={() => router.push('/(tabs)/tasks')}>
<Text style={[styles.seeAllButton, { color: colors.tint }]}>
See All
</Text>
</TouchableOpacity>
</View>
<View style={styles.taskList}>
{attentionTasks.slice(0, 3).map((task) => (
<QuickTaskItem
key={task.id}
task={task}
onPress={() => router.push(`/task/${task.id}`)}
/>
))}
</View>
</View>
)}
{/* Empty State */}
{!isLoadingTasks && (!tasks || tasks.length === 0) && (
<View style={styles.emptyState}>
<Ionicons
name="cube-outline"
size={64}
color={colors.secondaryText}
/>
<Text style={[styles.emptyTitle, { color: colors.text }]}>
No tasks yet
</Text>
<Text style={[styles.emptyMessage, { color: colors.secondaryText }]}>
Tasks created from contracts will appear here
</Text>
</View>
)}
</ScrollView>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
},
content: {
padding: 16,
gap: 20,
},
statsGrid: {
flexDirection: 'row',
flexWrap: 'wrap',
gap: 12,
},
statCard: {
flex: 1,
minWidth: '45%',
padding: 16,
borderRadius: 12,
alignItems: 'center',
gap: 8,
},
iconContainer: {
width: 48,
height: 48,
borderRadius: 24,
alignItems: 'center',
justifyContent: 'center',
},
statValue: {
fontSize: 28,
fontWeight: '700',
},
statTitle: {
fontSize: 14,
fontWeight: '500',
},
alertBanner: {
flexDirection: 'row',
alignItems: 'center',
padding: 16,
borderRadius: 12,
gap: 12,
},
alertContent: {
flex: 1,
},
alertTitle: {
fontSize: 16,
fontWeight: '600',
},
alertSubtitle: {
fontSize: 13,
marginTop: 2,
},
section: {
gap: 12,
},
sectionHeader: {
flexDirection: 'row',
justifyContent: 'space-between',
alignItems: 'center',
},
sectionTitle: {
fontSize: 18,
fontWeight: '600',
},
seeAllButton: {
fontSize: 14,
fontWeight: '500',
},
taskList: {
gap: 8,
},
quickTaskItem: {
flexDirection: 'row',
alignItems: 'center',
padding: 12,
borderRadius: 10,
gap: 12,
},
quickTaskContent: {
flex: 1,
gap: 2,
},
quickTaskName: {
fontSize: 15,
fontWeight: '500',
},
quickTaskSummary: {
fontSize: 13,
},
emptyState: {
alignItems: 'center',
justifyContent: 'center',
paddingVertical: 48,
gap: 12,
},
emptyTitle: {
fontSize: 18,
fontWeight: '600',
},
emptyMessage: {
fontSize: 14,
textAlign: 'center',
},
});
|