Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…into Cambios-TontoDelDia
  • Loading branch information
JLeonN committed Apr 2, 2024
2 parents 821fd99 + 7ad4385 commit 63010c4
Show file tree
Hide file tree
Showing 13 changed files with 643 additions and 188 deletions.
33 changes: 33 additions & 0 deletions .github/workflows/deploy-pages.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: 🚢 Publicar a GitHub Pages

on:
push:
branches: [ "main" ]
workflow_dispatch:

concurrency:
group: ci-deploy-pages-${{ github.ref }}
cancel-in-progress: true

jobs:
publish:
defaults:
run:
working-directory: ${{ github.workspace }}/frontend
name: Publicar a GitHub Pages
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: 20.5.1
cache: 'npm'
- run: pwd
- run: rm -rf dist
- run: git branch
- run: ls -l
- run: npm install
- run: npm run deploy

3 changes: 2 additions & 1 deletion frontend/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/Cowboys.png" />
<base href="%BASE_URL%" />
<link rel="icon" type="image/svg+xml" href="Cowboys.png" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>The Cowboy of the Day</title>
<style>
Expand Down
682 changes: 516 additions & 166 deletions frontend/package-lock.json

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"dev": "vite",
"build": "vite build",
"lint": "eslint . --ext js,jsx --report-unused-disable-directives --max-warnings 0",
"preview": "vite preview"
"preview": "vite preview",
"deploy": "vite build --base=/the-cowboy-day/ && gh-pages -d dist"
},
"dependencies": {
"@popperjs/core": "^2.11.8",
Expand All @@ -25,6 +26,7 @@
"eslint-plugin-react": "^7.33.2",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-react-refresh": "^0.4.5",
"gh-pages": "^6.1.1",
"vite": "^5.0.8"
}
}
2 changes: 1 addition & 1 deletion frontend/src/Componentes/Tarjeta/Tarjeta.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const TarjetaTonta = ({ nombre, total, titulos }) => {
<div className="row g-0">
<div className="fondoNav col-md-4">
<img
src="/Cowboys.png"
src="Cowboys.png"
className="fondoNav img-fluid rounded-start"
alt="Icono cowboys"
/>
Expand Down
43 changes: 43 additions & 0 deletions frontend/src/Pagina/CowboyDelDia.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { useState } from 'react';

const Inicio = () => {
const [cowboy, setCowboy] = useState(null);
const [clicked, setClick] = useState(false);

const click = () => {
setClick(true);

setTimeout(() => {
fetchCowboys();
}, 1000);
};

const fetchCowboys = async () => {
try {
const response = await fetch('https://thecowboys.duckdns.org/api/cowboys/today');
const data = await response.json();
setCowboy(data.name);
} catch (error) {
console.error('Error fetching data:', error);
}
};

return (
<div className="cowboyDelDia">
{
!clicked ? (
<button className='btn btn-dark' onClick={click}>
¿Quien es el Cowboy del día?
</button>
) : (
<div>
<p>El cowboy de hoy es....</p>
<h2>{cowboy}</h2>
</div>
)
}
</div>
);
};

export default Inicio;
2 changes: 1 addition & 1 deletion frontend/src/Pagina/Errores/Carga.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const Carga = () => {
return (
<>
<div className="carga">
<img className="cargaImg" src="/Cowboys.png" alt="Icono cowboys" />
<img className="cargaImg" src="Cowboys.png" alt="Icono cowboys" />
</div>
</>
);
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/Pagina/Errores/Error.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const Error = () => {
</p>
<Link to="/">
<img
src="/CowboysBaliado.png"
src="CowboysBaliado.png"
alt="Error"
className="img-fluid mb-3 hoverImg"
width="200"
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/Pagina/Errores/Error404.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const Error404 = () => {
</p>
<Link to="/">
<img
src="/CowboysBaliado.png"
src="CowboysBaliado.png"
alt="Error 404"
className="img-fluid mb-3 hoverImg"
width="200"
Expand Down
7 changes: 6 additions & 1 deletion frontend/src/Pagina/Inicio.jsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import { useObtenerTonto } from "../Hooks/useObtenerTonto";
import Tarjeta from "../Componentes/Tarjeta/Tarjeta";
import Carga from "../Pagina/Errores/Carga";

const Inicio = () => {
const { tonto } = useObtenerTonto();
const { tonto, carga } = useObtenerTonto();

if (carga) {
return <Carga />;
}

return (
<>
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/main.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import "./App.css";
import { BrowserRouter } from "react-router-dom";

ReactDOM.createRoot(document.getElementById("root")).render(
<BrowserRouter>
<BrowserRouter basename={import.meta.env.BASE_URL}>
<App />
</BrowserRouter>
);
38 changes: 24 additions & 14 deletions server/tontos/tontos.repository.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,40 @@
const pool = require("./../database");

const convertirCowboy = (row) => {
return {
id: row.id,
nombre: row.name,
total: row.total,
correo: row.email,
};
};

async function getTontoByDate(dayStr) {
const res = await pool.query(
`
SELECT
t.dia dia,
t.dia AS dia,
c.id AS id,
c.name AS name,
c.email AS email,
ti.name AS titulo,
COUNT(t.cowboy_id)::int AS total
FROM tontos t
INNER JOIN cowboys c ON t.cowboy_id = c.id
COUNT(t1.id)::int AS total
FROM cowboys c
INNER JOIN tontos t ON t.cowboy_id = c.id
LEFT JOIN titulos ti ON ti.cowboy_id = c.id
WHERE t.dia = $1
LEFT JOIN tontos t1 ON t1.cowboy_id = c.id
WHERE t.dia = $1
GROUP BY t.dia, c.id, c.name, ti.name;
`,
[dayStr]
);

if (res.rows.length > 0) {
const firstRow = res.rows[0];
const cowboy = convertirCowboy(firstRow);
return {
...cowboy,
dia: firstRow.dia,
id: firstRow.id,
nombre: firstRow.name,
total: firstRow.total,
titulos: res.rows.map((row) => row.titulo).filter((t) => t),
};
}
Expand Down Expand Up @@ -56,6 +66,7 @@ async function getTontos() {
SELECT
c.id AS id,
c.name AS name,
c.email AS email,
ti.name AS titulo,
COUNT(t.cowboy_id)::int AS total
FROM cowboys c
Expand All @@ -73,10 +84,9 @@ async function getTontos() {
} else {
const titulos = [];
if (row.titulo) titulos.push(row.titulo);
const cowboy = convertirCowboy(row);
acc.set(row.id, {
id: row.id,
nombre: row.name,
total: row.total,
...cowboy,
titulos: titulos,
});
}
Expand All @@ -92,6 +102,7 @@ async function getTontoById(idCowboy) {
SELECT
c.id AS id,
c.name AS name,
c.email AS email,
ti.name AS titulo,
COUNT(t.cowboy_id)::int AS total
FROM cowboys c
Expand All @@ -105,11 +116,10 @@ async function getTontoById(idCowboy) {

if (res.rows.length > 0) {
const firstRow = res.rows[0];
const cowboy = convertirCowboy(firstRow);
return {
...cowboy,
dia: firstRow.dia,
id: firstRow.id,
nombre: firstRow.name,
total: firstRow.total,
titulos: res.rows.map((row) => row.titulo).filter((t) => t),
};
}
Expand Down
11 changes: 11 additions & 0 deletions sql/005_add_email_column.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
ALTER TABLE cowboys ADD COLUMN email varchar UNIQUE;

UPDATE cowboys SET email = '[email protected]' where id = 4;
UPDATE cowboys SET email = '[email protected]' where id = 3;
UPDATE cowboys SET email = '[email protected]' where id = 5;
UPDATE cowboys SET email = '[email protected]' where id = 6;
UPDATE cowboys SET email = '[email protected]' where id = 2;
UPDATE cowboys SET email = '[email protected]' where id = 1;

-- make email not null
ALTER TABLE cowboys ALTER COLUMN email SET NOT NULL;

0 comments on commit 63010c4

Please sign in to comment.