From 7a8f441390847277397612021a0236ba88759a3f Mon Sep 17 00:00:00 2001 From: Nils-Johan Gynther Date: Wed, 6 May 2026 10:43:55 +0200 Subject: [PATCH] feat: update API endpoint for product listing and simplify manual product creation UI --- .../presentation/create_inventory_screen.dart | 4 +- .../presentation/inventory_screen.dart | 87 +------------------ 2 files changed, 6 insertions(+), 85 deletions(-) diff --git a/flutter/lib/features/inventory/presentation/create_inventory_screen.dart b/flutter/lib/features/inventory/presentation/create_inventory_screen.dart index f91c3c75..c0791fee 100644 --- a/flutter/lib/features/inventory/presentation/create_inventory_screen.dart +++ b/flutter/lib/features/inventory/presentation/create_inventory_screen.dart @@ -58,7 +58,7 @@ class _CreateInventoryScreenState try { final token = await ref.read(authStateProvider.future); final api = ref.read(apiClientProvider); - final data = await api.getJson(ProductApiPaths.list, token: token); + final data = await api.getJson(ProductApiPaths.mine, token: token); final list = data is List ? data : (data is Map && data['items'] is List) @@ -326,4 +326,4 @@ class _CreateInventoryScreenState ); } } - + diff --git a/flutter/lib/features/inventory/presentation/inventory_screen.dart b/flutter/lib/features/inventory/presentation/inventory_screen.dart index 0582dbbb..a728f601 100644 --- a/flutter/lib/features/inventory/presentation/inventory_screen.dart +++ b/flutter/lib/features/inventory/presentation/inventory_screen.dart @@ -3,11 +3,8 @@ import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:go_router/go_router.dart'; import '../../../core/api/api_error_mapper.dart'; -import '../../../core/api/api_paths.dart'; -import '../../../core/api/api_providers.dart'; import '../../../core/l10n/l10n.dart'; import '../../../core/ui/async_state_views.dart'; -import '../../auth/data/auth_providers.dart'; import '../data/inventory_providers.dart'; import 'swipeable_inventory_tile.dart'; @@ -22,65 +19,6 @@ class InventoryScreen extends ConsumerWidget { (value: 'bestBeforeDesc', label: context.l10n.inventorySortBestBeforeDesc), ]; - Future _createManualProduct(BuildContext context, WidgetRef ref) async { - final nameCtrl = TextEditingController(); - final created = await showDialog( - context: context, - builder: (dialogContext) => AlertDialog( - title: const Text('Ny produkt'), - content: TextField( - controller: nameCtrl, - autofocus: true, - decoration: const InputDecoration( - labelText: 'Produktnamn', - border: OutlineInputBorder(), - ), - ), - actions: [ - TextButton( - onPressed: () => Navigator.pop(dialogContext), - child: Text(context.l10n.cancelAction), - ), - FilledButton( - onPressed: () { - final value = nameCtrl.text.trim(); - if (value.isEmpty) return; - Navigator.pop(dialogContext, value); - }, - child: const Text('Skapa'), - ), - ], - ), - ); - nameCtrl.dispose(); - - if (created == null || created.trim().isEmpty || !context.mounted) return; - - try { - final token = ref.read(authStateProvider).maybeWhen( - data: (t) => t, - orElse: () => null, - ) ?? - await ref.read(authStateProvider.future); - final api = ref.read(apiClientProvider); - await api.postJson( - ProductApiPaths.createPrivate, - body: {'name': created.trim()}, - token: token, - ); - if (!context.mounted) return; - ScaffoldMessenger.of(context).showSnackBar( - const SnackBar(content: Text('Produkt skapad. Lägg nu till den i inventariet.')), - ); - context.push('/inventory/create'); - } catch (e) { - if (!context.mounted) return; - ScaffoldMessenger.of(context).showSnackBar( - buildCopyableErrorSnackBar(context, mapErrorToUserMessage(e, context)), - ); - } - } - @override Widget build(BuildContext context, WidgetRef ref) { final location = ref.watch(inventoryLocationFilterProvider); @@ -158,21 +96,10 @@ class InventoryScreen extends ConsumerWidget { Positioned( right: 16, bottom: 16, - child: Column( - mainAxisSize: MainAxisSize.min, - children: [ - FloatingActionButton.extended( - onPressed: () => context.push('/inventory/create'), - icon: const Icon(Icons.add), - label: Text(context.l10n.addAction), - ), - const SizedBox(height: 8), - FloatingActionButton.extended( - onPressed: () => _createManualProduct(context, ref), - icon: const Icon(Icons.add_box_outlined), - label: const Text('Ny produkt'), - ), - ], + child: FloatingActionButton.extended( + onPressed: () => context.push('/inventory/create'), + icon: const Icon(Icons.add), + label: Text(context.l10n.addAction), ), ), ], @@ -202,12 +129,6 @@ class InventoryScreen extends ConsumerWidget { label: Text(context.l10n.addAction), ), const SizedBox(height: 8), - FloatingActionButton.extended( - onPressed: () => _createManualProduct(context, ref), - icon: const Icon(Icons.add_box_outlined), - label: const Text('Ny produkt'), - ), - const SizedBox(height: 8), FloatingActionButton.extended( onPressed: () => context.go('/recipes'), icon: const Icon(Icons.restaurant_menu),