Add "go to last page" and page count to notifications and devices lists

The list endpoints now return a total count alongside the page so the
front-end can show how many pages exist and offer a last-page jump.

Backend: add count(is_new) and count_devices(...) (sharing a WHERE-builder
with list_devices so page and count can't drift), wrap both list responses
in {items, total_count} structs, and register them with utoipa.

Front-end: parse the wrapper shape (dropping the fetch-one-extra trick),
add a Last-page button and a responsive "Page X of Y" / "X / Y" label to
the shared PaginationBar, and track the total in both lists. Notifications
re-sync the count on every fetch and decrement it locally on mark-read/
unread removals so the count stays accurate without a re-fetch.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
rzuasti
2026-06-05 21:09:25 -04:00
co-authored by Claude Opus 4.8
parent 3cb104e364
commit 844d7d189c
21 changed files with 765 additions and 275 deletions
+8 -12
View File
@@ -87,19 +87,15 @@ class BackendAPI {
return fromJson(response.data as Map<String, dynamic>);
}
/// Splits a "fetch one extra item" page into its items and a [hasNextPage]
/// flag. Callers request `perPage + 1` items so a full extra item signals
/// that another page exists.
({List<T> items, bool hasNextPage}) _paginate<T>(
List<dynamic> data,
/// Decodes a paged list response of the shape `{items: [...], total_count: N}`
/// into the page's items and the total number of rows matching the request's
/// filters. The total lets callers report how many pages exist and offer a
/// "go to last page" control.
({List<T> items, int totalCount}) _paginate<T>(
Map<String, dynamic> data,
T Function(dynamic) fromItem,
int perPage,
) {
final results = data.map(fromItem).toList();
final hasNextPage = results.length > perPage;
return (
items: hasNextPage ? results.take(perPage).toList() : results,
hasNextPage: hasNextPage,
);
final items = (data['items'] as List<dynamic>).map(fromItem).toList();
return (items: items, totalCount: data['total_count'] as int);
}
}