fix: port 7 web features and repair the endless-loading screens

Root cause behind most "stuck loading" reports: the backend changed shape
(schedules became an array, location_preferences a string) while the mobile
parser still hard-cast to Map/int. The TypeError was swallowed by a silent
catch that returned null, and screens only handled the success state, so a
parse failure rendered as a permanent spinner. Same class of bug appeared
across service lists via non-null map lookups and a total absence of
request timeouts.

Ported from prosappweb:
- in-app suggestions (POST /suggestions)
- policies/terms from GET /settings/policies
- configurable appointment length (slot_duration_minutes)
- block/unblock calendar slots (POST /services/block)
- GPS city detection on the profile (Nominatim)
- server-side professional search with haversine distance
- retry cooldown after a rejected professional application

Reliability:
- parse schedules array (day_of_week 0=Mon) and string location_preferences
- read times as wall clock, so 08:00 stays 08:00 across timezones
- carry minutes into hours in TimeOfDay.add; a minute-based step used to
  loop forever and freeze the calendar (covered by test/time_slots_test.dart)
- semver update check instead of string equality, which blocked every build
  that did not exactly match the configured version
- request timeouts across all repositories
- surface HTTP >= 400 instead of reporting failed writes as success
- error states with retry instead of an indefinite shimmer

Includes pre-existing uncommitted work from the UI redesign.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
Lizandro Guarnizo
2026-08-24 16:45:42 -05:00
co-authored by Claude Opus 5
parent 06a89df690
commit 8631e6f729
86 changed files with 5470 additions and 5291 deletions
@@ -5,6 +5,8 @@ import 'package:http/http.dart' as http;
import 'package:shared_preferences/shared_preferences.dart';
import 'package:service_repository/service_repository.dart';
const _kHttpTimeout = Duration(seconds: 20);
const _base = 'https://backend.prosapp.co/api/v1';
// Backend uses string status; Flutter uses int-indexed enum
@@ -50,7 +52,7 @@ class ApiServiceRepository {
}
Future<dynamic> _get(String path) async {
final res = await http.get(Uri.parse('$_base$path'), headers: await _headers());
final res = await http.get(Uri.parse('$_base$path'), headers: await _headers()).timeout(_kHttpTimeout);
return jsonDecode(res.body);
}
@@ -59,7 +61,7 @@ class ApiServiceRepository {
Uri.parse('$_base$path'),
headers: await _headers(),
body: jsonEncode(body),
);
).timeout(_kHttpTimeout);
return jsonDecode(res.body);
}
@@ -68,7 +70,7 @@ class ApiServiceRepository {
Uri.parse('$_base$path'),
headers: await _headers(),
body: jsonEncode(body),
);
).timeout(_kHttpTimeout);
return jsonDecode(res.body);
}
@@ -149,6 +151,17 @@ class ApiServiceRepository {
});
}
Future<String> blockSlot(String day, TimeOfDay hour1) async {
String fmt(TimeOfDay t) =>
'${t.hour.toString().padLeft(2, '0')}:${t.minute.toString().padLeft(2, '0')}';
final data = await _post('/services/block', {
'day': day,
'range1_hour1': fmt(hour1),
});
return data['id']?.toString() ?? '';
}
Stream<ServiceEntity> getService(String serviceId) {
final controller = StreamController<ServiceEntity>();
_get('/services/$serviceId').then((data) {
@@ -169,12 +182,11 @@ class ApiServiceRepository {
return _stream('/services/professional');
}
Future<List<ServiceEntity>> getServicesForProfessionalforCalendar(String professionalId) async {
try {
return _parseList(await _get('/services/professional/calendar'));
} catch (_) {
return [];
}
/// Throws on failure: the caller must distinguish "no bookings" from
/// "could not load bookings", otherwise busy slots render as free.
Future<List<ServiceEntity>> getServicesForProfessionalforCalendar(
String professionalId) async {
return _parseList(await _get('/services/professional/calendar'));
}
Stream<List<ServiceEntity>> getServicesHistoryForUser(String userId) {