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

Yifan-Happy-Thought-Post #70

Open
wants to merge 30 commits into
base: main
Choose a base branch
from
Open

Yifan-Happy-Thought-Post #70

wants to merge 30 commits into from

Conversation

Yifan-858
Copy link

Netlify link

https://yifan-happy-thought-post.netlify.app/

Collaborators

[yifan-858]

Copy link

@trista1987 trista1987 left a comment

Choose a reason for hiding this comment

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

Very impressive. I learned SCSS and use localStorage from your code. Like the way how did you work on liked button and message length. Good job!

return (
<div className="heart-display">
<button
className={`heart-icon ${isLiked && "liked-icon"}`}

Choose a reason for hiding this comment

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

smart girl! clear and simple way to make the liked-icon

export const HeartDisplay = ({ post, handleUpdate, handlePlusHeartCount }) => {
const [isLiked, setIsLiked] = useState(
localStorage.getItem(`liked-${post._id}`)
);

Choose a reason for hiding this comment

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

I don't really understand liked-${post._id}, what is 'liked - ' for?

Copy link
Author

Choose a reason for hiding this comment

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

Hi Trista!

I will try to explain as well as I can based on what I read for this project!

liked-${post._id}, this whole piece, is the key for the key-value pair you set for the localStorage object. 'liked - ' is a part of the key name. And '${post._id}' makes it more dynamic.

For example, the localStorage you saved could look like this: 'liked-12321231(whatever id): true'. You can also name it as you prefer, for example clicked-${post._id} or heartBtn-${post._id}.

Once you successfully set your value to the localStorage by using localStorage.setItem(), you can check it in inspect -> Application -> Local storage -> click the down arrow -> click the URL, then you will see a list with the key-value pairs.

Choose a reason for hiding this comment

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

Hey thank you! Now I understand everything, no idea why yesterday I was confused

.liked-icon {
@extend .heart-icon;
background-color: $active-btn-color;
}

Choose a reason for hiding this comment

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

good to know @extend

});

if (!response.ok) {
console.log("Post failed");

Choose a reason for hiding this comment

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

can we use error instead of condole.log here?

Copy link
Author

Choose a reason for hiding this comment

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

Seems like
"if (!response.ok) {
throw new Error("Post failed");
}" works as the same.

className={
isMaxLengthExceeded ? "character-count-max" : "character-count"
}
>

Choose a reason for hiding this comment

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

what are "textarea-error-effect" and "character-count-max" for?

Choose a reason for hiding this comment

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

got the answer in SCSS 😊

console.log("dependency rendered");
const plusHeartCount = localStorage.getItem("shared-heart-count")
? parseInt(localStorage.getItem("shared-heart-count"), 10) + 1
: "1";

Choose a reason for hiding this comment

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

do we alwayt put the number 10? or it depends on the situation

Copy link
Author

Choose a reason for hiding this comment

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

Number 10 represents decimal. The localStorage object stores data as strings. So when you try to get data from localStorage, the data needs to be converted into numbers again by using parseInt(). And 10 here is the second parameter you pass into parseInt() to make the result a decimal number.

It seems like you can skip 10 in JavaScript because the default behavior is returning a decimal number.

setTimeago(displayTimeAgo);
}, [post.createdAt]);

return <p className="post-time">{timeAgo}</p>;

Choose a reason for hiding this comment

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

for the time, you can also use ```
const timeFormat = date => {
const currentTime = new Date (date)
return moment (currentTime).fromNow()
}

Copy link
Author

Choose a reason for hiding this comment

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

Cool! Thank you for the new method will look into it!

Copy link
Contributor

@dzc1 dzc1 left a comment

Choose a reason for hiding this comment

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

Amazing work Yifan, loving to see the destructuring of logic + comps on your 1App.jsx` file as well as your subtle animation upon creating a new thought.

Keep up the great work!

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.

3 participants