chore: أرشفة تطبيقات ولوحات تريبز التي سيحلّ محلها كود سيرو
استكمال قرار 2026-07-27 (كوميت fff76c9 أرشف الباك إند):
apps/rider → apps/rider-archive-cubit
apps/driver → apps/driver-archive-cubit
dashboards/admin-web → dashboards/admin-web-archive
dashboards/service-web → dashboards/service-web-archive
إعادة تسمية بلا تعديل محتوى. rider/driver كانا إعادة بناء Cubit مبنية على
عقد NestJS المؤرشف. admin-web و service-web نموذجان بملف HTML واحد (164 و
128 سطراً) — يحلّ محلهما siro_admin و siro_service المكتملان.
يُحمل من المؤرشف ولا يُعاد اكتشافه: عقد map-saas المثبَّت بالتجربة في
apps/rider-archive-cubit/lib/core/api/ (x-api-key ترويسة، reverse مصفوفة،
route في points) ودرس مسار FCM.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5
parent
fff76c949f
commit
9909d9b4c1
@@ -0,0 +1,108 @@
|
||||
import 'dart:async';
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import '../data/maps_repository.dart';
|
||||
import '../data/models/place_model.dart';
|
||||
|
||||
/// حالة شاشة البحث عن الوجهة.
|
||||
class DestinationState extends Equatable {
|
||||
final String query;
|
||||
final List<PlaceModel> results;
|
||||
final bool searching;
|
||||
final String? error;
|
||||
|
||||
const DestinationState({
|
||||
this.query = '',
|
||||
this.results = const [],
|
||||
this.searching = false,
|
||||
this.error,
|
||||
});
|
||||
|
||||
DestinationState copyWith({
|
||||
String? query,
|
||||
List<PlaceModel>? results,
|
||||
bool? searching,
|
||||
String? error,
|
||||
bool clearError = false,
|
||||
}) {
|
||||
return DestinationState(
|
||||
query: query ?? this.query,
|
||||
results: results ?? this.results,
|
||||
searching: searching ?? this.searching,
|
||||
error: clearError ? null : (error ?? this.error),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
List<Object?> get props => [query, results, searching, error];
|
||||
}
|
||||
|
||||
/// البحث عن وجهة مع debounce.
|
||||
class DestinationCubit extends Cubit<DestinationState> {
|
||||
final MapsRepository _mapsRepo;
|
||||
Timer? _debounce;
|
||||
|
||||
DestinationCubit(this._mapsRepo) : super(const DestinationState());
|
||||
|
||||
void onQueryChanged(String query) {
|
||||
_debounce?.cancel();
|
||||
emit(state.copyWith(query: query, clearError: true));
|
||||
|
||||
if (query.trim().length < 2) {
|
||||
emit(state.copyWith(results: [], searching: false));
|
||||
return;
|
||||
}
|
||||
|
||||
emit(state.copyWith(searching: true));
|
||||
|
||||
_debounce = Timer(const Duration(milliseconds: 500), () {
|
||||
_search(query);
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> _search(String query) async {
|
||||
try {
|
||||
final results = await _mapsRepo.search(query);
|
||||
emit(state.copyWith(results: results, searching: false));
|
||||
} catch (e) {
|
||||
emit(state.copyWith(
|
||||
searching: false, error: e.toString(), clearError: false));
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> searchDirectly(String query) async {
|
||||
_debounce?.cancel();
|
||||
if (query.trim().length < 2) return;
|
||||
emit(state.copyWith(searching: true, clearError: true));
|
||||
try {
|
||||
final results = await _mapsRepo.search(query);
|
||||
emit(state.copyWith(results: results, searching: false));
|
||||
} catch (e, st) {
|
||||
debugPrint('Map Search Error: $e\n$st');
|
||||
emit(state.copyWith(
|
||||
searching: false, error: e.toString(), clearError: false));
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> searchVoiceDirectly(String query,
|
||||
{double? lat, double? lng}) async {
|
||||
_debounce?.cancel();
|
||||
if (query.trim().isEmpty) return;
|
||||
emit(state.copyWith(searching: true, clearError: true));
|
||||
try {
|
||||
final results = await _mapsRepo.voiceSearch(query, lat: lat, lng: lng);
|
||||
emit(state.copyWith(results: results, searching: false));
|
||||
} catch (e, st) {
|
||||
debugPrint('Map Voice Search Error: $e\n$st');
|
||||
emit(state.copyWith(
|
||||
searching: false, error: e.toString(), clearError: false));
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> close() {
|
||||
_debounce?.cancel();
|
||||
return super.close();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,135 @@
|
||||
import 'dart:async';
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:geolocator/geolocator.dart';
|
||||
import 'package:intaleq_maps/intaleq_maps.dart';
|
||||
import '../data/maps_repository.dart';
|
||||
import '../data/models/place_model.dart';
|
||||
|
||||
/// حالة شاشة الخريطة الرئيسية.
|
||||
class HomeState extends Equatable {
|
||||
final bool loading;
|
||||
final LatLng? currentLocation;
|
||||
final LatLng? cameraTarget;
|
||||
final PlaceModel? pickup;
|
||||
final PlaceModel? destination;
|
||||
final String? error;
|
||||
|
||||
const HomeState({
|
||||
this.loading = true,
|
||||
this.currentLocation,
|
||||
this.cameraTarget,
|
||||
this.pickup,
|
||||
this.destination,
|
||||
this.error,
|
||||
});
|
||||
|
||||
HomeState copyWith({
|
||||
bool? loading,
|
||||
LatLng? currentLocation,
|
||||
LatLng? cameraTarget,
|
||||
PlaceModel? pickup,
|
||||
PlaceModel? destination,
|
||||
String? error,
|
||||
bool clearPickup = false,
|
||||
bool clearDestination = false,
|
||||
bool clearError = false,
|
||||
}) {
|
||||
return HomeState(
|
||||
loading: loading ?? this.loading,
|
||||
currentLocation: currentLocation ?? this.currentLocation,
|
||||
cameraTarget: cameraTarget ?? this.cameraTarget,
|
||||
pickup: clearPickup ? null : (pickup ?? this.pickup),
|
||||
destination: clearDestination ? null : (destination ?? this.destination),
|
||||
error: clearError ? null : (error ?? this.error),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
List<Object?> get props => [loading, currentLocation, cameraTarget, pickup, destination, error];
|
||||
}
|
||||
|
||||
/// إدارة موقع المستخدم الحالي + الخريطة.
|
||||
class HomeCubit extends Cubit<HomeState> {
|
||||
final MapsRepository _mapsRepo;
|
||||
|
||||
HomeCubit(this._mapsRepo) : super(const HomeState()) {
|
||||
initLocation();
|
||||
}
|
||||
|
||||
Future<void> initLocation() async {
|
||||
try {
|
||||
emit(state.copyWith(loading: true, clearError: true));
|
||||
|
||||
LocationPermission permission = await Geolocator.checkPermission();
|
||||
if (permission == LocationPermission.denied) {
|
||||
permission = await Geolocator.requestPermission();
|
||||
if (permission == LocationPermission.denied ||
|
||||
permission == LocationPermission.deniedForever) {
|
||||
emit(state.copyWith(
|
||||
loading: false,
|
||||
error: 'Location permission denied',
|
||||
));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
final pos = await Geolocator.getCurrentPosition(
|
||||
locationSettings: const LocationSettings(
|
||||
accuracy: LocationAccuracy.high,
|
||||
timeLimit: Duration(seconds: 10),
|
||||
),
|
||||
);
|
||||
final loc = LatLng(pos.latitude, pos.longitude);
|
||||
|
||||
// نوسّط الكاميرا على الموقع فوراً — لا ننتظر العنوان العكسي.
|
||||
emit(state.copyWith(
|
||||
loading: false,
|
||||
currentLocation: loc,
|
||||
cameraTarget: loc,
|
||||
));
|
||||
|
||||
// العنوان العكسي تحسين إضافي: فشله يجب ألّا يمنع توسيط الخريطة.
|
||||
try {
|
||||
final place = await _mapsRepo.reverseGeocode(pos.latitude, pos.longitude);
|
||||
emit(state.copyWith(pickup: place));
|
||||
} catch (_) {
|
||||
emit(state.copyWith(
|
||||
pickup: PlaceModel(name: '', lat: loc.latitude, lng: loc.longitude),
|
||||
));
|
||||
}
|
||||
} catch (e) {
|
||||
emit(state.copyWith(
|
||||
loading: false,
|
||||
error: e.toString(),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
void updateCameraTarget(LatLng target) {
|
||||
emit(state.copyWith(cameraTarget: target));
|
||||
}
|
||||
|
||||
void setPickup(PlaceModel place) {
|
||||
emit(state.copyWith(pickup: place));
|
||||
}
|
||||
|
||||
void setPickupFromLatLng(LatLng loc, {String? address}) {
|
||||
emit(state.copyWith(
|
||||
pickup: PlaceModel(
|
||||
name: address ?? '',
|
||||
address: address,
|
||||
lat: loc.latitude,
|
||||
lng: loc.longitude,
|
||||
),
|
||||
));
|
||||
}
|
||||
|
||||
void setDestination(PlaceModel place) {
|
||||
emit(state.copyWith(destination: place));
|
||||
}
|
||||
|
||||
void clearTripData() {
|
||||
emit(state.copyWith(clearPickup: true, clearDestination: true, clearError: true));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import '../data/tariff_repository.dart';
|
||||
import '../data/models/quote_model.dart';
|
||||
|
||||
/// حالة شاشة اختيار فئة الرحلة + السعر.
|
||||
class QuoteState extends Equatable {
|
||||
final bool loading;
|
||||
final QuoteModel? quote;
|
||||
final String? selectedClass;
|
||||
final String paymentMethod;
|
||||
final String? couponCode;
|
||||
final String? error;
|
||||
|
||||
const QuoteState({
|
||||
this.loading = false,
|
||||
this.quote,
|
||||
this.selectedClass,
|
||||
this.paymentMethod = 'cash',
|
||||
this.couponCode,
|
||||
this.error,
|
||||
});
|
||||
|
||||
QuoteState copyWith({
|
||||
bool? loading,
|
||||
QuoteModel? quote,
|
||||
String? selectedClass,
|
||||
String? paymentMethod,
|
||||
String? couponCode,
|
||||
String? error,
|
||||
bool clearError = false,
|
||||
bool clearCoupon = false,
|
||||
}) {
|
||||
return QuoteState(
|
||||
loading: loading ?? this.loading,
|
||||
quote: quote ?? this.quote,
|
||||
selectedClass: selectedClass ?? this.selectedClass,
|
||||
paymentMethod: paymentMethod ?? this.paymentMethod,
|
||||
couponCode: clearCoupon ? null : (couponCode ?? this.couponCode),
|
||||
error: clearError ? null : (error ?? this.error),
|
||||
);
|
||||
}
|
||||
|
||||
QuoteClassModel? get selectedQuoteClass {
|
||||
if (quote == null || selectedClass == null) return null;
|
||||
try {
|
||||
return quote!.classes.firstWhere((c) => c.vehicleClass == selectedClass);
|
||||
} catch (_) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
List<Object?> get props => [loading, quote, selectedClass, paymentMethod, couponCode, error];
|
||||
}
|
||||
|
||||
/// جلب الأسعار واختيار الفئة.
|
||||
class QuoteCubit extends Cubit<QuoteState> {
|
||||
final TariffRepository _tariffRepo;
|
||||
|
||||
QuoteCubit(this._tariffRepo) : super(const QuoteState());
|
||||
|
||||
Future<void> fetchQuote({
|
||||
required double pickupLat,
|
||||
required double pickupLng,
|
||||
String? pickupAddress,
|
||||
required double dropoffLat,
|
||||
required double dropoffLng,
|
||||
String? dropoffAddress,
|
||||
List<Map<String, dynamic>>? stops,
|
||||
String? vehicleClass,
|
||||
String? scheduledAt,
|
||||
}) async {
|
||||
emit(state.copyWith(loading: true, clearError: true));
|
||||
try {
|
||||
final quote = await _tariffRepo.getQuote(
|
||||
pickupLat: pickupLat,
|
||||
pickupLng: pickupLng,
|
||||
pickupAddress: pickupAddress,
|
||||
dropoffLat: dropoffLat,
|
||||
dropoffLng: dropoffLng,
|
||||
dropoffAddress: dropoffAddress,
|
||||
vehicleClass: vehicleClass,
|
||||
scheduledAt: scheduledAt,
|
||||
);
|
||||
final firstClass = quote.classes.isNotEmpty ? quote.classes.first.vehicleClass : null;
|
||||
emit(state.copyWith(
|
||||
loading: false,
|
||||
quote: quote,
|
||||
selectedClass: firstClass,
|
||||
));
|
||||
} catch (e) {
|
||||
emit(state.copyWith(loading: false, error: e.toString()));
|
||||
}
|
||||
}
|
||||
|
||||
void selectClass(String vehicleClass) {
|
||||
emit(state.copyWith(selectedClass: vehicleClass));
|
||||
}
|
||||
|
||||
void setPaymentMethod(String method) {
|
||||
emit(state.copyWith(paymentMethod: method));
|
||||
}
|
||||
|
||||
void setCouponCode(String? code) {
|
||||
emit(state.copyWith(couponCode: code));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
|
||||
import '../../../core/storage/saved_places_store.dart';
|
||||
|
||||
class SavedPlacesState {
|
||||
final List<SavedPlace> places;
|
||||
final bool loading;
|
||||
final String? error;
|
||||
|
||||
const SavedPlacesState({
|
||||
this.places = const [],
|
||||
this.loading = false,
|
||||
this.error,
|
||||
});
|
||||
|
||||
SavedPlacesState copyWith({
|
||||
List<SavedPlace>? places,
|
||||
bool? loading,
|
||||
String? error,
|
||||
}) {
|
||||
return SavedPlacesState(
|
||||
places: places ?? this.places,
|
||||
loading: loading ?? this.loading,
|
||||
error: error,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class SavedPlacesCubit extends Cubit<SavedPlacesState> {
|
||||
final SavedPlacesStore _store;
|
||||
|
||||
SavedPlacesCubit(this._store) : super(const SavedPlacesState());
|
||||
|
||||
Future<void> load() async {
|
||||
emit(state.copyWith(loading: true, error: null));
|
||||
try {
|
||||
final places = await _store.getAll();
|
||||
emit(SavedPlacesState(places: places));
|
||||
} catch (e) {
|
||||
emit(state.copyWith(loading: false, error: e.toString()));
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> addPlace(SavedPlace place) async {
|
||||
try {
|
||||
await _store.add(place);
|
||||
await load();
|
||||
} catch (e) {
|
||||
emit(state.copyWith(error: e.toString()));
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> removePlace(String id) async {
|
||||
try {
|
||||
await _store.remove(id);
|
||||
await load();
|
||||
} catch (e) {
|
||||
emit(state.copyWith(error: e.toString()));
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> setFavorite(String id, FavoriteType type) async {
|
||||
try {
|
||||
await _store.setFavorite(id, type);
|
||||
await load();
|
||||
} catch (e) {
|
||||
emit(state.copyWith(error: e.toString()));
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> clearFavorite(FavoriteType type) async {
|
||||
try {
|
||||
await _store.clearFavorite(type);
|
||||
await load();
|
||||
} catch (e) {
|
||||
emit(state.copyWith(error: e.toString()));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user