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

Create Toy App #16

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

yuriyivanenko
Copy link

App is able to fetch toys from backend API. We can also add new toys to our backend as well as update the likes.

App is able to fetch toys from backend API. We can
also add new toys to our backend as well as update
the likes.
Copy link

@stephenmckeon stephenmckeon left a comment

Choose a reason for hiding this comment

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

Awesome work!

Comment on lines +13 to +32
const createHTMLElement = (tag, className, textContent, src, id) => {
const element = document.createElement(tag)
if(className) element.className = className
if(textContent) element.textContent = textContent
if(src) element.src = src
if(id) element.id = id
return element
}

const renderToyCard = (toy) => {
const div = createHTMLElement('div', 'card')
div.appendChild(createHTMLElement('h2', null, toy.name))
div.appendChild(createHTMLElement('img', 'toy-avatar', null,toy.image))
div.appendChild(createHTMLElement('p', null, `${toy.likes} Likes`))
const button = createHTMLElement('button', 'like-btn', `Like ❤️`, null, `${toy.id}`)
button.style.cursor = 'pointer'
button.addEventListener('click', handlePATCHLikes)
div.appendChild(button)
toyCollection.appendChild(div)
}

Choose a reason for hiding this comment

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

I appreciate the idea, but it's certainly confusing. Contrary to the saying, sometimes more is less. Sacrificing readability to make something shorter is always a tough dilemma, but I think in this case being more explicit is the way to go. But again, I love the creativity.

Comment on lines +41 to +42
e.target[0].value = ''
e.target[1].value = ''

Choose a reason for hiding this comment

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

Suggested change
e.target[0].value = ''
e.target[1].value = ''
e.target.reset()

})
.then(res => res.json())
.then(data => updateLikes(data, event))
.catch(handleError)

Choose a reason for hiding this comment

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

Nice!

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