Fix trips on entry page, correct order of trips on dashboard and trip page, move to prod api
Some checks failed
Release / meta (push) Successful in 17s
Release / linux-build (push) Successful in 1m33s
Release / android-build (push) Successful in 15m28s
Release / release-dev (push) Failing after 4s
Release / release-master (push) Successful in 29s

This commit is contained in:
2025-12-12 09:17:18 +00:00
parent 53eaf0b4af
commit 292163bda6
6 changed files with 180 additions and 110 deletions

View File

@@ -117,7 +117,8 @@ class DataService extends ChangeNotifier {
);
}
final buffer = StringBuffer(
'?sort_direction=$sortDirection&sort_by=$sortBy&offset=$offset&limit=$limit');
'?sort_direction=$sortDirection&sort_by=$sortBy&offset=$offset&limit=$limit',
);
if (dateRangeStart != null && dateRangeStart.isNotEmpty) {
buffer.write('&date_range_start=$dateRangeStart');
}
@@ -178,7 +179,7 @@ class DataService extends ChangeNotifier {
try {
final params = StringBuffer('?limit=$limit&offset=$offset');
if (hadOnly) params.write('&had_only=true');
if (mileageFirst) params.write('&mileage_first=true');
if (!mileageFirst) params.write('&mileage_first=false');
final payload = <String, dynamic>{};
if (locoClass != null && locoClass.isNotEmpty) {
@@ -203,7 +204,7 @@ class DataService extends ChangeNotifier {
if (json is List) {
final newItems = json.map((e) => LocoSummary.fromJson(e)).toList();
_traction = append ? [..._traction, ...newItems] : newItems;
_tractionHasMore = newItems.length >= limit;
_tractionHasMore = newItems.length >= limit - 1;
} else {
throw Exception('Unexpected traction response: $json');
}
@@ -245,12 +246,13 @@ class DataService extends ChangeNotifier {
try {
final json = await api.get('/trips/legs-and-stats');
if (json is List) {
_tripDetails = json.map((e) => TripDetail.fromJson(e)).toList();
final trip_map = json.map((e) => TripDetail.fromJson(e)).toList();
_tripDetails = [...trip_map]..sort((a, b) => b.id.compareTo(a.id));
} else {
_tripDetails = [];
}
} catch (e) {
debugPrint('Failed to fetch trips: $e');
debugPrint('Failed to fetch trip_map: $e');
_tripDetails = [];
} finally {
_isTripDetailsLoading = false;
@@ -260,7 +262,7 @@ class DataService extends ChangeNotifier {
Future<void> fetchTrips() async {
try {
final json = await api.get('/trips');
final json = await api.get('/trips/mileage');
Iterable<dynamic>? raw;
if (json is List) {
raw = json;
@@ -274,10 +276,12 @@ class DataService extends ChangeNotifier {
}
}
if (raw != null) {
_tripList = raw
final trip_map = raw
.whereType<Map<String, dynamic>>()
.map((e) => TripSummary.fromJson(e))
.toList();
_tripList = [...trip_map]..sort((a, b) => b.tripId.compareTo(a.tripId));
} else {
debugPrint('Unexpected trip list response: $json');
_tripList = [];