forked from AdaGold/react-chatlog
-
Notifications
You must be signed in to change notification settings - Fork 153
Ocelots - Megan Maple #136
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
Open
maple-megan333
wants to merge
8
commits into
Ada-C18:main
Choose a base branch
from
maple-megan333:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
6631f55
Set up complete and chatEntry functioning.
maple-megan333 0b023de
Chatlog test passing.
maple-megan333 f2494f3
updated log and chatentry to get liked from prop
maple-megan333 b1f43a9
liked or not return entry, in hex or str
maple-megan333 9f49d00
Use state and onclick
maple-megan333 e8b49c6
Debugged '$' for like
maple-megan333 dfc996c
passing all but last one
maple-megan333 c614433
Somehow managed to complete wave 3!
maple-megan333 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,53 +1,53 @@ | ||
| import React from 'react' | ||
| import App from './App' | ||
| import { render, screen, fireEvent } from '@testing-library/react' | ||
| import React from 'react'; | ||
| import App from './App'; | ||
| import { render, screen, fireEvent } from '@testing-library/react'; | ||
|
|
||
| describe('Wave 03: clicking like button and rendering App', () => { | ||
| test('that the correct number of likes is printed at the top', () => { | ||
| // Arrange | ||
| const { container } = render(<App />) | ||
| let buttons = container.querySelectorAll('button.like') | ||
| const { container } = render(<App />); | ||
| let buttons = container.querySelectorAll('button.like'); | ||
|
|
||
| // Act | ||
| fireEvent.click(buttons[0]) | ||
| fireEvent.click(buttons[1]) | ||
| fireEvent.click(buttons[10]) | ||
| fireEvent.click(buttons[0]); | ||
| fireEvent.click(buttons[1]); | ||
| fireEvent.click(buttons[10]); | ||
|
|
||
| // Assert | ||
| const countScreen = screen.getByText(/3 ❤️s/) | ||
| expect(countScreen).not.toBeNull() | ||
| }) | ||
| const countScreen = screen.getByText(/3 ❤️'s/); | ||
| expect(countScreen).not.toBeNull(); | ||
| }); | ||
|
|
||
| test('clicking button toggles heart and does not affect other buttons', () => { | ||
| // Arrange | ||
| const { container } = render(<App />) | ||
| const buttons = container.querySelectorAll('button.like') | ||
| const firstButton = buttons[0] | ||
| const lastButton = buttons[buttons.length - 1] | ||
| const { container } = render(<App />); | ||
| const buttons = container.querySelectorAll('button.like'); | ||
| const firstButton = buttons[0]; | ||
| const lastButton = buttons[buttons.length - 1]; | ||
|
|
||
| // Act-Assert | ||
|
|
||
| // click the first button | ||
| fireEvent.click(firstButton) | ||
| expect(firstButton.innerHTML).toEqual('❤️') | ||
| fireEvent.click(firstButton); | ||
| expect(firstButton.innerHTML).toEqual('❤️'); | ||
|
|
||
| // check that all other buttons haven't changed | ||
| for (let i = 1; i < buttons.length; i++) { | ||
| expect(buttons[i].innerHTML).toEqual('🤍') | ||
| expect(buttons[i].innerHTML).toEqual('🤍'); | ||
| } | ||
|
|
||
| // click the first button a few more times | ||
| fireEvent.click(firstButton) | ||
| expect(firstButton.innerHTML).toEqual('🤍') | ||
| fireEvent.click(firstButton) | ||
| expect(firstButton.innerHTML).toEqual('❤️') | ||
| fireEvent.click(firstButton) | ||
| expect(firstButton.innerHTML).toEqual('🤍') | ||
| fireEvent.click(firstButton); | ||
| expect(firstButton.innerHTML).toEqual('🤍'); | ||
| fireEvent.click(firstButton); | ||
| expect(firstButton.innerHTML).toEqual('❤️'); | ||
| fireEvent.click(firstButton); | ||
| expect(firstButton.innerHTML).toEqual('🤍'); | ||
|
|
||
| // click the last button a couple times | ||
| fireEvent.click(lastButton) | ||
| expect(lastButton.innerHTML).toEqual('❤️') | ||
| fireEvent.click(lastButton) | ||
| expect(lastButton.innerHTML).toEqual('🤍') | ||
| }) | ||
| }) | ||
| fireEvent.click(lastButton); | ||
| expect(lastButton.innerHTML).toEqual('❤️'); | ||
| fireEvent.click(lastButton); | ||
| expect(lastButton.innerHTML).toEqual('🤍'); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -97,4 +97,4 @@ button { | |
|
|
||
| .chat-entry.remote .entry-bubble:hover::before { | ||
| background-color: #a9f6f6; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,22 +1,53 @@ | ||
| import React from 'react'; | ||
| import React, { useState } from 'react'; | ||
| import './ChatEntry.css'; | ||
| import PropTypes from 'prop-types'; | ||
|
|
||
| const ChatEntry = (props) => { | ||
| //chatMessages.reduce((a, obj) => { | ||
| //return a + obj.liked; | ||
| //}, 0), | ||
|
|
||
| const timeDifference = (posted) => { | ||
| const difference = new Date( | ||
| new Date().getTime() - new Date('2018-05-18T22:12:03Z').getTime() | ||
| ); | ||
| if (difference.getFullYear() - 1970) { | ||
| return `${difference.getFullYear() - 1970} years ago`; | ||
| } | ||
| return difference.getMonth() - 1 | ||
| ? `${difference.getMonth() - 1} months ago` | ||
| : `${difference.getDate() - 1} days ago`; | ||
| }; | ||
|
|
||
| const ChatEntry = ({ id, sender, body, timeStamp, liked, updateChatData }) => { | ||
| const [isLiked, setLikes] = useState(liked); | ||
| const likedOrNot = isLiked ? '❤️' : '🤍'; | ||
| return ( | ||
| <div className="chat-entry local"> | ||
| <h2 className="entry-name">Replace with name of sender</h2> | ||
| <h2 className="entry-name">{sender}</h2> | ||
| <section className="entry-bubble"> | ||
| <p>Replace with body of ChatEntry</p> | ||
| <p className="entry-time">Replace with TimeStamp component</p> | ||
| <button className="like">🤍</button> | ||
| <p>{body}</p> | ||
| <p className="entry-time">{timeDifference(timeStamp)}</p> | ||
| <button | ||
| className="like" | ||
| onClick={() => { | ||
| updateChatData(id); | ||
| setLikes(!isLiked); | ||
| }} | ||
| > | ||
| {likedOrNot} | ||
| </button> | ||
| </section> | ||
| </div> | ||
| ); | ||
| }; | ||
|
|
||
| ChatEntry.propTypes = { | ||
| //Fill with correct proptypes | ||
| id: PropTypes.number, | ||
| sender: PropTypes.string.isRequired, | ||
| body: PropTypes.string.isRequired, | ||
| timeStamp: PropTypes.string.isRequired, | ||
| liked: PropTypes.bool.isRequired, | ||
| updateChatData: PropTypes.func.isRequired, | ||
| }; | ||
|
|
||
| export default ChatEntry; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| import React from 'react'; | ||
| import './ChatLog.css'; | ||
| import ChatEntry from './ChatEntry'; | ||
| import PropTypes from 'prop-types'; | ||
|
|
||
| const mapChats = (entries, updateChatData) => { | ||
| return entries.map((entry) => { | ||
| return ( | ||
| <ChatEntry | ||
| key={entry.id} | ||
| id={entry.id} | ||
| sender={entry.sender} | ||
| body={entry.body} | ||
| timeStamp={entry.timeStamp} | ||
| liked={entry.liked} | ||
| updateChatData={updateChatData} | ||
| /> | ||
| ); | ||
| }); | ||
| }; | ||
|
|
||
| const ChatLog = ({ entries, updateChatData }) => { | ||
| return ( | ||
| <article className="chat-log">{mapChats(entries, updateChatData)}</article> | ||
| ); | ||
| }; | ||
|
|
||
| ChatLog.propTypes = { | ||
| entries: PropTypes.arrayOf( | ||
| PropTypes.shape({ | ||
| id: PropTypes.number.isRequired, | ||
| sender: PropTypes.string.isRequired, | ||
| body: PropTypes.string.isRequired, | ||
| liked: PropTypes.bool.isRequired, | ||
| timeStamp: PropTypes.string.isRequired, | ||
| }) | ||
| ), | ||
| updateChatData: PropTypes.func.isRequired, | ||
| }; | ||
|
|
||
| export default ChatLog; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| import React from 'react'; | ||
|
|
||
| const likeCount = { | ||
| likes: 0, | ||
| }; | ||
|
|
||
| export default likeCount; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 use of propTypes to control variable requirements