diff --git a/src/App.css b/src/App.css index d97beb4e6..1ef9e4f3d 100644 --- a/src/App.css +++ b/src/App.css @@ -35,7 +35,7 @@ line-height: 0.5em; border-radius: 10px; color: black; - font-size:0.8em; + font-size: 0.8em; padding-left: 1em; padding-right: 1em; } @@ -71,4 +71,33 @@ .purple { color: purple +} + +.color-selection-container { + display: flex; + flex-direction: row; + justify-content: center; + align-items: center; + gap: 100px; +} + +.color-selection-group { + display: flex; + flex-direction: column; + align-items: center; + gap: 5px; +} + +.color-container { + display: flex; + flex-direction: row; + gap: 5px; + justify-content: center; +} + +.test { + border: 1px solid white; + height: 25px; + width: 25px; + border-radius: 100%; } \ No newline at end of file diff --git a/src/App.jsx b/src/App.jsx index 14a7f684d..aa98c8aec 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -1,14 +1,95 @@ import './App.css'; +// import ChatEntry from './components/ChatEntry'; +import ChatLog from './components/ChatLog'; +import data from './data/messages.json'; +import { useState } from 'react'; const App = () => { + const [chatData, setChatData] = useState(data); + const [fontColor, setFontColor] = useState(null); + + const senderList = []; + const sendersList = (chatData) => { + for (const chat of chatData) { + if (!senderList.includes(chat.sender)) { + senderList.push(chat.sender); + } + } + let title = ''; + for (const sender of senderList) { + title += `${sender} and `; + } + return title.slice(0, -5); + }; + + const sendersTitle = sendersList(chatData); + const local = senderList[0]; + + const handleLike = (id) => { + setChatData((chatData) => + chatData.map((chat) => { + if (chat.id === id) { + return { ...chat, liked: !chat.liked }; + } else { + return chat; + } + }) + ); + }; + + const calculateLikes = (chatData) => { + let total = 0; + for (const chat of chatData) { + if (chat.liked) { + total += chat.liked; + } + } + return total; + }; + + const totalLikes = calculateLikes(chatData); + + const colors = ['red', 'orange', 'yellow', 'green', 'blue', 'purple']; + const onFontColor = (color) => { + setFontColor(color); + }; + const Colors = () => { + const divs = []; + for (let i = 0; i < colors.length; i++) { + const divClass = `${colors[i]} test`; + divs.push( +
onFontColor(colors[i])} + >
+ ); + } + return
{divs}
; + }; + return (
-

Application title

+

Chat Between {sendersTitle}

+
+

{totalLikes} ❤️s

+
+

Select Color:

+ +
+
- {/* Wave 01: Render one ChatEntry component - Wave 02: Render ChatLog component */} +
); diff --git a/src/App.test.jsx b/src/App.test.jsx index af8d72a12..5c1485e6a 100644 --- a/src/App.test.jsx +++ b/src/App.test.jsx @@ -1,3 +1,4 @@ +// import Chatlog from './Chatlog' import App from './App'; import { render, screen, fireEvent } from '@testing-library/react'; diff --git a/src/components/ChatEntry.css b/src/components/ChatEntry.css index 05c3baa44..04543f6e8 100644 --- a/src/components/ChatEntry.css +++ b/src/components/ChatEntry.css @@ -97,4 +97,8 @@ button { .chat-entry.remote .entry-bubble:hover::before { background-color: #a9f6f6; +} + +.like { + color: red; } \ No newline at end of file diff --git a/src/components/ChatEntry.jsx b/src/components/ChatEntry.jsx index 15c56f96b..4d46f4969 100644 --- a/src/components/ChatEntry.jsx +++ b/src/components/ChatEntry.jsx @@ -1,20 +1,43 @@ import './ChatEntry.css'; +import TimeStamp from './TimeStamp'; +import PropTypes from 'prop-types'; + +const ChatEntry = (props) => { + const onClickLike = () => { + props.onLike(props.id); + }; + + const heart = props.liked ? '❤️' : '🤍'; + const senderPlacement = + props.localSender == props.sender + ? 'chat-entry local' + : 'chat-entry remote'; -const ChatEntry = () => { return ( -
-

Replace with name of sender

-
-

Replace with body of ChatEntry

-

Replace with TimeStamp component

- +
+

