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

Happy Thoughts #434

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Open

Happy Thoughts #434

wants to merge 16 commits into from

Conversation

FionaKlacar
Copy link

No description provided.

Copy link

@fannystenberg fannystenberg left a comment

Choose a reason for hiding this comment

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

Great work! Your code has a good structure and the app works as it should 💌


## The problem

Describe how you approached to problem, and what tools and techniques you used to solve it. How did you plan? What technologies did you use? If you had more time, what would be next?
I began by using the Example Project to help me understand how to write the code, which components I would need, and how to fetch and post the thoughts using the APIs. I also thought about which useState hooks I would need and which useEffect hook I would need to use. My first task was to fetch the recent thoughts, then create a thought using a POST request. After that I worked on the Heart (like) button. There were a lot of different elements to this week’s task and I needed help with some challenges I faced. I am pleased I managed to add a stretch goal in the end and if I had more time I would add another stretch goal, such as work on getting an error message back from the API if the message is empty, too long or too short.

Choose a reason for hiding this comment

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

Structured way to go about it! Always easier to divide the project in smaller bits to check off ✅

}

useEffect(() => {
fetchThoughts();

Choose a reason for hiding this comment

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

Is there any specific reason why you did a separate function instead of putting the fetch request directly in useEffect?

<Hearts
thought={thought}
fetchThoughts={fetchThoughts} />
<p className="timeStamp date">{formatDistance(new Date(thought.createdAt), Date.now(), { addSuffix: true })}</p>

Choose a reason for hiding this comment

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

Nice way of displaying the date!

Comment on lines 4 to 28
export const Hearts = ({ thought, fetchThoughts }) => {
const onHeartCountIncreaseButtonClick = () => {
const options = {
method: 'POST'
}
console.log('options', options)

fetch(`https://happy-thoughts-ux7hkzgmwa-uc.a.run.app/thoughts/${thought._id}/like`, options)
.then((res) => res.json())
.then((data) => console.log(data))
.catch((error) => console.log(error))
.finally(() => fetchThoughts())
console.log('heart count increase')
}

return (
// eslint-disable-next-line react/jsx-no-comment-textnodes
<div>
<div className="heartsSection">
<button className="heartButton" onClick={onHeartCountIncreaseButtonClick} type="button">❤️</button>
<p className="heartCount">x <span className="heartCountNumber">{thought.hearts}</span></p>
</div>
</div>
)
}

Choose a reason for hiding this comment

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

good structure and clean code 👍

Comment on lines +12 to +17
<div className="characterCount">{eachThought.length < 5 || eachThought.length > 140 ? (
<p className="redText">{eachThought.length}/140</p>
) : (
<p className="normalText">{eachThought.length}/140</p>
)}
</div>

Choose a reason for hiding this comment

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

Nice with the change depending on the characters, another way of getting the className to change with less code could be:
<p className={eachThought.length < 5 || eachThought.length > 140 ? 'redText' : 'normalText'}>{eachThought.length} / 140</p>

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