Repository navigation
fix(client): add validation to profile image URL - #41927
Conversation
| testImage.addEventListener('load', () => { | ||
| this.setState({ isPictureUrlValid: true }); | ||
| }); | ||
| testImage.addEventListener('error', () => { | ||
| this.setState({ isPictureUrlValid: false }); | ||
| }); |
There was a problem hiding this comment.
How can we make these mutually exclusive
There was a problem hiding this comment.
Is there any situation where they can happen at the same time ? I am not so sure about that
There was a problem hiding this comment.
If not, then why use two handlers? Why not set the state to be false and depend only the load to update the state to be truthy.
There was a problem hiding this comment.
The Image object needs to listen to the 2 events so that if one enters a faulty url and then correct it, he can submit it (because the load event will be fired and then the state will change), and to also prevent one from entering first a correct url and saving it and then editing it to become faulty (the error event will be fired). The user should not be able to submit it.
If we set the state to be false and we keep only the load event, I can first enter a correct url, submit it (the state will become true), come back to the form and edit it to become incorrect, I will still have the possibility to submit
There was a problem hiding this comment.
I see your point here. Since the changes could fire load or error and alter the validity of the image.
We would need the image in a way so we could clean up the event listeners on componentDidUnmount.
ahmaxed
left a comment
There was a problem hiding this comment.
Thanks for working on this feature, here are a few nitpicks.
| testImage.addEventListener('load', () => { | ||
| this.setState({ isPictureUrlValid: true }); | ||
| }); | ||
| testImage.addEventListener('error', () => { | ||
| this.setState({ isPictureUrlValid: false }); | ||
| }); |
There was a problem hiding this comment.
I see your point here. Since the changes could fire load or error and alter the validity of the image.
We would need the image in a way so we could clean up the event listeners on componentDidUnmount.
|
Also a cypress test would be appreciated to lock this feature down. |
This comment was marked as off-topic.
This comment was marked as off-topic.
|
Added a few tests (will maybe need some more tests) + edited the function handlePictureChange() |
Co-authored-by: Sem Bauke <[email protected]>
Checklist:
Update index.md)mainbranch of freeCodeCamp.This PR is for the issue #40050