feat: enhance inventory and pantry features with filtering, sorting, and error handling improvements

This commit is contained in:
Nils-Johan Gynther
2026-04-22 18:14:19 +02:00
parent dd05fed279
commit 07ed164112
8 changed files with 142 additions and 11 deletions
@@ -7,15 +7,36 @@ import '../domain/inventory_item.dart';
import '../domain/inventory_consumption.dart';
import 'inventory_repository.dart';
class InventoryQuery {
final String location;
final String sort;
const InventoryQuery({required this.location, required this.sort});
}
final inventoryLocationFilterProvider = StateProvider<String>((ref) => '');
final inventorySortFilterProvider = StateProvider<String>((ref) => '');
final inventoryQueryProvider = Provider<InventoryQuery>((ref) {
final location = ref.watch(inventoryLocationFilterProvider);
final sort = ref.watch(inventorySortFilterProvider);
return InventoryQuery(location: location, sort: sort);
});
final inventoryRepositoryProvider = Provider<InventoryRepository>((ref) {
return InventoryRepository(ref.watch(apiClientProvider));
});
final inventoryProvider = FutureProvider<List<InventoryItem>>((ref) async {
final token = await ref.watch(authStateProvider.future);
final query = ref.watch(inventoryQueryProvider);
return guardedApiCall(
ref,
() => ref.read(inventoryRepositoryProvider).fetchInventory(token: token),
() => ref.read(inventoryRepositoryProvider).fetchInventory(
location: query.location,
sort: query.sort,
token: token,
),
);
});