mirror of
https://github.com/rzuasti/oott.git
synced 2026-07-08 19:21:54 +02:00
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:
co-authored by
Claude Opus 4.8
parent
3cb104e364
commit
844d7d189c
@@ -1,23 +1,32 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../theme/dimens.dart';
|
||||
|
||||
class PaginationBar extends StatelessWidget {
|
||||
const PaginationBar({
|
||||
super.key,
|
||||
required this.currentPage,
|
||||
required this.hasNextPage,
|
||||
required this.totalPages,
|
||||
required this.isLoading,
|
||||
required this.onPageChanged,
|
||||
});
|
||||
|
||||
final int currentPage;
|
||||
final bool hasNextPage;
|
||||
final int totalPages;
|
||||
final bool isLoading;
|
||||
final ValueChanged<int> onPageChanged;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final lastPage = totalPages - 1;
|
||||
final canGoBack = currentPage > 0 && !isLoading;
|
||||
final canGoForward = hasNextPage && !isLoading;
|
||||
final canGoForward = currentPage < lastPage && !isLoading;
|
||||
// Phones don't have room for the verbose label, so they get the compact
|
||||
// "X / Y" form; wider layouts spell it out.
|
||||
final isWide = MediaQuery.sizeOf(context).width >= Breakpoints.medium;
|
||||
final label = isWide
|
||||
? 'Page ${currentPage + 1} of $totalPages'
|
||||
: '${currentPage + 1} / $totalPages';
|
||||
// While a page change is in flight the buttons disable so the tap reads as
|
||||
// registered and double-taps are blocked; the progress cue itself is drawn
|
||||
// by the app shell at the bottom of the page body.
|
||||
@@ -39,10 +48,7 @@ class PaginationBar extends StatelessWidget {
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16),
|
||||
child: Text(
|
||||
'Page ${currentPage + 1}',
|
||||
style: Theme.of(context).textTheme.bodyMedium,
|
||||
),
|
||||
child: Text(label, style: Theme.of(context).textTheme.bodyMedium),
|
||||
),
|
||||
IconButton.outlined(
|
||||
onPressed: canGoForward
|
||||
@@ -51,6 +57,12 @@ class PaginationBar extends StatelessWidget {
|
||||
icon: const Icon(Icons.chevron_right),
|
||||
tooltip: 'Next page',
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
IconButton.outlined(
|
||||
onPressed: canGoForward ? () => onPageChanged(lastPage) : null,
|
||||
icon: const Icon(Icons.last_page),
|
||||
tooltip: 'Last page',
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user