-
Notifications
You must be signed in to change notification settings - Fork 40
DragonFly Dennif Portilla #26
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| name: Deploy | ||
|
|
||
| on: | ||
| push: | ||
| branches: | ||
| - main | ||
|
|
||
| jobs: | ||
| build: | ||
| name: Build | ||
| runs-on: ubuntu-latest | ||
|
|
||
| steps: | ||
| - name: Checkout repo | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Setup Node | ||
| uses: actions/setup-node@v4 | ||
|
|
||
| - name: Install dependencies | ||
| uses: bahmutov/npm-install@v1 | ||
|
|
||
| - name: Build project | ||
| run: npm run build | ||
|
|
||
| - name: Upload production-ready build files | ||
| uses: actions/upload-artifact@v4 | ||
| with: | ||
| name: production-files | ||
| path: ./dist | ||
|
|
||
| deploy: | ||
| name: Deploy | ||
| needs: build | ||
| runs-on: ubuntu-latest | ||
| if: github.ref == 'refs/heads/main' | ||
|
|
||
| steps: | ||
| - name: Download artifact | ||
| uses: actions/download-artifact@v4 | ||
| with: | ||
| name: production-files | ||
| path: ./dist | ||
|
|
||
| - name: Deploy to GitHub Pages | ||
| uses: peaceiris/actions-gh-pages@v4 | ||
| with: | ||
| github_token: ${{ secrets.GITHUB_TOKEN }} | ||
| publish_dir: ./dist |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,14 +1,32 @@ | ||
| import React, { useState } from "react"; | ||
| import './App.css'; | ||
| import ChatLog from './components/ChatLog'; | ||
| import chat from './data/messages.json'; | ||
|
|
||
| const App = () => { | ||
| const [chatMessages, setChatMessages] = useState(chat); | ||
|
|
||
| const toggleLike = (id) => { | ||
| const updatedMessages = chatMessages.map((entry) => { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice use of map here to both handle making a new list so that React sees the message data has changed, and make new data for the clicked message with its like status toggled. |
||
| if (entry.id === id) { | ||
| return { ...entry, liked: !entry.liked }; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We showed this approach in class, but technically, we're mixing a few responsibilities here. rather than this function needing to know how to change the liked status itself, we could move this update logic to a helper function. This would better mirror how we eventually update records when there's an API call involved. In this project, our messages are very simple objects, but if we had more involved operations, it could be worthwhile to create an actual class with methods to work with them, or at least have a set of dedicated helper functions to centralize any such mutation logic. |
||
| } else { | ||
| return entry; | ||
| } | ||
| }); | ||
| setChatMessages(updatedMessages); | ||
| }; | ||
|
|
||
| const totalLikes = chatMessages.filter((entry) => entry.liked).length; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Great idea to filter down the data to the liked messages and use the list length as the count! This approach works, but you'll typically see JS devs use const calculateTotalLikeCount = (chatData) => {
return chatData.reduce((acc, chat) => {
return chat.liked ? acc + 1 : acc;
}, 0);
}; |
||
|
|
||
| return ( | ||
| <div id="App"> | ||
| <header> | ||
| <h1>Application title</h1> | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. An element missing from your project is the header "Chat Between X and Y". Here you have "Application Title". @dniph How would you create a header that reflects the screenshot below? It can be done by hardcoding the string in the Please respond to this comment with your answer, thank you!
|
||
| <p>{totalLikes} ❤️s</p> | ||
| </header> | ||
| <main> | ||
| {/* Wave 01: Render one ChatEntry component | ||
| Wave 02: Render ChatLog component */} | ||
| <ChatLog entries={chatMessages} onLikeToggle={toggleLike} /> | ||
| </main> | ||
| </div> | ||
| ); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,20 +1,34 @@ | ||
| import './ChatEntry.css'; | ||
| import PropTypes from 'prop-types'; | ||
| import TimeStamp from './TimeStamp'; | ||
|
|
||
| const ChatEntry = ({ id, sender, body, timeStamp, liked, onLikeToggle }) => { | ||
| // Función que se ejecuta al hacer clic en el botón del corazón | ||
| const handleLikeClick = () => { | ||
| onLikeToggle(id); | ||
| }; | ||
|
Comment on lines
+7
to
+9
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
|
|
||
| const ChatEntry = () => { | ||
| return ( | ||
| <div className="chat-entry local"> | ||
| <h2 className="entry-name">Replace with name of sender</h2> | ||
| <div className={`chat-entry ${sender === 'Vladimir' ? 'local' : 'remote'}`}> | ||
| <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> | ||
| <TimeStamp time={timeStamp} /> | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice job using the provided |
||
| <button className="like" onClick={handleLikeClick}> | ||
| {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, | ||
| onLikeToggle: PropTypes.func.isRequired, | ||
| }; | ||
|
|
||
| export default ChatEntry; | ||
| export default ChatEntry; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| import './ChatLog.css'; | ||
| import PropTypes from 'prop-types'; | ||
| import ChatEntry from './ChatEntry'; | ||
|
|
||
| const ChatLog = ({ entries, onLikeToggle }) => { | ||
| const ChatEntries = entries.map((entry) => { | ||
| return ( | ||
| <ChatEntry | ||
| key={entry.id} | ||
| id={entry.id} | ||
| sender={entry.sender} | ||
| body={entry.body} | ||
| timeStamp={entry.timeStamp} | ||
| liked={entry.liked} | ||
| onLikeToggle={onLikeToggle} | ||
| /> | ||
| ); | ||
| }); | ||
|
|
||
| return <div className='chat-log'>{ChatEntries}</div>; | ||
| }; | ||
|
|
||
| ChatLog.propTypes = { | ||
| entries: PropTypes.array.isRequired, | ||
| onLikeToggle: PropTypes.func.isRequired | ||
| }; | ||
|
|
||
| export default ChatLog; |

There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