From b2205c4d178adc0468025b5701377e30e935fa81 Mon Sep 17 00:00:00 2001 From: Liubov Dav Date: Sat, 14 Dec 2024 21:03:24 -0800 Subject: [PATCH 1/6] Implemented wave-01 --- src/App.jsx | 2 ++ src/components/ChatEntry.jsx | 9 +++++---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/App.jsx b/src/App.jsx index 14a7f684d..6fdde8e82 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -1,4 +1,5 @@ import './App.css'; +import ChatEntry from './components/ChatEntry'; const App = () => { return ( @@ -7,6 +8,7 @@ const App = () => {

Application title

+ {/* Wave 01: Render one ChatEntry component Wave 02: Render ChatLog component */}
diff --git a/src/components/ChatEntry.jsx b/src/components/ChatEntry.jsx index 15c56f96b..96d31a684 100644 --- a/src/components/ChatEntry.jsx +++ b/src/components/ChatEntry.jsx @@ -1,12 +1,13 @@ import './ChatEntry.css'; +import TimeStamp from './TimeStamp.jsx'; -const ChatEntry = () => { +const ChatEntry = (props) => { return (
-

Replace with name of sender

+

{props.sender}

-

Replace with body of ChatEntry

-

Replace with TimeStamp component

+

{props.body}

+

From 2542b4b6a9d967d3e938141f020d2d2a208fcdee Mon Sep 17 00:00:00 2001 From: Liubov Dav Date: Sat, 14 Dec 2024 22:11:45 -0800 Subject: [PATCH 2/6] Implemented wave-02 --- src/App.jsx | 9 ++++----- src/components/ChatLog.jsx | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+), 5 deletions(-) create mode 100644 src/components/ChatLog.jsx diff --git a/src/App.jsx b/src/App.jsx index 6fdde8e82..987910d77 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -1,16 +1,15 @@ import './App.css'; -import ChatEntry from './components/ChatEntry'; +import ChatLog from './components/ChatLog'; +import chatLogData from '../src/data/messages.json'; const App = () => { return (
-

Application title

+

Chat between Vladimir and Estragon

0 🤍s

- - {/* Wave 01: Render one ChatEntry component - Wave 02: Render ChatLog component */} +
); diff --git a/src/components/ChatLog.jsx b/src/components/ChatLog.jsx new file mode 100644 index 000000000..0b6d35b32 --- /dev/null +++ b/src/components/ChatLog.jsx @@ -0,0 +1,18 @@ +import ChatEntry from "./ChatEntry"; + +const ChatLog = (props) => { + + const chatEntryComponents = props.entries.map(chatEntry => { + return ( + + ); + }); + + return ( + <> + {chatEntryComponents} + + ); +}; + +export default ChatLog; From cb0a381217dbe00435e6cac7e5e7e232b4df117c Mon Sep 17 00:00:00 2001 From: Liubov Dav Date: Sun, 15 Dec 2024 18:56:50 -0800 Subject: [PATCH 3/6] Added id, key, propTypes --- src/App.jsx | 2 +- src/components/ChatEntry.jsx | 10 +++++++--- src/components/ChatLog.jsx | 33 +++++++++++++++++++++++---------- 3 files changed, 31 insertions(+), 14 deletions(-) diff --git a/src/App.jsx b/src/App.jsx index 987910d77..16ff29588 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -6,7 +6,7 @@ const App = () => { return (
-

Chat between Vladimir and Estragon

0 🤍s

+

Chat between Vladimir and Estragon

0 ❤️s

diff --git a/src/components/ChatEntry.jsx b/src/components/ChatEntry.jsx index 96d31a684..d20d66c94 100644 --- a/src/components/ChatEntry.jsx +++ b/src/components/ChatEntry.jsx @@ -1,21 +1,25 @@ import './ChatEntry.css'; import TimeStamp from './TimeStamp.jsx'; +import PropTypes from 'prop-types'; const ChatEntry = (props) => { return ( -
+

{props.sender}

{props.body}

- +
); }; ChatEntry.propTypes = { - // Fill with correct proptypes + id: PropTypes.number.isRequired, + sender: PropTypes.string.isRequired, + body: PropTypes.string.isRequired, + timeStamp: PropTypes.string.isRequired }; export default ChatEntry; diff --git a/src/components/ChatLog.jsx b/src/components/ChatLog.jsx index 0b6d35b32..63c88e001 100644 --- a/src/components/ChatLog.jsx +++ b/src/components/ChatLog.jsx @@ -1,18 +1,31 @@ import ChatEntry from "./ChatEntry"; +import PropTypes from "prop-types"; const ChatLog = (props) => { - - const chatEntryComponents = props.entries.map(chatEntry => { - return ( - - ); - }); - + const chatEntryComponents = props.entries.map(chatEntry => { return ( - <> - {chatEntryComponents} - + ); + }); + + return <>{chatEntryComponents}; +}; + +ChatLog.propTypes = { + entries: PropTypes.arrayOf( + PropTypes.shape({ + id: PropTypes.number.isRequired, + sender: PropTypes.string.isRequired, + body: PropTypes.string.isRequired, + timeStamp: PropTypes.string.isRequired, + }) + ), }; export default ChatLog; From 65cd2f1daf65e85341c9f4f3751f49ebb49cef3f Mon Sep 17 00:00:00 2001 From: Liubov Dav Date: Sun, 15 Dec 2024 22:34:26 -0800 Subject: [PATCH 4/6] Implemented wave-03 --- src/App.jsx | 33 ++++++++++++++++++++++++++++++--- src/components/ChatEntry.jsx | 14 ++++++++++++-- src/components/ChatLog.jsx | 8 ++++++-- 3 files changed, 48 insertions(+), 7 deletions(-) diff --git a/src/App.jsx b/src/App.jsx index 16ff29588..bbb4989c6 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -1,15 +1,42 @@ import './App.css'; import ChatLog from './components/ChatLog'; -import chatLogData from '../src/data/messages.json'; +import chatLogDataFromFile from '../src/data/messages.json'; +import { useState } from 'react'; const App = () => { + const [likesCount, setLikesCount] = useState(0); + + const [chatLogData, setChatLogData] = useState(chatLogDataFromFile); + + const toggleChatEntryLiked = (chatEntryId) => { + const chatLogDataAfterToggle = chatLogData.map(chatEntry => { + if (chatEntry.id === chatEntryId) { + if (chatEntry.liked) { + setLikesCount(likesCount - 1); + } else { + setLikesCount(likesCount + 1); + } + return { ...chatEntry, liked: !chatEntry.liked }; + } else { + return chatEntry; + } + }); + + setChatLogData(chatLogDataAfterToggle); + }; + return (
-

Chat between Vladimir and Estragon

0 ❤️s

+

+ Chat between Vladimir and Estragon +
+
+ {likesCount} ❤️s +

- +
); diff --git a/src/components/ChatEntry.jsx b/src/components/ChatEntry.jsx index d20d66c94..8d1fc4367 100644 --- a/src/components/ChatEntry.jsx +++ b/src/components/ChatEntry.jsx @@ -1,15 +1,23 @@ import './ChatEntry.css'; import TimeStamp from './TimeStamp.jsx'; import PropTypes from 'prop-types'; +import { useState } from 'react'; const ChatEntry = (props) => { + const [isLiked, setIsLiked] = useState(props.liked); + + const likeButtonClicked = () => { + setIsLiked(!props.liked); + props.onToggleLiked(props.id); + }; + return (

{props.sender}

{props.body}

- +
); @@ -19,7 +27,9 @@ ChatEntry.propTypes = { id: PropTypes.number.isRequired, sender: PropTypes.string.isRequired, body: PropTypes.string.isRequired, - timeStamp: PropTypes.string.isRequired + timeStamp: PropTypes.string.isRequired, + liked: PropTypes.bool.isRequired, + onToggleLiked: PropTypes.func.isRequired }; export default ChatEntry; diff --git a/src/components/ChatLog.jsx b/src/components/ChatLog.jsx index 63c88e001..0f9ca6492 100644 --- a/src/components/ChatLog.jsx +++ b/src/components/ChatLog.jsx @@ -1,5 +1,5 @@ -import ChatEntry from "./ChatEntry"; -import PropTypes from "prop-types"; +import ChatEntry from './ChatEntry'; +import PropTypes from 'prop-types'; const ChatLog = (props) => { const chatEntryComponents = props.entries.map(chatEntry => { @@ -10,6 +10,8 @@ const ChatLog = (props) => { sender={chatEntry.sender} body={chatEntry.body} timeStamp={chatEntry.timeStamp} + liked={chatEntry.liked} + onToggleLiked={props.onToggleChatEntryLiked} > ); }); @@ -24,8 +26,10 @@ ChatLog.propTypes = { sender: PropTypes.string.isRequired, body: PropTypes.string.isRequired, timeStamp: PropTypes.string.isRequired, + liked: PropTypes.bool.isRequired }) ), + onToggleChatEntryLiked: PropTypes.func.isRequired }; export default ChatLog; From 358bbba146d7419ae8530e85789814128287836c Mon Sep 17 00:00:00 2001 From: Liubov Dav Date: Sun, 15 Dec 2024 22:59:12 -0800 Subject: [PATCH 5/6] Implemented local-remote --- src/components/ChatEntry.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/ChatEntry.jsx b/src/components/ChatEntry.jsx index 8d1fc4367..8deb9a28c 100644 --- a/src/components/ChatEntry.jsx +++ b/src/components/ChatEntry.jsx @@ -12,7 +12,7 @@ const ChatEntry = (props) => { }; return ( -
+

{props.sender}

{props.body}

From d9eb229512905be91216a5c3861865f94e5fae18 Mon Sep 17 00:00:00 2001 From: Liubov Dav Date: Mon, 16 Dec 2024 11:37:40 -0800 Subject: [PATCH 6/6] Changed is required --- src/components/ChatEntry.jsx | 2 +- src/components/ChatLog.jsx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/ChatEntry.jsx b/src/components/ChatEntry.jsx index 8deb9a28c..ce00a5aac 100644 --- a/src/components/ChatEntry.jsx +++ b/src/components/ChatEntry.jsx @@ -29,7 +29,7 @@ ChatEntry.propTypes = { body: PropTypes.string.isRequired, timeStamp: PropTypes.string.isRequired, liked: PropTypes.bool.isRequired, - onToggleLiked: PropTypes.func.isRequired + onToggleLiked: PropTypes.func }; export default ChatEntry; diff --git a/src/components/ChatLog.jsx b/src/components/ChatLog.jsx index 0f9ca6492..1a1d762d5 100644 --- a/src/components/ChatLog.jsx +++ b/src/components/ChatLog.jsx @@ -29,7 +29,7 @@ ChatLog.propTypes = { liked: PropTypes.bool.isRequired }) ), - onToggleChatEntryLiked: PropTypes.func.isRequired + onToggleChatEntryLiked: PropTypes.func }; export default ChatLog;