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

[WIP] allow to complete nutrition facts #36

Merged
merged 19 commits into from
Nov 20, 2019

Conversation

alexfauquette
Copy link
Member

this pull request is related to issue #17

@teolemon
Copy link
Member

teolemon commented Aug 26, 2019

great 👌 I've pinged Raphael, Stéphane and Arnaud in the #hunger-games channel. Can you join it ?

Copy link
Contributor

@ArnaudBarre ArnaudBarre left a comment

Choose a reason for hiding this comment

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

Thanks ! Looks good overall, but I just think some edge cases are not correctly handle

const [productsBacklog, setProductsBacklog] = useState([]);

useEffect(() => {
if (nbOfPages && productsBacklog.length < 6) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Be careful, you use Math.floor to set the nb of pages, so it can be 0. even if count > 0. But the problem is that 0 is false in JS, so you should check for !== undefined or use Math.ceil (and also be careful about the edge case of count === 0)

Copy link
Contributor

Choose a reason for hiding this comment

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

Also an early return here can be good to directly see that if nbOfPages if undefined, nothing is executed

const nbOfPages = useNumberOfPages();
const [products, setProducts] = useGetProduct(nbOfPages);

return products && products.length > 0 ? (
Copy link
Contributor

Choose a reason for hiding this comment

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

You should use early return to avoid to much indentation of your main block (that will probably later be more complex). Also you should maybe add a display if products.length can be 0.
I suggest something like that (with more {} depending on your taste)

if (! products) return <p>Loading</p>
if (products.length === 0) return <p>No more product</p>
return (
  <>
    ...
  </>
)

lang: product.lang,
};
});
setProductsBacklog([...productsBacklog, ...products]);
Copy link
Contributor

Choose a reason for hiding this comment

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

I can suggest:

setProductsBacklog(
  productsBacklog.concat(
    products.map(({ code, lang, image_nutrition_url }) => ({
      code,
      imageUrl: image_nutrition_url,
      lang,
    })
  ))
)

At least try to avoid using let when not required, two const with a name like productsFormatted will be simpler because you don't need to track when the variable was updated

Copy link
Contributor

@ArnaudBarre ArnaudBarre left a comment

Choose a reason for hiding this comment

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

Cool thanks for the update. Are you sure that the api will never return an empty list ? Otherwise you could still display loading even after the query ended

@ArnaudBarre
Copy link
Contributor

Also when adding a new UI a quick screenshot in the PR description is useful to better understand the css code :)

@alexfauquette
Copy link
Member Author

To avoid having to validate multiple times the deletion of a possible nutriment, I propose the folowing design.

Here, I'm not sure of the value for energy, then I don't fill it
image

When I click on validate, a recap appears and let me the possibility to confirm or to come back for modification.
image

@ArnaudBarre
Copy link
Contributor

👍 I will just put some margin between buttons (or have skip in grey to distinct the limit and imply skip as a secondary action)

Nit: Have consistent labels for fill and skip

@alexfauquette
Copy link
Member Author

For now, server receives only filled entries. For deleted one, should I associate an empty string to them ?

@ArnaudBarre Thanks for the feedback, I will correct it

export default {
Energy: 'nutriment_energy',
Fat: 'nutriment_fat',
'Sat FAt': 'nutriment_saturated-fat',
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
'Sat FAt': 'nutriment_saturated-fat',
'Sat Fat': 'nutriment_saturated-fat',

Not quite sure the capitalization was intentional

@teolemon
Copy link
Member

teolemon commented Nov 1, 2019

Can we merge this one and start testing it ?
ALSO: We recently introduced checks in production to spot products with likely nutritional mistakes. We could load those products in priority.

@alexfauquette
Copy link
Member Author

@teolemon Yes it's ready for test.

Just for information, deletion does not work. I don't know how should I delete data. Should I send an empty string?

I did'n found time to prefile with nutrient detection

@teolemon
Copy link
Member

teolemon commented Nov 4, 2019

Yes, data deletion works with an empty string @alexfauquette

@alexfauquette
Copy link
Member Author

@teolemon and @ArnaudBarre I think It can be merged like that (after reviewing last commit of course)

I will be too busy this month to look at the "nutrient detection". We should probably add this as s distinct issue.

@teolemon teolemon merged commit 59ce422 into openfoodfacts:master Nov 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants