diff --git a/lib/l10n/app_en.arb b/lib/l10n/app_en.arb index c6a802c13..d48b125c7 100644 --- a/lib/l10n/app_en.arb +++ b/lib/l10n/app_en.arb @@ -442,11 +442,14 @@ "@noNutritionalPlans": { "description": "Message shown when the user has no nutritional plans" }, - "manageLists": "Manage lists", - "@manageLists": { - "description": "Label for the button to manage ingredient lists" - }, "clearSearchTerm": "Clear search term (text)", + "@clearSearchTerm": { + "description": "Tooltip for the icon-button that clears the ingredient search text field" + }, + "ingredients": "Ingredients", + "@ingredients": { + "description": "Plural title for the ingredients overview screen" + }, "onlyLogging": "Only track calories", "onlyLoggingHelpText": "Check the box if you only want to log your calories and don't want to setup a detailed nutritional plan with specific meals", "goalMacro": "Macro goals", @@ -563,8 +566,8 @@ "@timeStartAhead": {}, "ingredient": "Ingredient", "@ingredient": { - "description": "Title for the ingredients screen" - }, + "description": "Singular label for an ingredient" + }, "energy": "Energy", "@energy": { "description": "Energy in a meal, ingredient etc. e.g. in kJ" @@ -1363,8 +1366,8 @@ "description": "Heading for the Nutri-Score slider in the ingredient search filter dialog" }, "nutriscoreValue": "Nutri-Score:", - "@filterNutriscore": { - "description": "label for Nutri-Score(nutriscore) for.eg, in subtitle of ingredient custom lists" + "@nutriscoreValue": { + "description": "Inline label prefixing a Nutri-Score value, e.g. in the subtitle of a custom ingredient list entry" }, "filterNutriscoreOff": "Off", "@filterNutriscoreOff": { diff --git a/lib/providers/ingredient_notifier.dart b/lib/providers/ingredient_notifier.dart index aab5119ef..5bb24a994 100644 --- a/lib/providers/ingredient_notifier.dart +++ b/lib/providers/ingredient_notifier.dart @@ -122,10 +122,24 @@ final class IngredientNotifier extends _$IngredientNotifier { } } -/// Trigger ingredient search flow by reacting to filter changes. -final searchedIngredientsProvider = FutureProvider>((ref) async { +/// Debounce window applied to the search-term keystrokes +const _searchDebounce = Duration(milliseconds: 350); + +/// Triggers an ingredient search whenever the filter state changes, debounced +/// to avoid one server request per keystroke. +final searchedIngredientsProvider = FutureProvider.autoDispose>((ref) async { final filters = ref.watch(ingredientFiltersSyncProvider); + // Wait for the debounce window. If the filters change again (or the + // provider is disposed) before the delay elapses, abort this run so we + // don't fire a request for an intermediate keystroke. + var disposed = false; + ref.onDispose(() => disposed = true); + await Future.delayed(_searchDebounce); + if (disposed) { + throw StateError('search debounced'); + } + // search logic handles the Online/Offline routing return ref .read(ingredientProvider.notifier) diff --git a/lib/screens/ingredients_screen.dart b/lib/screens/ingredients_screen.dart index 7135be758..f9894d1e5 100644 --- a/lib/screens/ingredients_screen.dart +++ b/lib/screens/ingredients_screen.dart @@ -52,10 +52,7 @@ class _IngredientsScreenState extends ConsumerState { return Scaffold( appBar: AppBar( - title: Text( - '${i18n.ingredient}' - 's', - ), + title: Text(i18n.ingredients), ), body: WidescreenWrapper( child: Column( diff --git a/lib/screens/nutritional_plans_screen.dart b/lib/screens/nutritional_plans_screen.dart index e38c4ff5c..ee9a54453 100644 --- a/lib/screens/nutritional_plans_screen.dart +++ b/lib/screens/nutritional_plans_screen.dart @@ -36,16 +36,17 @@ class NutritionalPlansScreen extends ConsumerWidget { @override Widget build(BuildContext context, WidgetRef ref) { + final i18n = AppLocalizations.of(context); return Scaffold( appBar: AppBar( - title: Text(AppLocalizations.of(context).nutritionalPlans), + title: Text(i18n.nutritionalPlans), actions: [ - PopupMenuButton( + PopupMenuButton<_NutritionalPlansAppBarOptions>( itemBuilder: (context) { return [ - const PopupMenuItem<_NutritionalPlansAppBarOptions>( + PopupMenuItem<_NutritionalPlansAppBarOptions>( value: _NutritionalPlansAppBarOptions.list, - child: Text('ingredient list'), // TODO: i10n + child: Text(i18n.ingredients), ), ]; },