diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 000000000..0542b110d --- /dev/null +++ b/.github/workflows/deploy.yml @@ -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 \ No newline at end of file diff --git a/src/App.jsx b/src/App.jsx index 14a7f684d..6de0c13f2 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -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) => { + if (entry.id === id) { + return { ...entry, liked: !entry.liked }; + } else { + return entry; + } + }); + setChatMessages(updatedMessages); + }; + + const totalLikes = chatMessages.filter((entry) => entry.liked).length; + return (

Application title

+

{totalLikes} ❤️s

- {/* 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..27ea1634d 100644 --- a/src/components/ChatEntry.jsx +++ b/src/components/ChatEntry.jsx @@ -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); + }; -const ChatEntry = () => { return ( -
-

Replace with name of sender

+
+

{sender}

-

Replace with body of ChatEntry

-

Replace with TimeStamp component

- +

{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, + onLikeToggle: PropTypes.func.isRequired, }; -export default ChatEntry; +export default ChatEntry; \ No newline at end of file diff --git a/src/components/ChatLog.jsx b/src/components/ChatLog.jsx new file mode 100644 index 000000000..276a119ff --- /dev/null +++ b/src/components/ChatLog.jsx @@ -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 ( + + ); + }); + + return
{ChatEntries}
; +}; + +ChatLog.propTypes = { + entries: PropTypes.array.isRequired, + onLikeToggle: PropTypes.func.isRequired +}; + +export default ChatLog; diff --git a/vite.config.js b/vite.config.js index 2e8881a23..4ec159c17 100644 --- a/vite.config.js +++ b/vite.config.js @@ -4,6 +4,7 @@ import react from '@vitejs/plugin-react' // https://vitejs.dev/config/ export default defineConfig({ plugins: [react()], + base: '/react-chatlog/', test: { // jest config here reporters: ['verbose'],