fix: show full garage stats independent of pagination
This commit is contained in:
parent
f2c3e80f3f
commit
69362e7a96
1 changed files with 42 additions and 13 deletions
|
|
@ -33,6 +33,8 @@ class GarageScreen extends StatefulWidget {
|
|||
|
||||
class GarageScreenState extends State<GarageScreen> {
|
||||
List<Map<String, dynamic>> _cars = [];
|
||||
int _totalCarsCount = 0;
|
||||
int _recentCarsCount = 0;
|
||||
bool _isLoading = true;
|
||||
bool _isLoadingMore = false;
|
||||
bool _hasMore = true;
|
||||
|
|
@ -79,6 +81,7 @@ class GarageScreenState extends State<GarageScreen> {
|
|||
_hasMore = true;
|
||||
_selectedIds.clear();
|
||||
_selectionMode = false;
|
||||
_loadCollectionStats();
|
||||
}
|
||||
|
||||
if (!_hasMore && !reset) return;
|
||||
|
|
@ -134,6 +137,43 @@ class GarageScreenState extends State<GarageScreen> {
|
|||
}
|
||||
}
|
||||
|
||||
Future<void> _loadCollectionStats() async {
|
||||
try {
|
||||
final weekAgoIso = DateTime.now()
|
||||
.subtract(const Duration(days: 7))
|
||||
.toUtc()
|
||||
.toIso8601String();
|
||||
|
||||
final totalResult = await supabase
|
||||
.from('hotwheels')
|
||||
.select('id')
|
||||
.eq('collection_id', widget.collectionId);
|
||||
|
||||
final recentResult = await supabase
|
||||
.from('hotwheels')
|
||||
.select('id')
|
||||
.eq('collection_id', widget.collectionId)
|
||||
.gte('created_at', weekAgoIso);
|
||||
|
||||
if (!mounted) return;
|
||||
setState(() {
|
||||
_totalCarsCount = totalResult.length;
|
||||
_recentCarsCount = recentResult.length;
|
||||
});
|
||||
} catch (_) {
|
||||
if (!mounted) return;
|
||||
setState(() {
|
||||
_totalCarsCount = _cars.length;
|
||||
_recentCarsCount = _cars.where((c) {
|
||||
final ts = c['created_at'];
|
||||
final d = ts == null ? null : DateTime.tryParse(ts.toString());
|
||||
final weekAgo = DateTime.now().subtract(const Duration(days: 7));
|
||||
return d != null && d.isAfter(weekAgo);
|
||||
}).length;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
List<Map<String, dynamic>> get _filteredCars {
|
||||
if (_searchQuery.isEmpty) return _cars;
|
||||
final q = _searchQuery.toLowerCase();
|
||||
|
|
@ -230,13 +270,13 @@ class GarageScreenState extends State<GarageScreen> {
|
|||
children: [
|
||||
_StatChip(
|
||||
icon: Icons.directions_car,
|
||||
label: '${_cars.length}',
|
||||
label: '$_totalCarsCount',
|
||||
subtitle: 'Total Cars',
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
_StatChip(
|
||||
icon: Icons.new_releases,
|
||||
label: _recentCount(),
|
||||
label: '$_recentCarsCount',
|
||||
subtitle: 'This Week',
|
||||
),
|
||||
],
|
||||
|
|
@ -365,17 +405,6 @@ class GarageScreenState extends State<GarageScreen> {
|
|||
);
|
||||
}
|
||||
|
||||
String _recentCount() {
|
||||
final weekAgo = DateTime.now().subtract(const Duration(days: 7));
|
||||
final count = _cars.where((c) {
|
||||
final ts = c['created_at'];
|
||||
if (ts == null) return false;
|
||||
final d = DateTime.tryParse(ts.toString());
|
||||
return d != null && d.isAfter(weekAgo);
|
||||
}).length;
|
||||
return '$count';
|
||||
}
|
||||
|
||||
void _toggleSelectionMode(bool enabled) {
|
||||
if (widget.isViewer && enabled) return;
|
||||
setState(() {
|
||||
|
|
|
|||
Loading…
Reference in a new issue