Skip to content

Conversation

@LiamBorner
Copy link

These are my attempts at completing the challenges

Copy link
Contributor

@BowlegsBill BowlegsBill left a comment

Choose a reason for hiding this comment

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

Added some comments

Comment on lines 13 to 24
"email-validator": "^2.0.4",
"formik": "^2.1.4",
"jquery": "^3.4.1",
"prop-types": "^15.7.2",
"react": "^16.12.0",
"react-dom": "^16.12.0",
"react-native-form-validator": "^0.3.2",
"react_ujs": "^2.6.1",
"ts-loader": "^6.2.1",
"turbolinks": "^5.2.0",
"typescript": "^3.7.5"
"typescript": "^3.7.5",
"yup": "^0.28.1"
Copy link
Contributor

Choose a reason for hiding this comment

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

I guess these were all previous attempts at validating the email?

Copy link
Author

Choose a reason for hiding this comment

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

They were indeed

Comment on lines 76 to 78
<h3>1. Randomise the image when you click the button.</h3>
/* this can potentially be achieved by using the NASA api documentation to fetch
an image from their database each time */
Copy link
Contributor

Choose a reason for hiding this comment

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

So basically NASA has 1 image per day so you need to create a random date and pass it into the getImage method and it will give you back their image for that day

@LiamBorner
Copy link
Author

Hi Bill,

If I've done this correctly, you should be able to see my amends based on your review that have been committed back to my master branch. I'm clicking 'Close and comment' so hopefully this submits those changes.

I have two outstanding issues that I'm stumped with and have tried many methods to solve them. It's frustrating as I was hoping to have them all resolved thanks to your guidance.

Copy link
Contributor

@BowlegsBill BowlegsBill left a comment

Choose a reason for hiding this comment

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

Thanks for doing this mate, much appreciated. You should receive an email from me through Pinpoint shortly



function getImage(date: string) {
return fetch(`${baseUri}?api_key=${nasaApiKey}&date=${myDate}`)
Copy link
Contributor

Choose a reason for hiding this comment

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

You don't need to use myDate here since we are passing the date into the method.

Just needs to be return fetch('${baseUri}?api_key=${nasaApiKey}&date=${date}')

<button style={buttonStyles}>Randomise</button>
<div className="card" style={{ backgroundImage: `${baseUri}?api_key=${nasaApiKey}&date=${myDate}` }} /></div>
<div style={{ display: 'flex', justifyContent: 'center' }}>
<button style={buttonStyles} >Randomise</button>
Copy link
Contributor

Choose a reason for hiding this comment

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

So for the onClick add an onclick handler to the button;

<button style={buttonStyles} onClick={handleRandomise}>Randomise</button>

Then we also need to do something with the onClick so:

function handleRandomise() {
   const randomDate = "2019-0"+Math.floor(Math.random()*12).toString() +"-" +  
   Math.floor(Math.random()*29).toString();
     getImage(randomDate).then(response => setRandomImage(response))
   }

Then we need some new state const [randomImage, setRandomImage] = React.useState('')

And finally change the background image for the card:

<div className="card" style={{ backgroundImage: `url(${randomImage})` }} /></div>
  <div style={{ display: 'flex', justifyContent: 'center' }}>
    <button style={buttonStyles} onClick={handleRandomise}>Randomise</button>
  </div>

Comment on lines +17 to +25
function validateEmail(value) {
let error;
if (!value) {
error = 'Required';
} else if (!/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i.test(value)) {
error = 'Invalid email address';
}
return error;
};
Copy link
Contributor

Choose a reason for hiding this comment

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

Pretty much there with this one.

Add an onblur handler to the email input and add the email validation error into the error box:

<input name="email" type="email" value={email} onChange={handleEmailChange} onBlur={validateEmail} />
<div style={{ color: 'red', margin: '10px 0' }}>{emailValidationError}</div>

Then change your validation function slightly:

function validateEmail(event) {
    const value = event.target.value;
    let error;
    if (!value) {
      error = 'Required';
    } else if (!/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,6}$/i.test(value)) {
      error = 'Invalid email address';
    }
    setEmailValidationError(error)
  };

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.

2 participants