Skip to content

Commit

Permalink
Add pagination to tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
hillelcoren committed Mar 17, 2023
1 parent a55ffbf commit 764255e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
7 changes: 4 additions & 3 deletions lib/data/repositories/task_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
3 changes: 2 additions & 1 deletion lib/redux/task/task_actions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}
Expand Down
15 changes: 12 additions & 3 deletions lib/redux/task/task_middleware.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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));
Expand Down

0 comments on commit 764255e

Please sign in to comment.