diff --git a/src/App.css b/src/App.css index d97beb4e6..2675e8e24 100644 --- a/src/App.css +++ b/src/App.css @@ -49,6 +49,15 @@ display: inline-block } +.colorchoice button{ + border-radius: 20px; + margin: 5px; +} + +.colorchoice button:hover{ + box-shadow: 0px 0px 5px 0px rgba(0,0,0,0.75); +} + .red { color: #b22222 } @@ -58,17 +67,55 @@ } .yellow { - color: #e6e600 + color: #e6e600; } .green { - color: green + color: green; } .blue { - color: blue + color: blue; } .purple { - color: purple + color: purple; +} + +.black{ + color:black; +} + +.ribbon{ + display: flex; + flex-direction: row; + justify-content: space-evenly; +} + +.button-red{ + background-color: red; +} + +.button-orange { + background-color: #e6ac00 +} + +.button-yellow { + background-color: #e6e600; +} + +.button-green { + background-color: green; +} + +.button-blue { + background-color: blue; +} + +.button-purple { + background-color: purple; +} + +.sender{ + color:black; } \ No newline at end of file diff --git a/src/App.js b/src/App.js index c10859093..55d029238 100644 --- a/src/App.js +++ b/src/App.js @@ -1,16 +1,61 @@ -import React from 'react'; +import React, {useState} from 'react'; import './App.css'; import chatMessages from './data/messages.json'; +import ChatLog from './components/ChatLog'; +import ColorChoice from './components/ColorChoice'; const App = () => { + const [messages, setMessages] = useState(chatMessages); + const [localColor, setLocalColor] = useState('black'); + const [remoteColor, setRemoteColor] = useState('black'); + const local = 'Vladimir'; + const remote = 'Estragon'; + + const updateColor = (origin, updatedcolor)=>{ + if (origin === remote){ + setRemoteColor(updatedcolor); + }else{ + setLocalColor(updatedcolor); + } + } + + + const updateLike = (updatedmessage)=>{ + const updatedmessages = messages.map(message =>{ + if (message.id === updatedmessage.id){ + return updatedmessage; + + }else{ + return message; + } + }) + setMessages(updatedmessages); + } + + const getHeartCount = () =>{ + let heartCount = 0; + for (const message of messages){ + if (message.liked){ + heartCount ++; + } + } + return heartCount; + } + return (
-

Application title

+

Chat between {local} and {remote}

+
+ + {getHeartCount()} ❤️s + +
- {/* Wave 01: Render one ChatEntry component - Wave 02: Render ChatLog component */} + +
); diff --git a/src/components/ChatEntry.js b/src/components/ChatEntry.js index b92f0b7b2..2d858abc7 100644 --- a/src/components/ChatEntry.js +++ b/src/components/ChatEntry.js @@ -1,22 +1,47 @@ -import React from 'react'; +import React, { useState } from 'react'; import './ChatEntry.css'; import PropTypes from 'prop-types'; +import { DateTime } from 'luxon'; +import TimeStamp from './TimeStamp'; const ChatEntry = (props) => { - return ( -
-

Replace with name of sender

-
-

Replace with body of ChatEntry

-

Replace with TimeStamp component

- -
-
- ); -}; + const heart = props.liked ? '❤️':'🤍'; + let origin = 'local'; + let fontColor = props.colorForLocal; + if (props.sender != props.local){ + origin = 'remote'; + fontColor = props.colorForRemote; + } + + + const updateLike = () =>{ + const updatedmessage = { + id:props.id, + sender:props.sender, + body:props.body, + timeStamp:props.timeStamp, + liked:!props.liked, + } + props.onupdate(updatedmessage) + }; + return ( +
+

{props.sender}

+
+

{props.body}

+

+ +
+
+ ); + }; ChatEntry.propTypes = { - //Fill with correct proptypes + id: PropTypes.number, + sender:PropTypes.string, + body:PropTypes.string, + timeStamp:PropTypes.string, + liked:PropTypes.bool, }; export default ChatEntry; diff --git a/src/components/ChatLog.js b/src/components/ChatLog.js new file mode 100644 index 000000000..04a90d7ac --- /dev/null +++ b/src/components/ChatLog.js @@ -0,0 +1,35 @@ +import React from 'react'; +import './ChatLog.css'; +import ChatEntry from './ChatEntry'; +import PropTypes from 'prop-types'; + +const ChatLog = ({entries, onupdate, local, colorForLocal, colorForRemote})=>{ + + + const chatentryComponents = entries.map((message, index)=>{ + return ; + }); + + return
{chatentryComponents}
; +} + +ChatLog.propTypes= { + entries: PropTypes.arrayOf( + PropTypes.shape({ + id: PropTypes.number, + sender: PropTypes.string, + body: PropTypes.string, + timeStamp:PropTypes.string, + liked:PropTypes.bool, + }) + ), + onupdate: PropTypes.func, + local: PropTypes.string, + colorForLocal:PropTypes.string, + colorForRemote:PropTypes.string, +}; +export default ChatLog; \ No newline at end of file diff --git a/src/components/ColorChoice.css b/src/components/ColorChoice.css new file mode 100644 index 000000000..139597f9c --- /dev/null +++ b/src/components/ColorChoice.css @@ -0,0 +1,2 @@ + + diff --git a/src/components/ColorChoice.js b/src/components/ColorChoice.js new file mode 100644 index 000000000..03e0b90c4 --- /dev/null +++ b/src/components/ColorChoice.js @@ -0,0 +1,30 @@ +import React from 'react'; +import './ColorChoice.css'; +import PropTypes from 'prop-types'; + + +const ColorChoice = ({color, origin, colorupdate})=>{ + + return( +
+

{origin}'s color

+
+ + + + + + +
+
+ ); +}; + +ColorChoice.propTypes ={ + color: PropTypes.string, + origin: PropTypes.string, + colorupdate: PropTypes.func, +} + + +export default ColorChoice; \ No newline at end of file