mirror of
https://github.com/qinglong-app/qinglong_app.git
synced 2025-10-09 16:48:19 +08:00
add pin
This commit is contained in:
@@ -1,12 +1,8 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:math';
|
||||
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:qinglong_app/base/base_viewmodel.dart';
|
||||
import 'package:qinglong_app/base/http/api.dart';
|
||||
import 'package:qinglong_app/base/http/http.dart';
|
||||
import 'package:qinglong_app/module/task/task_bean.dart';
|
||||
import 'package:qinglong_app/module/task/task_detail/task_detail_bean.dart';
|
||||
|
||||
var taskProvider = ChangeNotifierProvider((ref) => TaskViewModel());
|
||||
|
||||
@@ -42,6 +38,9 @@ class TaskViewModel extends BaseViewModel {
|
||||
list.sort((a, b) {
|
||||
return a.status!.compareTo(b.status!);
|
||||
});
|
||||
list.sort((a, b) {
|
||||
return b.isPinned!.compareTo(a.isPinned!);
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> runCrons(String cron) async {
|
||||
@@ -85,4 +84,28 @@ class TaskViewModel extends BaseViewModel {
|
||||
bean.command = result.command;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
void pinTask(String sId, int isPinned) async {
|
||||
if (isPinned == 1) {
|
||||
HttpResponse<NullResponse> response = await Api.unpinTask(sId);
|
||||
|
||||
if (response.success) {
|
||||
list.firstWhere((element) => element.sId == sId).isPinned = 0;
|
||||
sortList();
|
||||
success();
|
||||
} else {
|
||||
failToast(response.message, notify: true);
|
||||
}
|
||||
} else {
|
||||
HttpResponse<NullResponse> response = await Api.pinTask(sId);
|
||||
|
||||
if (response.success) {
|
||||
list.firstWhere((element) => element.sId == sId).isPinned = 1;
|
||||
sortList();
|
||||
success();
|
||||
} else {
|
||||
failToast(response.message, notify: true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user