Skip to content
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

Diana S - C19 Kunzite #118

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
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
17 changes: 15 additions & 2 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,29 @@
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 [totalLikes, setTotalLikes] = useState(0);

const likeChangeHandler = (liked) => {
if (liked) {
setTotalLikes((prevTotal) => prevTotal + 1);
} else {
setTotalLikes((prevTotal) => prevTotal - 1);
}
};

return (
<div id="App">
<header>
<h1>Application title</h1>
<h1>Chat between Vladimir and Estragon</h1>
<p> {totalLikes} ❤️s</p>
</header>
<main>
{/* Wave 01: Render one ChatEntry component
Wave 02: Render ChatLog component */}
<ChatLog entries={chatMessages} onLikeChange={likeChangeHandler} />
</main>
</div>
);
Expand Down
33 changes: 27 additions & 6 deletions src/components/ChatEntry.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,43 @@
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 [liked, setLiked] = useState(false);

const likeClickHandler = () => {
setLiked((prevLiked) => !prevLiked);

props.onLikeChange(!liked);

};

const isLocal = props.sender === 'Vladimir';
const entryClass = `chat-entry ${isLocal ? 'local': 'remote'}`;

return (
<div className="chat-entry local">
<h2 className="entry-name">Replace with name of sender</h2>
<div className={entryClass}>
<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={likeClickHandler}>
{liked ? '❤️' : '🤍'}
</button>
</section>
</div>
);
};

ChatEntry.propTypes = {
//Fill with correct proptypes
sender: PropTypes.string.isRequired,
body: PropTypes.string.isRequired,
timeStamp: PropTypes.string.isRequired,
onLikeChange: PropTypes.func.isRequired,
};

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

const ChatLog = (props) => {
// console.log(props.onLikeChange)

const chatEntryComponents = props.entries.map((entry) => (
<ChatEntry
key={entry.id}
id={entry.id}
sender={entry.sender}
body={entry.body}
timeStamp={entry.timeStamp}
onLikeChange={props.onLikeChange}
/>
));

return (
<div>
<h1>Conversation</h1>
{chatEntryComponents}
</div>
);
};

ChatLog.propTypes = {
entries: PropTypes.array.isRequired,
onLikeChange: PropTypes.func.isRequired,
};

export default ChatLog;