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

fix: 3018 - instant upload of images #3329

Merged
merged 4 commits into from Nov 19, 2022

Conversation

monsieurtanuki
Copy link
Contributor

New files:

  • ocr_widget.dart: Widget dedicated to OCR, with 3 actions: upload image, extract data, save. Used to be in edit_ingredients_page.dart
  • transient_file.dart: Helper class about transient files (= not fully uploaded yet).

Impacted files:

  • add_basic_details_page.dart: minor refactoring
  • add_new_product_page.dart: refactored around the class image repository
  • app_en.arb: added 1 label when OCR fails
  • app_fr.arb: added 1 label when OCR fails
  • background_task_details.dart: minor refactoring
  • background_task_image.dart: immediate execution with just one try
  • confirm_and_upload_picture.dart: minor refactoring with new private class _OutlinedButton
  • edit_ingredients_page.dart: moved OcrWidget code to dedicated new dart file; fixed the extract button - that cannot be reached if the image is not uploaded yet
  • image_crop_page.dart: refactored with more explicit method names
  • image_upload_card.dart: refactored with TransientFile
  • new_product_page.dart: minor refactoring
  • product_cards_helper.dart: minor refactoring
  • product_image_carousel.dart: minor refactoring
  • product_image_gallery_view.dart: refactored with new method confirmAndUploadNewPicture and new class TransientFile
  • product_image_viewer.dart: refactored with new class TransientFile
  • question_card.dart: minor refactoring
  • smooth_product_image.dart: refactored with new class TransientFile

What

  • The whole point of this PR is the use of new class TransientFile.
  • With this class, we can
    • instantaneously fake in the whole app that an image is uploaded, as soon as the user clicks on the "upload" button
    • when the upload is actually finished, the app will be refreshed and take into account the "server version" of the image (the "transient version" being deleted locally)
    • as with "details", for the moment we work on a "I'm lucky" mode - we try once, and rollback if it fails

Part of

New files:
* `ocr_widget.dart`: Widget dedicated to OCR, with 3 actions: upload image, extract data, save. Used to be in `edit_ingredients_page.dart`
* `transient_file.dart`: Helper class about transient files (= not fully uploaded yet).

Impacted files:
* `add_basic_details_page.dart`: minor refactoring
* `add_new_product_page.dart`: refactored around the class image repository
* `app_en.arb`: added 1 label when OCR fails
* `app_fr.arb`: added 1 label when OCR fails
* `background_task_details.dart`: minor refactoring
* `background_task_image.dart`: immediate execution with just one try
* `confirm_and_upload_picture.dart`: minor refactoring with new private class `_OutlinedButton`
* `edit_ingredients_page.dart`: moved `OcrWidget` code to dedicated new dart file; fixed the extract button - that cannot be reached if the image is not uploaded yet
* `image_crop_page.dart`: refactored with more explicit method names
* `image_upload_card.dart`: refactored with `TransientFile`
* `new_product_page.dart`: minor refactoring
* `product_cards_helper.dart`: minor refactoring
* `product_image_carousel.dart`: minor refactoring
* `product_image_gallery_view.dart`: refactored with new method `confirmAndUploadNewPicture` and new class `TransientFile`
* `product_image_viewer.dart`: refactored with new class `TransientFile`
* `question_card.dart`: minor refactoring
* `smooth_product_image.dart`: refactored with new class `TransientFile`
@monsieurtanuki monsieurtanuki requested a review from a team as a code owner November 17, 2022 12:29
@github-actions github-actions bot added database Hunger Games 🌐 l10n 🖼️ Photos - Cropping Product addition The easier it is to add a product and get Nutri-Score, Eco-Score, the happier the users. 🥫 Product page labels Nov 17, 2022
@codecov-commenter
Copy link

codecov-commenter commented Nov 17, 2022

Codecov Report

Merging #3329 (73d2307) into develop (b0b52c5) will increase coverage by 0.00%.
The diff coverage is 0.00%.

@@           Coverage Diff            @@
##           develop    #3329   +/-   ##
========================================
  Coverage    10.48%   10.49%           
========================================
  Files          251      253    +2     
  Lines        12322    12313    -9     
========================================
  Hits          1292     1292           
+ Misses       11030    11021    -9     
Impacted Files Coverage Δ
...th_app/lib/background/background_task_details.dart 0.00% <ø> (ø)
...ooth_app/lib/background/background_task_image.dart 0.00% <0.00%> (ø)
...th_app/lib/cards/data_cards/image_upload_card.dart 0.00% <0.00%> (ø)
...ib/cards/product_cards/product_image_carousel.dart 0.00% <ø> (ø)
...ckages/smooth_app/lib/database/transient_file.dart 0.00% <0.00%> (ø)
.../lib/generic_lib/widgets/smooth_product_image.dart 0.00% <0.00%> (ø)
...s/smooth_app/lib/helpers/product_cards_helper.dart 0.00% <0.00%> (ø)
...ooth_app/lib/pages/hunger_games/question_card.dart 0.00% <ø> (ø)
packages/smooth_app/lib/pages/image_crop_page.dart 1.38% <0.00%> (-0.26%) ⬇️
..._app/lib/pages/product/add_basic_details_page.dart 0.00% <ø> (ø)
... and 7 more

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

Copy link
Member

@AshAman999 AshAman999 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me!

I tried to run it locally , my initial impressions were good , it works

@monsieurtanuki
Copy link
Contributor Author

Looks good to me!
I tried to run it locally , my initial impressions were good , it works

Please approve it if relevant.

@AshAman999
Copy link
Member

Looks good to me!
I tried to run it locally , my initial impressions were good , it works

Please approve it if relevant.

I just had a rough look, looking into more details, will update you soon
Meanwhile was waiting for some other eyes to be on this as well

@M123-dev
Copy link
Member

Don't have time today, I'm having a look at it tomorrow

Copy link
Member

@M123-dev M123-dev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great @monsieurtanuki especially that you thought about the transient image for ocr. Added some minor comments


ProductImageData getProductImageData(
final Product product,
final AppLocalizations? appLocalizations,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this nullable

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The thing is that ProductImageData does 2 different things: it computes the image provider or url, and it populates the title and button labels.
In some cases we don't use the labels, therefore we don't need the AppLocalizations. I just wanted to avoid calling a AppLocalizations.of(context) just for something I don't care about - or maybe the context was not available there, don't remember.
Could be refactored later, especially now that I created specific methods for each use-case (button label, title label, url, provider).

@@ -215,3 +166,34 @@ class _ConfirmAndUploadPictureState extends State<ConfirmAndUploadPicture> {
await model.onCreateProduct(barcode); // TODO(monsieurtanuki): a bit fishy
}
}

/// Standard button for this page.
class _OutlinedButton extends StatelessWidget {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'n not a fan of having different private buttons per page can't we use one we already have

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before in this page the same code was repeated 3 times (once for each button), so it's an improvement, isn't it?

That said, feel free to create an issue about uniformisation of buttons in pages: probably not all identical, but at least "classes" of buttons that can be reused.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
database Hunger Games 🌐 l10n 🖼️ Photos - Cropping Product addition The easier it is to add a product and get Nutri-Score, Eco-Score, the happier the users. 🥫 Product page
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants