Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"@testing-library/react": "^11.1.0",
"@testing-library/user-event": "^12.1.10",
"luxon": "^2.4.0",
"moment": "^2.29.4",
"react": "^17.0.1",
"react-dom": "^17.0.1",
"react-scripts": "5.0.0"
Expand Down
14 changes: 10 additions & 4 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
import React from 'react';
import React, { useState } from 'react';
import './App.css';
import chatMessages from './data/messages.json';
import ChatLog from './components/ChatLog';

const App = () => {
const [likesCount, setLikesCount] = useState(0);

const updateLikesCount = (liked) => {
setLikesCount(likesCount + (liked ? 1 : -1));
};

return (
<div id="App">
<header>
<h1>Application title</h1>
<h1>{likesCount} ❤️s</h1>
</header>
<main>
{/* Wave 01: Render one ChatEntry component
Wave 02: Render ChatLog component */}
<ChatLog entries={chatMessages} onClickLike={updateLikesCount} />
</main>
</div>
);
Expand Down
25 changes: 20 additions & 5 deletions src/components/ChatEntry.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,37 @@
import React from 'react';
import React, { useState } from 'react';
import './ChatEntry.css';
import PropTypes from 'prop-types';
import moment from 'moment';

const ChatEntry = (props) => {
const [liked, setLiked] = useState(false);

const toggleLike = () => {
setLiked(!liked);
props.onClickLike(!liked);
};

return (
<div className="chat-entry local">
<h2 className="entry-name">Replace with name of sender</h2>
<h2 className="entry-name">{ props.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>{ props.body }</p>
<p className="entry-time">{ moment(props.timeStamp).fromNow() }</p>
<button className="like" onClick={toggleLike}>{ liked ? '❤️' : '🤍' }
</button>
</section>
</div>
);
};

ChatEntry.propTypes = {
//Fill with correct proptypes
id: PropTypes.number,
sender: PropTypes.string,
body: PropTypes.string,
timeStamp: PropTypes.string,
liked: PropTypes.bool,
onClickLike: PropTypes.func,
};

export default ChatEntry;
21 changes: 21 additions & 0 deletions src/components/ChatLog.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import React from 'react';
// import './ChatLog.css';
import ChatEntry from './ChatEntry';

const ChatLog = (props) => {
const chatComponents = props.entries.map((entry) => {
return (
<ChatEntry
key={entry.id}
sender={entry.sender}
body={entry.body}
timeStamp={entry.timeStamp}
onClickLike={props.onClickLike}
/>
);
});

return chatComponents;
};

export default ChatLog;
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7107,6 +7107,11 @@ mkdirp@~0.5.1:
dependencies:
minimist "^1.2.6"

moment@^2.29.4:
version "2.29.4"
resolved "https://registry.yarnpkg.com/moment/-/moment-2.29.4.tgz#3dbe052889fe7c1b2ed966fcb3a77328964ef108"
integrity sha512-5LC9SOxjSc2HF6vO2CyuTDNivEdoz2IvyJJGj6X8DJ0eFyfszE0QiEd+iXmBvUP3WHxSjFH/vIsA0EN00cgr8w==

ms@2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/ms/-/ms-2.0.0.tgz#5608aeadfc00be6c2901df5f9861788de0d597c8"
Expand Down