mirror of
https://github.com/GopeedLab/gopeed.git
synced 2026-11-09 01:50:30 +00:00
fix: sort of completed tasks (#297)
This commit is contained in:
7 files changed
+25
-19
No files matched your search
@@ -13,6 +13,7 @@ class Task {
|
||||
Status status;
|
||||
Progress progress;
|
||||
DateTime createdAt;
|
||||
DateTime updatedAt;
|
||||
|
||||
Task({
|
||||
required this.id,
|
||||
@@ -20,6 +21,7 @@ class Task {
|
||||
required this.status,
|
||||
required this.progress,
|
||||
required this.createdAt,
|
||||
required this.updatedAt,
|
||||
});
|
||||
|
||||
factory Task.fromJson(Map<String, dynamic> json) => _$TaskFromJson(json);
|
||||
|
||||
@@ -12,6 +12,7 @@ Task _$TaskFromJson(Map<String, dynamic> json) => Task(
|
||||
status: $enumDecode(_$StatusEnumMap, json['status']),
|
||||
progress: Progress.fromJson(json['progress'] as Map<String, dynamic>),
|
||||
createdAt: DateTime.parse(json['createdAt'] as String),
|
||||
updatedAt: DateTime.parse(json['updatedAt'] as String),
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$TaskToJson(Task instance) => <String, dynamic>{
|
||||
@@ -20,6 +21,7 @@ Map<String, dynamic> _$TaskToJson(Task instance) => <String, dynamic>{
|
||||
'status': _$StatusEnumMap[instance.status]!,
|
||||
'progress': instance.progress.toJson(),
|
||||
'createdAt': instance.createdAt.toIso8601String(),
|
||||
'updatedAt': instance.updatedAt.toIso8601String(),
|
||||
};
|
||||
|
||||
const _$StatusEnumMap = {
|
||||
|
||||
@@ -3,5 +3,6 @@ import 'package:gopeed/app/modules/task/controllers/task_list_controller.dart';
|
||||
import '../../../../api/model/task.dart';
|
||||
|
||||
class TaskDownloadedController extends TaskListController {
|
||||
TaskDownloadedController() : super([Status.done], SortDirection.asc);
|
||||
TaskDownloadedController()
|
||||
: super([Status.done], (a, b) => b.updatedAt.compareTo(a.updatedAt));
|
||||
}
|
||||
@@ -9,5 +9,5 @@ class TaskDownloadingController extends TaskListController {
|
||||
Status.pause,
|
||||
Status.wait,
|
||||
Status.error
|
||||
], SortDirection.desc);
|
||||
], (a, b) => b.createdAt.compareTo(a.createdAt));
|
||||
}
|
||||
@@ -5,13 +5,11 @@ import 'package:get/get.dart';
|
||||
import '../../../../api/api.dart';
|
||||
import '../../../../api/model/task.dart';
|
||||
|
||||
enum SortDirection { asc, desc }
|
||||
|
||||
abstract class TaskListController extends GetxController {
|
||||
List<Status> statuses;
|
||||
SortDirection sortDirection;
|
||||
int Function(Task a, Task b) compare;
|
||||
|
||||
TaskListController(this.statuses, this.sortDirection);
|
||||
TaskListController(this.statuses, this.compare);
|
||||
|
||||
final tasks = <Task>[].obs;
|
||||
final isRunning = false.obs;
|
||||
@@ -48,13 +46,7 @@ abstract class TaskListController extends GetxController {
|
||||
getTasksState() async {
|
||||
final tasks = await getTasks(statuses);
|
||||
// sort tasks by create time
|
||||
tasks.sort((a, b) {
|
||||
if (sortDirection == SortDirection.asc) {
|
||||
return a.createdAt.compareTo(b.createdAt);
|
||||
} else {
|
||||
return b.createdAt.compareTo(a.createdAt);
|
||||
}
|
||||
});
|
||||
tasks.sort(compare);
|
||||
this.tasks.value = tasks;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user