In this wave we will update the components to manage a like feature.
- Add behavior to heart button in
ChatEntry
so that when it is clicked it toggles from an empty heart (🤍) to a filled heart (❤️) and from a filled heart (❤️) to and empty heart (🤍). - Manage the click event and state of the chat entries such that when the like status of a chat message changes by clicking the heart button, it is tracked by the
App
such that theApp
reports the number of total messages that have been liked.- If the user has liked three messages,
3 ❤️s
will appear at the top of the screen.
- If the user has liked three messages,
Expand to see hints for implementing this feature
- We will now need to update the
ChatEntry
component to use theliked
field. - When we click a heart, the state of the
entries
will need to update in ourApp
so that it can report the number of likes (❤️s). - Consider implementing a helper function to calculate the number of likes (❤️s).
- Consider using a ternary to display a 🤍 or a ❤️ as needed.
The tests for this component are integration tests. They don't make assumptions about the implementation details of like feature. The tests verify the following functionality:
- When the user click on a 🤍 button it changes to a ❤️, and when the user clicks on a ❤️ it changes to a 🤍. This test also verifies that clicking on one
ChatEntry
's like button (🤍) doesn't change otherChatEntry
's buttons. - The correct number of filled hearts is displayed at the top of the screen.