Skip to content

Broken images should be detected and replaced with proper graphics #40050

Closed

Description

@ahmaxed

image

Activity

  1. added
    scope: curriculum
    platform: learn
    status: waiting triage
    on Oct 21, 2020
  2. ahmaxed commented on Oct 21, 2020

    @ahmaxed
    MemberAuthor

    @ojeytonwilliams, should we show the default avatar or a broken image graphic instead?

  3. ojeytonwilliams commented on Oct 21, 2020

    @ojeytonwilliams
    Contributor

    A broken image graphic looks, to me, like the site is not working correctly. I'd prefer the default avatar.

    Ideally the user should be informed their avatar is broken on the settings page, if we can do that in a sensible way. Maybe validate the image and warn if it does not return status 200?

  4. RandellDawson commented on Oct 21, 2020

    @RandellDawson
    Member

    Why don't we just host the image for the avatar, so there would never be a broken image to begin with?

  5. ojeytonwilliams commented on Oct 21, 2020

    @ojeytonwilliams
    Contributor

    Why don't we just host the image for the avatar, so there would never be a broken image to begin with?

    The avatar's fine. We just just need to be able to handle the case where someone provides a link that doesn't point to an image.

  6. amel-selmane commented on Dec 27, 2020

    @amel-selmane

    Hello :) Do we have news about this graphic issue ?

  7. ahmaxed commented on Dec 27, 2020

    @ahmaxed
    MemberAuthor

    @amel-selmane, We should go ahead with detecting if the user provided image is broken and show the default avatar.

  8. Ismailtlem commented on Mar 25, 2021

    @Ismailtlem
    Member

    Can you guys sign in locally ? After running the project locally, clicking on the sign in button directs to http://localhost:3000/signin which doesn't return anything

  9. RandellDawson commented on Mar 25, 2021

    @RandellDawson
    Member

    @Ismailtlem Did you seed the database before running npm run develop ?

    You can try running the following per our documentation?

    npm run seed

    or

    npm run seed:certified-user
  10. Ismailtlem commented on Mar 25, 2021

    @Ismailtlem
    Member

    works thanks

  11. Ismailtlem commented on Apr 1, 2021

    @Ismailtlem
    Member

    Here is a first fix in the handleSubmit method in the About.js component. It is just about seing if the provided url for the profil image is valid. If the provided url is incorrect, the default image is set. Should we maybe show some message if the provided url is incorrect ?

        handleSubmit = e => {
        e.preventDefault();
        var { formValues } = this.state;
        const { submitNewAbout } = this.props;
        const req = new XMLHttpRequest();
        req.onreadystatechange = function () {
          if (req.status !== 200) {
            formValues = {
              name: formValues.name,
              location: formValues.location,
              picture: 'https://freecodecamp.com/sample-image.png',
              about: formValues.about
            };
          }
        };
        req.open(`GET`, formValues.picture, true);
        req.send();
        return this.setState({ formClicked: true }, () =>
          submitNewAbout(formValues)
        );
      };
    

    What do you guys think ?

  12. ahmaxed commented on Apr 4, 2021

    @ahmaxed
    MemberAuthor

    @Ismailtlem, yes, I think we should display a massage in that case.
    If the user sends a broken image, we do not need to alter the form values.

    So there are two possibilities here:

    1. the user is trying to submit a broken image.
      We can have client validations and check if the link is working, etc, and display an error accordingly.

    2. the image ink breaks after submission.
      For the second, there is an image onError event that we could utilize and display the default image. Showing the flash message is not necessary.

  13. Ismailtlem commented on Apr 15, 2021

    @Ismailtlem
    Member

    Hi,

    • Any better solution to find if the url provided is valid apart from sending a get request to it ? A cors problem might appear that might block the incoming request. I tried also to use fetch with the following code on the About.js component but it also come with some misbehaviors
      handleSubmit = async e => {
        e.preventDefault();
        var { formValues } = this.state;
        const { submitNewAbout } = this.props;
       await fetch(formValues.picture, {
          method: 'GET',
          mode: 'no-cors',
          cache: 'default',
          credentials: 'same-origin',
          redirect: 'follow'
        })
          .then(response => {
            this.setState({ formClicked: true }, () => submitNewAbout(formValues));
          })
          .catch(error => {
            console.log(error);
            alert('The url of the picture provided is invalid');
          });
        return;
      };
    
    • How to call a flash message from the frontend ?
    • If one wants to add a flash message that doesn't exist yet (like a flash message saying that an incorrect picture url was provided), he should add also its translations to spanish and chinese right ?
  14. ShaunSHamilton commented on Apr 15, 2021

    @ShaunSHamilton
    Member

    @Ismailtlem

    How to call a flash message from the frontend ?

    You need to dispatch an action (createFlashMessage), which takes an object describing the type and the message. The message should be one of: https://github.com/freeCodeCamp/freeCodeCamp/blob/main/client/i18n/locales/english/translations.json#L410

    add also its translations to spanish and chinese right ?

    If it is new, then you add the English to all files, and they will be translated on Crowdin.

    Now that you know what we call it (the action), it is easiest just to look how it has been used in other places in the client.

    Hope this helps

  15. Ismailtlem commented on Apr 16, 2021

    @Ismailtlem
    Member

    Would only checking the extension of the image in the url as well as checking the presence of the http prefix (or https) with a regular expression be sufficient to check the correctness of a URL @ahmadabdolsaheb ? (Not so sure about that ..)

  16. ahmaxed commented on Apr 17, 2021

    @ahmaxed
    MemberAuthor

    Here are the suggestions from chat:
    If there's any error, CORS or otherwise, we could consider the image invalid and display flash error.

    Here are some resources from image verification:
    https://stackoverflow.com/questions/9714525/javascript-image-url-verify
    https://stackoverflow.com/questions/8124866/how-does-one-use-the-onerror-attribute-of-an-img-element

    Please let us know if you would need more help with arriving at viable solution.

  17. Ismailtlem commented on Apr 26, 2021

    @Ismailtlem
    Member

    Hi, I made a first trial in this PR #41927

    • I added a parameter in the state for handling an incorrect image and displaying the error message
    • for the second point you mentionned @ahmadabdolsaheb regarding that the image might break after submission. Shall we create some script that checks that the url provided is still valide every 3 days or so ?

    Any feedbacks or improvements are very welcome

  18. added and removed
    status: waiting triage
    on Apr 29, 2021
  19. ahmaxed commented on May 3, 2021

    @ahmaxed
    MemberAuthor

    Thanks for working on this feature.

    • for the second point you mentionned @ahmadabdolsaheb regarding that the image might break after submission. Shall we create some script that checks that the url provided is still valide every 3 days or so ?

    Adding a script is not necessary. The user should be able to recognize that their image is not matching the submitted image.

  20. ahmaxed commented on May 24, 2021

    @ahmaxed
    MemberAuthor

    We would just need another pr to target the onError event of the profile images on the navigation and on the profile page and show the default image.

  21. Ismailtlem commented on May 30, 2021

    @Ismailtlem
    Member

    Hi

    • Can a bug still happen on the profil page after this fix ? Same thing for the navigation page.
  22. ahmaxed commented on Jun 1, 2021

    @ahmaxed
    MemberAuthor

    Yes, if the image link breaks after submission. That is the root of the screenshot on the issue description.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

platform: learnscope: curriculum

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions