Skip to content

Commit 29c50fb

Browse files
committed
fixed insert tags hidden error
1 parent 4b1eb09 commit 29c50fb

File tree

4 files changed

+22
-15
lines changed

4 files changed

+22
-15
lines changed

lib/app/v3/db/task_database.dart

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -115,35 +115,34 @@ class TaskDatabase {
115115

116116
Future<void> insertTask(TaskForC task) async {
117117
await ensureDatabaseIsOpen();
118-
debugPrint("Database Insert");
119-
List<String> taskTags = task.tags?.map((e) => e.toString()).toList() ?? [];
120-
debugPrint("Database Insert $taskTags");
121-
List<String> taskDepends =
122-
task.tags?.map((e) => e.toString()).toList() ?? [];
123-
debugPrint("Database Insert $taskDepends");
118+
List<String> taskTags = task.tags ?? [];
119+
List<String> taskDepends = task.depends ?? [];
124120
List<Map<String, String?>> taskAnnotations = task.annotations != null
125121
? task.annotations!
126122
.map((a) => {"entry": a.entry, "description": a.description})
127123
.toList()
128124
: [];
125+
debugPrint(
126+
"Database insert ${task.description} for task tags are $taskTags");
129127
var map = task.toJson();
130128
map.remove("tags");
131129
map.remove("depends");
132130
map.remove("annotations");
133-
var dbi = await _database!.insert(
131+
await _database!.insert(
134132
'Tasks',
135133
map,
136134
conflictAlgorithm: ConflictAlgorithm.replace,
137135
);
138136
if (taskTags.isNotEmpty) {
139-
await setTagsForTask(task.uuid ?? '', dbi, taskTags.toList());
137+
// Use the ID from the task object itself for consistency
138+
await setTagsForTask(task.uuid ?? '', task.id, taskTags.toList());
140139
}
141140
if (taskDepends.isNotEmpty) {
142-
await setDependsForTask(task.uuid ?? '', dbi, taskDepends.toList());
141+
await setDependsForTask(task.uuid ?? '', task.id, taskDepends.toList());
143142
}
144143
if (taskAnnotations.isNotEmpty) {
145144
await setAnnotationsForTask(
146-
task.uuid ?? '', dbi, taskAnnotations.toList());
145+
task.uuid ?? '', task.id, taskAnnotations.toList());
147146
}
148147
}
149148

lib/app/v3/db/update.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import 'package:taskwarrior/app/v3/net/modify.dart';
88
import 'package:timezone/timezone.dart';
99

1010
Future<void> updateTasksInDatabase(List<TaskForC> tasks) async {
11+
debugPrint(
12+
"Updating tasks in database... Total tasks from server: ${tasks.length}");
1113
var taskDatabase = TaskDatabase();
1214
await taskDatabase.open();
1315
// find tasks without UUID
@@ -49,6 +51,8 @@ Future<void> updateTasksInDatabase(List<TaskForC> tasks) async {
4951

5052
if (localTask == null) {
5153
// Task doesn't exist in the local database, insert it
54+
debugPrint(
55+
'Inserting new task from server: ${serverTask.description}, modified: ${serverTask.modified}');
5256
await taskDatabase.insertTask(serverTask);
5357
} else {
5458
var serverTaskModifiedDate = DateTime.parse(serverTask.modified!);

lib/app/v3/models/task.dart

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class TaskForC {
1313
final String? end;
1414
final String entry;
1515
final String? modified;
16-
final List<dynamic>? tags;
16+
final List<String>? tags;
1717
// newer feilds in CCSync Model
1818
final String? start;
1919
final String? wait;
@@ -57,12 +57,13 @@ class TaskForC {
5757
end: json['end'],
5858
entry: json['entry'],
5959
modified: json['modified'],
60-
tags: json['tags'],
60+
tags: json['tags']?.map<String>((tag) => tag.toString()).toList() ?? [],
6161
start: json['start'],
6262
wait: json['wait'],
6363
rtype: json['rtype'],
6464
recur: json['recur'],
65-
depends: json['depends'],
65+
depends:
66+
json['depends']?.map<String>((d) => d.toString()).toList() ?? [],
6667
annotations: <Annotation>[]);
6768
}
6869

lib/app/v3/net/fetch.dart

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,18 @@ Future<List<TaskForC>> fetchTasks(String uuid, String encryptionSecret) async {
1515
var response = await http.get(Uri.parse(url), headers: {
1616
"Content-Type": "application/json",
1717
}).timeout(const Duration(seconds: 10000));
18+
debugPrint("Fetch tasks response: ${response.statusCode}");
19+
debugPrint("Fetch tasks body: ${response.body}");
1820
if (response.statusCode == 200) {
1921
List<dynamic> allTasks = jsonDecode(response.body);
2022
debugPrint(allTasks.toString());
2123
return allTasks.map((task) => TaskForC.fromJson(task)).toList();
2224
} else {
2325
throw Exception('Failed to load tasks');
2426
}
25-
} catch (e) {
26-
debugPrint('Error fetching tasks: $e');
27+
} catch (e, s) {
28+
debugPrint('Error fetching tasks: $e\n $s');
29+
2730
return [];
2831
}
2932
}

0 commit comments

Comments
 (0)