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: Add undo option when product in list deleted! #3648

Merged
merged 3 commits into from
Jan 29, 2023

Conversation

Sudhanva-Nadiger
Copy link
Contributor

  • files_impacted
    • packages/smooth_app/lib/pages/product/common/product_list_page.dart

What

  • when the user swipes left the list item will be deleted! With a message at the bottom saying " the product removed from history, " an extra Undo action button is added in the snack bar to revert the action

Screenshot

Undo_feat.mp4

Fixes bug(s)

Part of

@codecov-commenter
Copy link

codecov-commenter commented Jan 27, 2023

Codecov Report

Merging #3648 (ede86db) into develop (6f7f193) will decrease coverage by 0.01%.
The diff coverage is 0.00%.

@@             Coverage Diff             @@
##           develop    #3648      +/-   ##
===========================================
- Coverage    10.65%   10.64%   -0.01%     
===========================================
  Files          270      270              
  Lines        13474    13484      +10     
===========================================
  Hits          1435     1435              
- Misses       12039    12049      +10     
Impacted Files Coverage Δ
...pp/lib/pages/product/common/product_list_page.dart 0.00% <0.00%> (ø)

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

@@ -323,6 +323,8 @@ class _ProductListPageState extends State<ProductListPage>
setState(() => barcodes.removeAt(index));
}
//ignore: use_build_context_synchronously
Copy link
Member

Choose a reason for hiding this comment

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

I think we can get rid of this //ignore: use_build_context_synchronously

like

if(!mounted){
    return;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done ! Thanks @AshAman999

return;
}
barcodes.insert(index, barcode);
_selectedBarcodes.add(barcode);
Copy link
Member

Choose a reason for hiding this comment

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

why are we putting it back here in _selectedBarcodes , we aren't sure if it was there or not,
I think what would make sense is checking if it was there in the _selectedBarcodes then only put it back

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because it was removed when we deleted the card ! Even it's in selected barcodes before after deleting is it necessary to put that card in selected barcodes ? If not will remove that !

Copy link
Member

Choose a reason for hiding this comment

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

I think when we called the method to remove it doesn't necessarily mean it did remove it,

The remove function works like
If it's present there remove it and return true, or return false if there's isn't this element to remove.
Ref

Copy link
Contributor Author

@Sudhanva-Nadiger Sudhanva-Nadiger Jan 28, 2023

Choose a reason for hiding this comment

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

yeah !!! got it. I will remove that line! any other changes?

Copy link
Member

Choose a reason for hiding this comment

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

I think good for now, Just a minor comment

You could have checked if the barcode was removed from the selected_barcodes, on line 322
and based on that variable, u could reinsert the barcode in the selected_barcodes, when u undoing it,

Like if it was removed then add back or ignore

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 okay to me now !

Please have a look at my comment left on your earlier reply https://github.com/openfoodfacts/smooth-app/pull/3648#discussion_r1089776915

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.

LGTM 👍

@monsieurtanuki
Copy link
Contributor

@Sudhanva-Nadiger Please fix the format.

@Sudhanva-Nadiger
Copy link
Contributor Author

I am learning how to write better code !! Thanks @monsieurtanuki

@monsieurtanuki monsieurtanuki merged commit b013a9a into openfoodfacts:develop Jan 29, 2023
@monsieurtanuki
Copy link
Contributor

Thank you @Sudhanva-Nadiger!

@Sudhanva-Nadiger
Copy link
Contributor Author

Thanks @monsieurtanuki and @AshAman999 🥺❤️

@Sudhanva-Nadiger Sudhanva-Nadiger deleted the temp branch January 29, 2023 18:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants