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
3 changes: 3 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"singleQuote": true
}
29 changes: 18 additions & 11 deletions src/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -26,49 +26,56 @@
display: inline-block;
}

#App header h2 {
background-color: honeydew;
color: #222;
display: block;
font-size: x-large;
}

#App header section {
background-color: #e0ffff;
background-color: #d50e68;
}

#App .widget {
display: inline-block;
line-height: 0.5em;
border-radius: 10px;
color: black;
font-size:0.8em;
font-size: 0.8em;
padding-left: 1em;
padding-right: 1em;
}

#App #heartWidget {
font-size: 1.5em;
margin: 1em
margin: 1em;
}

#App span {
display: inline-block
display: inline-block;
}

.red {
color: #b22222
color: #b22222;
}

.orange {
color: #e6ac00
color: #e6ac00;
}

.yellow {
color: #e6e600
color: #e6e600;
}

.green {
color: green
color: green;
}

.blue {
color: blue
color: blue;
}

.purple {
color: purple
}
color: purple;
}
40 changes: 38 additions & 2 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,52 @@
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 chatData = chatMessages;

const [entryData, setEntryData] = useState(chatData);

const updateEntryData = (updatedEntry) => {
const entries = entryData.map((entry) => {
if (entry.id === updatedEntry.id) {
return updatedEntry;
} else {
return entry;
}
});

setEntryData(entries);
};

const [likeCount, setLikeCount] = useState(0);

const updateLikes = (isLiked) => {
if (isLiked) {
setLikeCount((prevState) => prevState + 1);
} else {
setLikeCount((prevState) => prevState - 1);
}
};

return (
<div id="App">
<header>
<h1>Application title</h1>
<h1>
Chat between {chatData[0].sender} and {chatData[1].sender}
</h1>
<h2> {likeCount} ❤️s </h2>
</header>
<main>
{/* Wave 01: Render one ChatEntry component
Wave 02: Render ChatLog component */}

<ChatLog
entries={entryData}
onUpdateEntryData={updateEntryData}
updateLikes={updateLikes}
/>
</main>
</div>
);
Expand Down
16 changes: 8 additions & 8 deletions src/components/ChatEntry.css
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
button {
background: none;
color: inherit;
border: none;
padding: 10px;
font: inherit;
cursor: pointer;
outline: inherit;
color: inherit;
border: none;
padding: 10px;
font: inherit;
cursor: pointer;
outline: inherit;
}

.chat-entry {
Expand Down Expand Up @@ -77,7 +77,7 @@ button {
}

.chat-entry.remote .entry-bubble {
background-color: #e0ffff;
background-color: #a4f9ad;
margin-left: auto;
margin-right: 0;
}
Expand All @@ -97,4 +97,4 @@ button {

.chat-entry.remote .entry-bubble:hover::before {
background-color: #a9f6f6;
}
}
41 changes: 34 additions & 7 deletions src/components/ChatEntry.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,49 @@
import React from 'react';
import React, { useState } from 'react';
import './ChatEntry.css';
import PropTypes from 'prop-types';
import TimeStamp from './TimeStamp';

const ChatEntry = (props) => {
const onLikeButtonClick = () => {
const updateEntry = {
id: props.id,
sender: props.sender,
body: props.body,
timeStamp: props.timeStamp,
liked: !props.liked,
};
props.onUpdateEntryData(updateEntry);
props.updateLikes(!props.liked);
};

const likeHeart = props.liked ? '❤️' : '🤍';

const chatClass =
props.sender === 'Vladimir' ? 'chat-entry local' : 'chat-entry remote';

return (
<div className="chat-entry local">
<h2 className="entry-name">Replace with name of sender</h2>
<div className={chatClass}>
<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">
{' '}
<TimeStamp time={props.timeStamp} />{' '}
</p>
<button className="like" onClick={onLikeButtonClick}>
{likeHeart}
</button>
</section>
</div>
);
};

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

export default ChatEntry;
3 changes: 2 additions & 1 deletion src/components/ChatLog.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.chat-log {
margin: auto;
max-width: 50rem;
max-width: 5rem;
color: darkgreen;
}
36 changes: 36 additions & 0 deletions src/components/ChatLog.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import React from 'react';
import ChatEntry from './ChatEntry';
import PropTypes from 'prop-types';

const ChatLog = ({ entries, onUpdateEntryData, updateLikes }) => {
return (
<div className="chat-log">
{entries.map((entry) => (
<ChatEntry
id={entry.id}
sender={entry.sender}
body={entry.body}
timeStamp={entry.timeStamp}
key={entry.id}
liked={entry.liked}
onUpdateEntryData={onUpdateEntryData}
updateLikes={updateLikes}
/>
))}
</div>
);
};

ChatLog.propTypes = {
entries: PropTypes.arrayOf(
PropTypes.shape({
id: PropTypes.number.isRequired,
sender: PropTypes.string.isRequired,
body: PropTypes.string.isRequired,
liked: PropTypes.bool
})),
onUpdateEntryData: PropTypes.func.isRequired,

};

export default ChatLog;