Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: A valid product needs to have a photo (otherwise -> new) #6191

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 34 additions & 6 deletions packages/smooth_app/lib/data_models/continuous_scan_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ import 'package:smooth_app/services/smooth_services.dart';

enum ScannedProductState {
FOUND,

/// Products without pictures are considered as not found
FOUND_BUT_CONSIDERED_AS_NOT_FOUND,
NOT_FOUND,
LOADING,
CACHED,
Expand Down Expand Up @@ -153,8 +156,11 @@ class ContinuousScanModel with ChangeNotifier {
if (!_barcodes.contains(barcode)) {
_barcodes.add(barcode);
}
_setBarcodeState(barcode, ScannedProductState.LOADING);
_cacheOrLoadBarcode(barcode);

if (state != ScannedProductState.FOUND_BUT_CONSIDERED_AS_NOT_FOUND) {
_setBarcodeState(barcode, ScannedProductState.LOADING);
_cacheOrLoadBarcode(barcode);
}
lastConsultedBarcode = barcode;
return true;
}
Expand Down Expand Up @@ -187,8 +193,16 @@ class ContinuousScanModel with ChangeNotifier {
final FetchedProduct fetchedProduct =
await _queryBarcode(barcode).timeout(SnackBarDuration.long);
if (fetchedProduct.product != null) {
_addProduct(barcode, ScannedProductState.CACHED);
return true;
if (fetchedProduct.isValid) {
_addProduct(barcode, ScannedProductState.CACHED);
return true;
} else {
_setBarcodeState(
barcode,
ScannedProductState.FOUND_BUT_CONSIDERED_AS_NOT_FOUND,
);
return true;
}
}
} on TimeoutException {
// We tried to load the product from the server,
Expand Down Expand Up @@ -218,7 +232,14 @@ class ContinuousScanModel with ChangeNotifier {
final FetchedProduct fetchedProduct = await _queryBarcode(barcode);
switch (fetchedProduct.status) {
case FetchedProductStatus.ok:
_addProduct(barcode, ScannedProductState.FOUND);
if (fetchedProduct.isValid) {
_addProduct(barcode, ScannedProductState.FOUND);
} else {
_setBarcodeState(
barcode,
ScannedProductState.FOUND_BUT_CONSIDERED_AS_NOT_FOUND,
);
}
return;
case FetchedProductStatus.internetNotFound:
_setBarcodeState(barcode, ScannedProductState.NOT_FOUND);
Expand All @@ -238,7 +259,14 @@ class ContinuousScanModel with ChangeNotifier {
final FetchedProduct fetchedProduct = await _queryBarcode(barcode);
switch (fetchedProduct.status) {
case FetchedProductStatus.ok:
_addProduct(barcode, ScannedProductState.FOUND);
if (fetchedProduct.isValid) {
_addProduct(barcode, ScannedProductState.FOUND);
} else {
_setBarcodeState(
barcode,
ScannedProductState.FOUND_BUT_CONSIDERED_AS_NOT_FOUND,
);
}
return;
case FetchedProductStatus.internetNotFound:
_setBarcodeState(barcode, ScannedProductState.NOT_FOUND);
Expand Down
5 changes: 5 additions & 0 deletions packages/smooth_app/lib/data_models/fetched_product.dart
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,9 @@ class FetchedProduct {
);
}
}

/// A valid product needs to have photos (otherwise, we consider it as new)
bool get isValid =>
product?.statesTags != null &&
!product!.statesTags!.contains('en:photos-to-be-uploaded');
}
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,10 @@ class ProductDialogHelper {
final AppLocalizations appLocalizations = AppLocalizations.of(context);
switch (fetchedProduct.status) {
case FetchedProductStatus.ok:
if (!fetchedProduct.isValid) {
_openProductNotFoundDialog();
return;
}
throw Exception("You're not supposed to call this if the status is ok");
case FetchedProductStatus.userCancelled:
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ class _ScanPageCarouselState extends State<ScanPageCarousel> {
onRemoveProduct: (_) => _model.removeBarcode(barcode),
);
case ScannedProductState.NOT_FOUND:
case ScannedProductState.FOUND_BUT_CONSIDERED_AS_NOT_FOUND:
return ScanProductCardNotFound(
barcode: barcode,
onAddProduct: () async {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ class SearchProductHelper extends SearchHelper {
);
final FetchedProduct fetchedProduct =
await productDialogHelper.openBestChoice();
if (fetchedProduct.status == FetchedProductStatus.ok) {
if (fetchedProduct.status == FetchedProductStatus.ok &&
fetchedProduct.isValid) {
// TODO(monsieurtanuki): add OxF to Matomo data?
AnalyticsHelper.trackSearch(
search: value,
Expand Down
Loading