feat: enhance inventory and pantry features with filtering, sorting, and error handling improvements
This commit is contained in:
@@ -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,
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user