Add pagination to tasks

This commit is contained in:
Hillel Coren 2023-03-17 14:54:25 +02:00
parent a55ffbf888
commit 764255e6c6
3 changed files with 18 additions and 7 deletions

View File

@ -35,9 +35,10 @@ class TaskRepository {
return taskResponse.data;
}
Future<BuiltList<TaskEntity>> loadList(
Credentials credentials, int createdAt, bool filterDeleted) async {
final url = credentials.url + '/tasks?created_at=$createdAt';
Future<BuiltList<TaskEntity>> loadList(Credentials credentials, int page,
int createdAt, bool filterDeleted) async {
final url = credentials.url +
'/tasks?per_page=$kMaxRecordsPerPage&page=$page&created_at=$createdAt';
/* Server is incorrect if client isn't set
if (filterDeleted) {

View File

@ -73,9 +73,10 @@ class LoadTaskActivity {
}
class LoadTasks {
LoadTasks({this.completer});
LoadTasks({this.completer, this.page = 1});
final Completer completer;
final int page;
}
class LoadTaskRequest implements StartLoading {}

View File

@ -1,6 +1,7 @@
// Flutter imports:
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:invoiceninja_flutter/constants.dart';
// Package imports:
import 'package:redux/redux.dart';
@ -284,16 +285,24 @@ Middleware<AppState> _loadTasks(TaskRepository repository) {
repository
.loadList(
state.credentials,
action.page,
state.createdAtLimit,
state.filterDeletedClients,
)
.then((data) {
store.dispatch(LoadTasksSuccess(data));
if (action.completer != null) {
action.completer.complete(null);
if (data.length == kMaxRecordsPerPage) {
store.dispatch(LoadTasks(
completer: action.completer,
page: action.page + 1,
));
} else {
if (action.completer != null) {
action.completer.complete(null);
}
store.dispatch(LoadVendors());
}
store.dispatch(LoadVendors());
}).catchError((Object error) {
print(error);
store.dispatch(LoadTasksFailure(error));