Skip to content

fix(client): add validation to profile image URL - #41927

Merged
Sembauke merged 5 commits into
freeCodeCamp:mainfrom
Ismailtlem:fix/fix-broken-image-url-validation
May 23, 2021
Merged

Sembauke merged 5 commits into
freeCodeCamp:mainfrom
Ismailtlem:fix/fix-broken-image-url-validation

Conversation

@Ismailtlem

Copy link
Copy Markdown
Member

Checklist:

  • I have read freeCodeCamp's contribution guidelines.
  • My pull request has a descriptive title (not a vague title like Update index.md)
  • My pull request targets the main branch of freeCodeCamp.
  • All the files I changed are in the same world language, for example: only English changes, or only Chinese changes, etc.

This PR is for the issue #40050

@Ismailtlem
Ismailtlem requested a review from a team April 26, 2021 22:48
@github-actions github-actions Bot added the platform: learn UI side of the client application that needs familiarity with React, Gatsby etc. label Apr 26, 2021
@raisedadead raisedadead changed the title fix: fix broken image url after validation fix(client): add validation to profile image URL Apr 27, 2021
Comment thread client/src/components/settings/About.js Resolved
@raisedadead raisedadead added status: waiting update Is awaiting update, after feedback or request for changes and removed status: waiting update Is awaiting update, after feedback or request for changes labels Apr 27, 2021
@Ismailtlem Ismailtlem added the status: waiting review To be applied to PR's that are ready for QA, especially when additional review is pending. label Apr 29, 2021
@raisedadead
raisedadead requested a review from a team April 29, 2021 09:36
Comment thread client/src/components/settings/About.js Resolved
Comment thread client/src/components/settings/About.js Outdated
Comment on lines +116 to +122
testImage.addEventListener('load', () => {
this.setState({ isPictureUrlValid: true });
});
testImage.addEventListener('error', () => {
this.setState({ isPictureUrlValid: false });
});

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

How can we make these mutually exclusive

@Ismailtlem Ismailtlem Apr 29, 2021 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Is there any situation where they can happen at the same time ? I am not so sure about that

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

@Ismailtlem Ismailtlem added status: waiting review To be applied to PR's that are ready for QA, especially when additional review is pending. and removed status: waiting review To be applied to PR's that are ready for QA, especially when additional review is pending. labels Apr 29, 2021
@raisedadead
raisedadead requested review from ahmaxed and moT01 May 8, 2021 07:23
@gitpod-io

gitpod-io Bot commented May 12, 2021

Copy link
Copy Markdown

@ahmaxed ahmaxed left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for working on this feature, here are a few nitpicks.

Comment thread client/src/components/settings/About.js Outdated
Comment on lines +116 to +122
testImage.addEventListener('load', () => {
this.setState({ isPictureUrlValid: true });
});
testImage.addEventListener('error', () => {
this.setState({ isPictureUrlValid: false });
});

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

Comment thread client/src/components/settings/About.js Resolved
Comment thread client/src/components/settings/About.js Resolved
Comment thread client/src/components/settings/About.js Resolved
@ahmaxed ahmaxed added the status: waiting update Is awaiting update, after feedback or request for changes label May 12, 2021
@ahmaxed

ahmaxed commented May 12, 2021

Copy link
Copy Markdown
Member

Also a cypress test would be appreciated to lock this feature down.

@raisedadead raisedadead removed the status: waiting review To be applied to PR's that are ready for QA, especially when additional review is pending. label May 12, 2021
@ujwalvinay007

This comment was marked as off-topic.

@github-actions github-actions Bot added the scope: tools/scripts Scripts for supporting dev work, generating config and build artifacts, etc. label May 13, 2021
@Ismailtlem

Copy link
Copy Markdown
Member Author

Added a few tests (will maybe need some more tests) + edited the function handlePictureChange()

@Ismailtlem Ismailtlem added status: waiting review To be applied to PR's that are ready for QA, especially when additional review is pending. and removed status: waiting update Is awaiting update, after feedback or request for changes labels May 19, 2021
@ahmaxed
ahmaxed self-requested a review May 22, 2021 14:23
ahmaxed
ahmaxed previously approved these changes May 22, 2021
@ahmaxed
ahmaxed self-requested a review May 23, 2021 13:28
@Sembauke
Sembauke merged commit 914ff44 into freeCodeCamp:main May 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

platform: learn UI side of the client application that needs familiarity with React, Gatsby etc. scope: tools/scripts Scripts for supporting dev work, generating config and build artifacts, etc. status: waiting review To be applied to PR's that are ready for QA, especially when additional review is pending.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants