Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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
31 changes: 27 additions & 4 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,37 @@
import React from 'react';
import React, { useState } from 'react';
import './App.css';
import ChatEntry from './components/ChatEntry';
import ChatLog from './components/ChatLog';
import chatMessages from './data/messages.json';

const App = () => {
const [chatData, updateChatData] = useState(chatMessages);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice job bringing in useState

const likesChanged = (id) => {
const chats = chatData.map((chat) => {
if (chat.id === id) {
chat.liked = !chat.liked;
}
return chat;
});
updateChatData(chats);
};
return (
<div id="App">
<header>
<h1>Application title</h1>
<header id="App header">
<h1 id="App h1">Chat between</h1>
</header>
<main>
<main id="App main">
<div>
{
<ChatEntry
id={chatData[0].id}
sender={chatData[0].sender}
body={chatData[0].body}
timeStamp={chatData[0].timeStamp}
liked={chatData[0].liked}
/>
}
</div>
{/* Wave 01: Render one ChatEntry component
Wave 02: Render ChatLog component */}
</main>
Expand Down
21 changes: 14 additions & 7 deletions src/components/ChatEntry.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,29 @@
import React from 'react';
import './ChatEntry.css';
import PropTypes from 'prop-types';
import TimeStamp from './TimeStamp';

const ChatEntry = ({ id, sender, body, timeStamp, liked }) => {
const chatTime = <TimeStamp time={timeStamp} />;

const ChatEntry = (props) => {
return (
<div className="chat-entry local">
<h2 className="entry-name">Replace with name of sender</h2>
<div key={id} className="chat-entry local">
<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">{chatTime}</p>
<button className="like">{liked}🤍</button>
</section>
</div>
);
};

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

export default ChatEntry;