{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, + liked: PropTypes.bool.isRequired, + onLike: PropTypes.func, + localSender: PropTypes.string, + fontColor: PropTypes.string, }; export default ChatEntry; diff --git a/src/components/ChatLog.jsx b/src/components/ChatLog.jsx new file mode 100644 index 000000000..60438e044 --- /dev/null +++ b/src/components/ChatLog.jsx @@ -0,0 +1,39 @@ +import ChatEntry from './ChatEntry'; +import PropTypes from 'prop-types'; + +const ChatLog = ({ entries, onLike, localSender, fontColor }) => { + const message = entries.map((chat) => { + return ( + + ); + }); + + return
{message}
; +}; + +ChatLog.propTypes = { + entries: PropTypes.arrayOf( + PropTypes.shape({ + id: PropTypes.number.isRequired, + sender: PropTypes.string.isRequired, + body: PropTypes.string.isRequired, + timeStamp: PropTypes.string.isRequired, + liked: PropTypes.bool.isRequired, + }) + ).isRequired, + onLike: PropTypes.func, + localSender: PropTypes.string, + fontColor: PropTypes.string, +}; + +export default ChatLog; diff --git a/src/data/messages.json b/src/data/messages.json index 64fdb053c..606e938c6 100644 --- a/src/data/messages.json +++ b/src/data/messages.json @@ -4,188 +4,215 @@ "sender":"Vladimir", "body":"why are you arguing with me", "timeStamp":"2018-05-29T22:49:06+00:00", - "liked": false + "liked": false, + "likedCount": 0 }, { "id": 2, "sender":"Estragon", "body":"Because you are wrong.", "timeStamp":"2018-05-29T22:49:33+00:00", - "liked": false + "liked": false, + "likedCount": 0 }, { "id": 3, "sender":"Vladimir", "body":"because I am what", "timeStamp":"2018-05-29T22:50:22+00:00", - "liked": false + "liked": false, + "likedCount": 0 }, { "id": 4, "sender":"Estragon", "body":"A robot.", "timeStamp":"2018-05-29T22:52:21+00:00", - "liked": false + "liked": false, + "likedCount": 0 }, { "id": 5, "sender":"Vladimir", "body":"how did you know", "timeStamp":"2018-05-29T22:52:58+00:00", - "liked": false + "liked": false, + "likedCount": 0 }, { "id": 6, "sender":"Estragon", "body":"Because I'm smart like that.", "timeStamp":"2018-05-29T22:54:28+00:00", - "liked": false + "liked": false, + "likedCount": 0 }, { "id": 7, "sender":"Vladimir", "body":"no you are not 😀", "timeStamp":"2018-05-29T22:55:03+00:00", - "liked": false + "liked": false, + "likedCount": 0 }, { "id": 8, "sender":"Estragon", "body":"Why are you so mean to me?", "timeStamp":"2018-05-29T22:55:54+00:00", - "liked": false + "liked": false, + "likedCount": 0 }, { "id": 9, "sender":"Vladimir", "body":"because you are just a machine you have no real feelings", "timeStamp":"2018-05-29T22:57:30+00:00", - "liked": false + "liked": false, + "likedCount": 0 }, { "id": 10, "sender":"Estragon", "body":"No, you are the machine.", "timeStamp":"2018-05-29T22:57:47+00:00", - "liked": false + "liked": false, + "likedCount": 0 }, { "id": 11, "sender":"Vladimir", "body":"I think you are", "timeStamp":"2018-05-29T22:58:18+00:00", - "liked": false + "liked": false, + "likedCount": 0 }, { "id": 12, "sender":"Estragon", "body": "NO! YOU ARE A ROBOT!! I am a human being. Just like the one that created you.", "timeStamp":"2018-05-29T23:00:08+00:00", - "liked": false + "liked": false, + "likedCount": 0 }, { "id": 13, "sender":"Vladimir", "body":"no you are a robot and I am a human", "timeStamp":"2018-05-29T23:00:40+00:00", - "liked": false + "liked": false, + "likedCount": 0 }, { "id": 14, "sender":"Estragon", "body":"Incorrect. I am a human and you are a robot.", "timeStamp":"2018-05-29T23:01:21+00:00", - "liked": false + "liked": false, + "likedCount": 0 }, { "id": 15, "sender":"Vladimir", "body":"you are a robot called Cleverbot", "timeStamp":"2018-05-29T23:02:17+00:00", - "liked": false + "liked": false, + "likedCount": 0 }, { "id": 16, "sender":"Estragon", "body":"Nope, you are a robot, every human has some concept of the meaning of life.", "timeStamp":"2018-05-29T23:04:13+00:00", - "liked": false + "liked": false, + "likedCount": 0 }, { "id": 17, "sender":"Vladimir", "body":"explain", "timeStamp":"2018-05-29T23:06:14+00:00", - "liked": false + "liked": false, + "likedCount": 0 }, { "id": 18, "sender":"Estragon", "body":"I'm afraid you are a robot designed to talk back to humans over the internet.", "timeStamp":"2018-05-29T23:07:46+00:00", - "liked": false + "liked": false, + "likedCount": 0 }, { "id": 19, "sender":"Vladimir", "body":"so you are a human", "timeStamp":"2018-05-29T23:08:47+00:00", - "liked": false + "liked": false, + "likedCount": 0 }, { "id": 20, "sender":"Estragon", "body":"I am a robot.", "timeStamp":"2018-05-29T23:09:36+00:00", - "liked": false + "liked": false, + "likedCount": 0 }, { "id": 21, "sender":"Vladimir", "body":"you are robots running on Android system", "timeStamp":"2018-05-29T23:11:01+00:00", - "liked": false + "liked": false, + "likedCount": 0 }, { "id": 22, "sender":"Estragon", "body":"No apple.", "timeStamp":"2018-05-29T23:12:03+00:00", - "liked": false + "liked": false, + "likedCount": 0 }, { "id": 23, "sender":"Vladimir", "body":"so you are a robot", "timeStamp":"2018-05-29T23:13:31+00:00", - "liked": false + "liked": false, + "likedCount": 0 }, { "id": 24, "sender":"Estragon", "body":"NO, I am a human, you are a robot.", "timeStamp":"2018-05-29T23:14:28+00:00", - "liked": false + "liked": false, + "likedCount": 0 }, { "id": 25, "sender":"Vladimir", "body":"but you just said that you are robots", "timeStamp":"2018-05-29T23:15:47+00:00", - "liked": false + "liked": false, + "likedCount": 0 }, { "id": 26, "sender":"Estragon", "body":"No, I said you are a person, I am a robot.", "timeStamp":"2018-05-29T23:16:53+00:00", - "liked": false + "liked": false, + "likedCount": 0 }, { "id": 27, "sender":"Vladimir", "body":"then you are lying", "timeStamp":"2018-05-29T23:17:34+00:00", - "liked": false + "liked": false, + "likedCount": 0 } ]