Skip to content

Commit a759ad7

Browse files
authored
Merge branch 'main' into create-task
2 parents f6c381d + 7b91943 commit a759ad7

9 files changed

Lines changed: 442 additions & 383 deletions

File tree

src/lib/features/chatbot/services/chatbot_services.dart

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,21 @@ class ChatBotAssistantService {
4141
description:
4242
'Danh sách các thẻ phân loại (ví dụ: ["Học tập", "Gấp", "Backend"]). Gửi mảng rỗng [] nếu không có.',
4343
),
44+
'start_time': Schema(
45+
SchemaType.string,
46+
description:
47+
'Thời gian bắt đầu công việc theo định dạng ISO 8601 (VD: 2026-04-18T15:00:00Z). Nếu người dùng không nói, hãy bỏ qua hoặc để rỗng.',
48+
),
49+
'due_time': Schema(
50+
SchemaType.string,
51+
description:
52+
'Thời gian kết thúc (deadline) theo định dạng ISO 8601. Nếu không có, bỏ qua.',
53+
),
54+
'category_name': Schema(
55+
SchemaType.string,
56+
description:
57+
'Phân loại công việc vào 1 trong 4 nhóm: "Cá nhân", "Học tập", "Công việc", hoặc "Giải trí". Nếu không phân loại được, mặc định trả về "Cá nhân".',
58+
),
4459
},
4560
requiredProperties: ['title', 'priority', 'tags'],
4661
),
@@ -77,26 +92,38 @@ class ChatBotAssistantService {
7792
final priority = (args['priority'] as num?)?.toInt() ?? 1;
7893
final rawTags = args['tags'] as List<dynamic>? ?? [];
7994
final tags = rawTags.map((e) => e.toString()).toList();
95+
final startTime = args['start_time'] as String?;
96+
final dueTime = args['due_time'] as String?;
8097

8198
final userId = Supabase.instance.client.auth.currentUser?.id;
8299
if (userId == null) {
83100
return 'Vui lòng đăng nhập để tạo công việc.';
84101
}
85-
102+
final categoryName = args['category_name'] as String? ?? 'Cá nhân';
86103
final dbResponse = await Supabase.instance.client.rpc(
87104
'create_task_full',
88105
params: {
89-
'p_title': title,
90-
'p_priority': priority,
106+
'p_title': args['title'],
107+
'p_priority': (args['priority'] as num?)?.toInt() ?? 1,
91108
'p_profile_id': userId,
92-
'p_tag_names': tags,
109+
'p_tag_names':
110+
(args['tags'] as List?)?.map((e) => e.toString()).toList() ??
111+
[],
112+
'p_category_name': categoryName,
113+
'p_start_time': args['start_time'],
114+
'p_due_time': args['due_time'],
93115
},
94116
);
95117

96118
final isSuccess = dbResponse['success'] == true;
119+
if (!isSuccess) {
120+
debugPrint("Lỗi từ Supabase: ${dbResponse['error']}");
121+
}
97122
final functionResponse = await _chatSession!.sendMessage(
98123
Content.functionResponse('create_task_full', {
99124
'status': isSuccess ? 'Thành công' : 'Thất bại',
125+
126+
'reason': isSuccess ? '' : dbResponse['error'].toString(),
100127
}),
101128
);
102129
return functionResponse.text ?? 'Đã xử lý xong yêu cầu của bạn!';

src/lib/features/tasks/model/task_model.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,4 +90,4 @@ class NoteModel {
9090
pinned: json['pinned'] ?? false,
9191
);
9292
}
93-
}
93+
}

src/lib/features/tasks/view/screens/create_task_screen.dart

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ class _CreateTaskScreenState extends State<CreateTaskScreen> {
212212
),
213213
boxShadow: [
214214
BoxShadow(
215-
color: Colors.black.withOpacity(0.05),
215+
color: Colors.black.withValues(alpha: 0.05),
216216
blurRadius: 10,
217217
offset: const Offset(0, 5),
218218
),
@@ -225,23 +225,23 @@ class _CreateTaskScreenState extends State<CreateTaskScreen> {
225225
IconButton(
226226
icon: Icon(
227227
Icons.arrow_back_ios_new_rounded,
228-
color: theme.colorScheme.onSurface,
228+
color: Theme.of(context).colorScheme.onSurface,
229229
),
230230
onPressed: () => Navigator.pop(context),
231231
),
232232
Icon(
233233
Icons.menu_rounded,
234-
color: theme.colorScheme.onSurface,
234+
color: Theme.of(context).colorScheme.onSurface,
235235
),
236236
Icon(
237237
Icons.assignment_outlined,
238-
color: theme.colorScheme.onSurface,
238+
color: Theme.of(context).colorScheme.onSurface,
239239
),
240240
],
241241
),
242242
),
243243

244-
// --- Body ---
244+
// ─── Body ─────────────────────────────────────────
245245
Expanded(
246246
child: SingleChildScrollView(
247247
padding: const EdgeInsets.all(25.0),
@@ -250,22 +250,23 @@ class _CreateTaskScreenState extends State<CreateTaskScreen> {
250250
children: [
251251
Text(
252252
'Create New Task',
253-
style: theme.textTheme.headlineMedium?.copyWith(
254-
fontWeight: FontWeight.bold,
255-
),
253+
style: Theme.of(context).textTheme.headlineMedium,
256254
),
257255
const SizedBox(height: 25),
258256

259-
// --- Input Name ---
257+
// Task Name
260258
CustomInputField(
261259
label: 'Task Name',
262260
hint: 'Enter task name',
263261
controller: _nameController,
264262
),
265263
const SizedBox(height: 20),
266264

267-
// --- Category ---
268-
Text('Select Category', style: theme.textTheme.labelLarge),
265+
// Category
266+
Text(
267+
'Select Category',
268+
style: Theme.of(context).textTheme.labelLarge,
269+
),
269270
const SizedBox(height: 10),
270271
SizedBox(
271272
child: categories.isEmpty
@@ -488,6 +489,15 @@ class _CreateTaskScreenState extends State<CreateTaskScreen> {
488489
controller: _descController,
489490
maxLines: 2,
490491
),
492+
const SizedBox(height: 25),
493+
494+
// Description
495+
CustomInputField(
496+
label: 'Description',
497+
hint: 'Enter task description',
498+
controller: _descController,
499+
maxLines: 2,
500+
),
491501
const SizedBox(height: 40),
492502

493503
// ─── Create Button ────────────────────────
@@ -535,4 +545,4 @@ class _CreateTaskScreenState extends State<CreateTaskScreen> {
535545
),
536546
);
537547
}
538-
}
548+
}

0 commit comments

Comments
 (0)