-
Notifications
You must be signed in to change notification settings - Fork 53
Happy thoughts project #44
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
base: main
Are you sure you want to change the base?
Conversation
| return saved ? JSON.parse(saved) : [] | ||
| }) | ||
|
|
||
| // fetch messages from API + interval polling |
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.
Maybe would be good to add some error handling in the fetch function, i.e. so that an error message is thrown if the API fetch has errors or fails!
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.
Fixed! Thanks for the advise!
| return () => clearInterval(intervalID) | ||
| },[]) | ||
|
|
||
| // Update local storage when likedPosts changes |
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 work with liked posts and local storage, works great!
|
|
||
| fetchMessages() // Initial fetch | ||
|
|
||
| // Set interval to fetch messages every 30 seconds |
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.
I wonder if i's maybe more efficient to use a state as dependency here (in the useEffect where you have the fetch function), instead of re-fetching every 30 seconds. In other words, so that it only re-fetches when it needs to, for example when there is an update which would be after you send a new message or like.
...But the it's maybe hard to know when there has been an update coming from someone posting from another app to the API :D. Well, just some reflections!
| localStorage.setItem("likedPosts", JSON.stringify(likedPosts)) | ||
| }, [likedPosts]) | ||
|
|
||
| // Post new message to API |
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.
Any reason you are using different API methods (async/await vs .then) between fetching the data, posting messages and likes? Just curious! :)
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.
No, just for practice:)
src/App.jsx
Outdated
| <p>Loading Happy Thoughts...</p> | ||
| </LoadingWrapper> | ||
| ) : ( | ||
| <ScrollArea> |
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.
Really nice with the scroll function for the messages!
gabriellaberko
left a comment
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.
Overall really great work with this project! Looks super nice and works as expected, including some stretch goal functionality.
Nice feature with the adding the liked posts to local storage, the scroll function, as well as the use of theme. Also nice to see that you used some TypeScript in the project too! Well done!
|
Thank you so much for your positive feed back!! |
Netlify link: https://happy-thoughts-25.netlify.app/