Skip to content

Commit

Permalink
feat: 5855 - no visible product type filter by default
Browse files Browse the repository at this point in the history
Impacted files:
* `background_task_price.dart`: minor unrelated fix due to off-dart 3.17.0
* `dao_product.dart`: we overwrite the products product_type with the server product type only if null
* `product_query.dart`: now retrieving product_type field in products found on a server
* `product_refresher.dart`: unrelated minor refactoring
* `pubspec.lock`: wtf
* `pubspec.yaml`: upgraded off-dart to 3.17.0
* `search_product_helper.dart`: visible/invisible product type filter, by default invisible and working on food
* `user_preferences_dev_mode.dart`: on/off switch for visible product type filter, off by default
  • Loading branch information
monsieurtanuki committed Nov 18, 2024
1 parent 2bffec1 commit 274bdd2
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ abstract class BackgroundTaskPrice extends BackgroundTask {
..productCode = barcodes[i];

// create price
final MaybeError<Price> addedPrice =
final MaybeError<Price?> addedPrice =
await OpenPricesAPIClient.createPrice(
price: newPrice,
bearerToken: bearerToken,
Expand Down
4 changes: 3 additions & 1 deletion packages/smooth_app/lib/database/dao_product.dart
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,9 @@ class DaoProduct extends AbstractSqlDao implements BulkDeletable {
required final ProductType productType,
}) async {
for (final Product product in products) {
product.productType = productType;
// in case the server product has no product type, which shouldn't happen
// in the future
product.productType ??= productType;
}
await localDatabase.database.transaction(
(final Transaction transaction) async => _bulkReplaceLoop(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ class UserPreferencesDevMode extends AbstractUserPreferences {
static const String userPreferencesTestEnvDomain = '__testEnvHost';
static const String userPreferencesFlagEditIngredients = '__editIngredients';
static const String userPreferencesFlagHideFolksonomy = '__hideFolksonomy';
static const String userPreferencesFlagHideProductTypeFilter =
'__hideProductTypeFilter';
static const String userPreferencesFlagBoostedComparison =
'__boostedComparison';
static const String userPreferencesEnumScanMode = '__scanMode';
Expand Down Expand Up @@ -375,6 +377,19 @@ class UserPreferencesDevMode extends AbstractUserPreferences {
_showSuccessMessage();
},
),
UserPreferencesItemSwitch(
title: 'Hide Product Type Filter',
value: userPreferences
.getFlag(userPreferencesFlagHideProductTypeFilter) ??
true,
onChanged: (bool value) async {
await userPreferences.setFlag(
userPreferencesFlagHideProductTypeFilter,
value,
);
_showSuccessMessage();
},
),
UserPreferencesItemSection(
label: appLocalizations.dev_mode_section_ui,
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,10 @@ class ProductRefresher {
/// Returns the standard configuration for several barcodes product query.
ProductSearchQueryConfiguration getBarcodeListQueryConfiguration(
final List<String> barcodes,
final OpenFoodFactsLanguage language, {
final List<ProductField>? fields,
}) =>
final OpenFoodFactsLanguage language,
) =>
ProductSearchQueryConfiguration(
fields: fields ?? ProductQuery.fields,
fields: ProductQuery.fields,
language: language,
country: ProductQuery.getCountry(),
parametersList: <Parameter>[
Expand Down
17 changes: 15 additions & 2 deletions packages/smooth_app/lib/pages/search/search_product_helper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import 'package:smooth_app/helpers/analytics_helper.dart';
import 'package:smooth_app/helpers/provider_helper.dart';
import 'package:smooth_app/helpers/string_extension.dart';
import 'package:smooth_app/pages/navigator/app_navigator.dart';
import 'package:smooth_app/pages/preferences/user_preferences_dev_mode.dart';
import 'package:smooth_app/pages/product/common/product_dialog_helper.dart';
import 'package:smooth_app/pages/product/common/product_query_page_helper.dart';
import 'package:smooth_app/pages/product/common/search_helper.dart';
Expand All @@ -32,7 +33,13 @@ class SearchProductHelper extends SearchHelper {
appLocalizations.search;

@override
Widget getAdditionalFilter() => _ProductTypeFilter(this);
Widget? getAdditionalFilter() =>
UserPreferences.getUserPreferencesSync().getFlag(
UserPreferencesDevMode.userPreferencesFlagHideProductTypeFilter,
) ??
true
? null
: _ProductTypeFilter(this);

@override
void search(
Expand Down Expand Up @@ -119,7 +126,13 @@ class SearchProductHelper extends SearchHelper {
localDatabase: localDatabase,
productQuery: KeywordsProductQuery(
value,
productType: _productType,
productType: UserPreferences.getUserPreferencesSync().getFlag(
UserPreferencesDevMode
.userPreferencesFlagHideProductTypeFilter,
) ??
true
? ProductType.food
: _productType,
),
context: context,
editableAppBarTitle: false,
Expand Down
1 change: 1 addition & 0 deletions packages/smooth_app/lib/query/product_query.dart
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ abstract class ProductQuery {
ProductField.NAME_ALL_LANGUAGES,
ProductField.BRANDS,
ProductField.BARCODE,
ProductField.PRODUCT_TYPE,
ProductField.NUTRISCORE,
ProductField.FRONT_IMAGE,
ProductField.IMAGE_FRONT_URL,
Expand Down
4 changes: 2 additions & 2 deletions packages/smooth_app/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1076,10 +1076,10 @@ packages:
dependency: "direct main"
description:
name: openfoodfacts
sha256: d35a213d6354246e3b27e0b18fe3def658e00c337346cf11c4f8ba082f92dfaa
sha256: "56df1ab54751a1b4491d99580b90141ea3327cf546724fa6055943e85d64fd51"
url: "https://pub.dev"
source: hosted
version: "3.16.0"
version: "3.17.0"
openfoodfacts_flutter_lints:
dependency: "direct dev"
description:
Expand Down
2 changes: 1 addition & 1 deletion packages/smooth_app/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ dependencies:
path: ../scanner/zxing


openfoodfacts: 3.16.0
openfoodfacts: 3.17.0
# openfoodfacts:
# path: ../../../openfoodfacts-dart

Expand Down

0 comments on commit 274bdd2

Please sign in to comment.