-
Notifications
You must be signed in to change notification settings - Fork 434
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
base: master
Are you sure you want to change the base?
Happy Thoughts #434
Conversation
…changed some places where things are mounted
There was a problem hiding this 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. |
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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> |
There was a problem hiding this comment.
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!
code/src/components/Hearts.js
Outdated
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> | ||
) | ||
} |
There was a problem hiding this comment.
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 👍
<div className="characterCount">{eachThought.length < 5 || eachThought.length > 140 ? ( | ||
<p className="redText">{eachThought.length}/140</p> | ||
) : ( | ||
<p className="normalText">{eachThought.length}/140</p> | ||
)} | ||
</div> |
There was a problem hiding this comment.
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>
No description provided.