From 2a80f885f75a0a2bdaf38aea7d498a113cceefd6 Mon Sep 17 00:00:00 2001 From: aek676 Date: Sat, 29 Nov 2025 19:50:25 +0100 Subject: [PATCH 01/17] feat: reestructurar componentes de botones y mejorar importaciones --- src/components/ActionButton.astro | 11 ++++++++++ src/components/ActionButton.tsx | 9 -------- src/components/Hero.astro | 11 ++-------- src/components/LinkButton.astro | 12 +++++++++++ src/components/LinkButton.tsx | 10 --------- src/components/MyButton.astro | 36 +++++++++++++++++++++++++++++++ src/components/MyButton.tsx | 22 ------------------- src/pages/game/[...slug].astro | 3 +-- src/pages/game/index.astro | 6 +++--- 9 files changed, 65 insertions(+), 55 deletions(-) create mode 100644 src/components/ActionButton.astro delete mode 100644 src/components/ActionButton.tsx create mode 100644 src/components/LinkButton.astro delete mode 100644 src/components/LinkButton.tsx create mode 100644 src/components/MyButton.astro delete mode 100644 src/components/MyButton.tsx diff --git a/src/components/ActionButton.astro b/src/components/ActionButton.astro new file mode 100644 index 0000000..251dec5 --- /dev/null +++ b/src/components/ActionButton.astro @@ -0,0 +1,11 @@ +--- +import MyButton from "./MyButton.astro"; + +interface Props { + text: string; +} + +const { text } = Astro.props; +--- + + diff --git a/src/components/ActionButton.tsx b/src/components/ActionButton.tsx deleted file mode 100644 index 5193f5c..0000000 --- a/src/components/ActionButton.tsx +++ /dev/null @@ -1,9 +0,0 @@ -import { MyButton } from "./MyButton"; - -interface StartGameAgainButtonProps { - text: string; -} - -export default function ActionButton({ text }: StartGameAgainButtonProps) { - return ; -}; diff --git a/src/components/Hero.astro b/src/components/Hero.astro index c712ae8..524e588 100644 --- a/src/components/Hero.astro +++ b/src/components/Hero.astro @@ -1,5 +1,5 @@ --- -import LinkButton from "./LinkButton"; +import LinkButton from "./LinkButton.astro"; import ImpostorAnimation from "@/components/ImpostorAnimation.astro"; --- @@ -7,7 +7,6 @@ import ImpostorAnimation from "@/components/ImpostorAnimation.astro";
- {/* TÍTULO */}

- {/* CONTENEDOR DE LA CARTA */}
- {/* Capa de ruido (Noise) */}
- {/* ANIMACIÓN */} - { - /* Aquí está la clave: w-full para que se adapte, max-w para limitar */ - }
@@ -45,6 +38,6 @@ import ImpostorAnimation from "@/components/ImpostorAnimation.astro";
- +
diff --git a/src/components/LinkButton.astro b/src/components/LinkButton.astro new file mode 100644 index 0000000..0d1d441 --- /dev/null +++ b/src/components/LinkButton.astro @@ -0,0 +1,12 @@ +--- +import MyButton from "./MyButton.astro"; + +interface Props { + text: string; + href: string; +} + +const { text, href } = Astro.props; +--- + + diff --git a/src/components/LinkButton.tsx b/src/components/LinkButton.tsx deleted file mode 100644 index a676584..0000000 --- a/src/components/LinkButton.tsx +++ /dev/null @@ -1,10 +0,0 @@ -import { MyButton } from "./MyButton"; - -interface LinkButtonProps { - text: string; - href: string; -} - -export default function LinkButton({ text, href }: LinkButtonProps) { - return window.location.href = href} />; -}; diff --git a/src/components/MyButton.astro b/src/components/MyButton.astro new file mode 100644 index 0000000..d946176 --- /dev/null +++ b/src/components/MyButton.astro @@ -0,0 +1,36 @@ +--- +interface Props { + text: string; + type?: "button" | "submit" | "reset"; + disabled?: boolean; + href?: string; + id?: string; + class?: string; +} + +const { + text, + type = "button", + disabled = false, + href, + id, + class: className, + ...rest +} = Astro.props; + +const Tag = href ? "a" : "button"; +const props = href ? { href, ...rest } : { type, disabled, ...rest }; +--- + + +
+
+
+
+
{text}
+
+
+
+
+
+
diff --git a/src/components/MyButton.tsx b/src/components/MyButton.tsx deleted file mode 100644 index ff84f1e..0000000 --- a/src/components/MyButton.tsx +++ /dev/null @@ -1,22 +0,0 @@ -interface MyButtonProps { - text: string; - onClick?: React.MouseEventHandler; - type?: "button" | "submit" | "reset"; -} - -export function MyButton({ text, onClick, type = "button" }: MyButtonProps) { - return ( - - ); -} \ No newline at end of file diff --git a/src/pages/game/[...slug].astro b/src/pages/game/[...slug].astro index e8a25c0..105c0bb 100644 --- a/src/pages/game/[...slug].astro +++ b/src/pages/game/[...slug].astro @@ -1,7 +1,7 @@ --- import Layout from "@/layouts/Layout.astro"; import { SwipeCard } from "@/components/SwipeToRevealCard"; -import LinkButton from "@/components/LinkButton"; +import LinkButton from "@/components/LinkButton.astro"; export const prerender = false; @@ -34,7 +34,6 @@ const randomCard = !currentPlayer.isImpostor image={randomCard?.iconUrls.medium} /> diff --git a/src/pages/game/index.astro b/src/pages/game/index.astro index c337ce4..b964910 100644 --- a/src/pages/game/index.astro +++ b/src/pages/game/index.astro @@ -1,7 +1,7 @@ --- import PressToReveal from "@/components/PressToReveal"; import Layout from "@/layouts/Layout.astro"; -import ActionButton from "@/components/ActionButton"; +import ActionButton from "@/components/ActionButton.astro"; import { actions } from "astro:actions"; const [randomPlayerToStart, players] = await Promise.all([ @@ -45,11 +45,11 @@ if (clearGame && !clearGame.error) { )) } - +
- + From f926db8a28dee787b0e702b809c4229ca6739c58 Mon Sep 17 00:00:00 2001 From: aek676 Date: Sat, 29 Nov 2025 20:02:51 +0100 Subject: [PATCH 02/17] =?UTF-8?q?feat:=20reescribir=20SetupScreen=20en=20A?= =?UTF-8?q?stro=20y=20ajustar=20importaciones=20en=20la=20p=C3=A1gina=20de?= =?UTF-8?q?=20configuraci=C3=B3n?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/SetupScreen.astro | 175 +++++++++++++++++++++++++++++++ src/components/SetupScreen.tsx | 138 ------------------------ src/pages/config.astro | 4 +- 3 files changed, 177 insertions(+), 140 deletions(-) create mode 100644 src/components/SetupScreen.astro delete mode 100644 src/components/SetupScreen.tsx diff --git a/src/components/SetupScreen.astro b/src/components/SetupScreen.astro new file mode 100644 index 0000000..2fe9583 --- /dev/null +++ b/src/components/SetupScreen.astro @@ -0,0 +1,175 @@ +--- +import { X } from "lucide-react"; +import { actions } from "astro:actions"; +import MyButton from "./MyButton.astro"; +import { Card } from "./ui/card"; +import { Input } from "./ui/input"; +import { Label } from "./ui/label"; + +interface Props { + onGameStartRedirect: string; + minPlayers?: number; +} + +const { minPlayers = 3 } = Astro.props; +--- + +
+ +
+

Configuración

+

+ Añade al menos {minPlayers} jugadores para empezar +

+
+ +
+
+
+ + +
+
+ +
+
+ + +
+ +
+
+ +
+
+
+
+ + diff --git a/src/components/SetupScreen.tsx b/src/components/SetupScreen.tsx deleted file mode 100644 index 9bcdafb..0000000 --- a/src/components/SetupScreen.tsx +++ /dev/null @@ -1,138 +0,0 @@ -import { useState } from "react"; -import { X } from "lucide-react"; -import { Button } from "./ui/button"; -import { Card } from "./ui/card"; -import { Input } from "./ui/input"; -import { Label } from "./ui/label"; -import { actions } from "astro:actions"; - -interface ConfiguracionJuegoProps { - onGameStartRedirect: string; - minPlayers?: number; -} - -export function SetupScreen({ - minPlayers = 3, -}: ConfiguracionJuegoProps) { - const [playerName, setPlayerName] = useState(""); - const [players, setPlayers] = useState([]); - - const canStart = players.length >= minPlayers; - const remainingPlayers = minPlayers - players.length; - - const handleAddPlayer = () => { - if (playerName.trim()) { - setPlayers([...players, playerName.trim()]); - setPlayerName(""); - } - }; - - const handleKeyDown = (e: React.KeyboardEvent) => { - if (e.key === "Enter") { - handleAddPlayer(); - } - }; - - const onRemovePlayer = (indexToRemove: number) => { - setPlayers(players.filter((_, index) => index !== indexToRemove)); - }; - - const onStartGame = async () => { - if (!canStart) return; - - try { - const formData = new FormData(); - players.forEach((player) => formData.append('players', player)); - - const result = await actions.game.startGame(formData); - - if (result.data?.success) { - const firstPlayer = result.data.firstPlayer; - window.location.href = `/game/${encodeURIComponent(firstPlayer)}`; - } else { - console.error('Error al iniciar el juego:', result.error); - } - } catch (error) { - console.error('Error al iniciar el juego:', error); - } - }; - - return ( -
- -
-

Configuración

-

- Añade al menos {minPlayers} jugadores para empezar -

-
- -
-
-
- - setPlayerName(e.target.value)} - onKeyDown={handleKeyDown} - placeholder="Escribe un nombre..." - className="mt-1 bg-muted/50 border-border text-foreground" - /> -
-
- -
-
- - {players.length > 0 && ( -
- -
- {players.map((player, index) => ( -
- - {player} - - -
- ))} -
-
- )} -
- - -
-
- ); -} \ No newline at end of file diff --git a/src/pages/config.astro b/src/pages/config.astro index 9bfa4d4..f261398 100644 --- a/src/pages/config.astro +++ b/src/pages/config.astro @@ -1,8 +1,8 @@ --- import Layout from "@/layouts/Layout.astro"; -import { SetupScreen } from "@/components/SetupScreen"; +import SetupScreen from "@/components/SetupScreen.astro"; --- - + From b2dca813d17b3d5cfc931ea3a2a88c22a9c3a157 Mon Sep 17 00:00:00 2001 From: aek676 Date: Sat, 29 Nov 2025 21:09:58 +0100 Subject: [PATCH 03/17] =?UTF-8?q?feat:=20agregar=20componente=20ConfigGame?= =?UTF-8?q?=20y=20eliminar=20SetupScreen=20en=20la=20p=C3=A1gina=20de=20co?= =?UTF-8?q?nfiguraci=C3=B3n?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/ConfigGame.astro | 147 ++++++++++++++++++++++++++ src/components/SetupScreen.astro | 175 ------------------------------- src/pages/config.astro | 23 +++- 3 files changed, 167 insertions(+), 178 deletions(-) create mode 100644 src/components/ConfigGame.astro delete mode 100644 src/components/SetupScreen.astro diff --git a/src/components/ConfigGame.astro b/src/components/ConfigGame.astro new file mode 100644 index 0000000..294d2bf --- /dev/null +++ b/src/components/ConfigGame.astro @@ -0,0 +1,147 @@ +--- +// src/components/ConfigGame.astro +import { actions } from "astro:actions"; +import MyButton from "./MyButton.astro"; +import { Card } from "./ui/card"; +import { Input } from "./ui/input"; +import { Label } from "./ui/label"; +import ActionButton from "./ActionButton.astro"; + +interface Props { + minPlayers?: number; + serverError?: string; +} + +const { minPlayers = 3, serverError } = Astro.props; +--- + +
+ +
+

Configuración

+

+ Añade al menos {minPlayers} jugadores +

+
+ +
+
+
+ + +
+
+ +
+
+ + +
+ +
+
+
+ + +
+ + { + serverError && ( +
+ ❌ Error: {serverError} +
+ ) + } +
+
+
+ + diff --git a/src/components/SetupScreen.astro b/src/components/SetupScreen.astro deleted file mode 100644 index 2fe9583..0000000 --- a/src/components/SetupScreen.astro +++ /dev/null @@ -1,175 +0,0 @@ ---- -import { X } from "lucide-react"; -import { actions } from "astro:actions"; -import MyButton from "./MyButton.astro"; -import { Card } from "./ui/card"; -import { Input } from "./ui/input"; -import { Label } from "./ui/label"; - -interface Props { - onGameStartRedirect: string; - minPlayers?: number; -} - -const { minPlayers = 3 } = Astro.props; ---- - -
- -
-

Configuración

-

- Añade al menos {minPlayers} jugadores para empezar -

-
- -
-
-
- - -
-
- -
-
- - -
- -
-
- -
-
-
-
- - diff --git a/src/pages/config.astro b/src/pages/config.astro index f261398..0a21586 100644 --- a/src/pages/config.astro +++ b/src/pages/config.astro @@ -1,8 +1,25 @@ --- +// src/pages/config.astro import Layout from "@/layouts/Layout.astro"; -import SetupScreen from "@/components/SetupScreen.astro"; +// Importa TU componente del formulario. Asumo que se llama ConfigGame.astro +import ConfigGame from "@/components/ConfigGame.astro"; +import { actions } from "astro:actions"; + +// 1. CAPTURAMOS EL RESULTADO ANTES DE PINTAR NADA +const result = Astro.getActionResult(actions.game.startGame); + +// 2. SI TODO FUE BIEN, REDIRIGIMOS (Aquí aún no se ha enviado HTML) +if (result && !result.error && result.data?.success) { + return Astro.redirect( + `/game/${encodeURIComponent(result.data.firstPlayer)}`, + ); +} + +// 3. SI HUBO ERROR, LO PREPARAMOS +// Si result.error es un objeto complejo, sacamos el mensaje +const errorMessage = result?.error ? JSON.stringify(result.error) : undefined; --- - - + + From 0d0a564f3d82b2656895ca7d8f2ef5f5a9730425 Mon Sep 17 00:00:00 2001 From: aek676 Date: Sat, 29 Nov 2025 22:18:10 +0100 Subject: [PATCH 04/17] =?UTF-8?q?feat:=20pulir=20pantalla=20de=20configura?= =?UTF-8?q?ci=C3=B3n=20y=20mejorar=20el=20componente=20MyButton?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/ConfigGame.astro | 56 +++++++--- src/components/MyButton.astro | 181 ++++++++++++++++++++++++++++++-- src/styles/global.css | 113 +------------------- 3 files changed, 213 insertions(+), 137 deletions(-) diff --git a/src/components/ConfigGame.astro b/src/components/ConfigGame.astro index 294d2bf..41221f7 100644 --- a/src/components/ConfigGame.astro +++ b/src/components/ConfigGame.astro @@ -5,7 +5,6 @@ import MyButton from "./MyButton.astro"; import { Card } from "./ui/card"; import { Input } from "./ui/input"; import { Label } from "./ui/label"; -import ActionButton from "./ActionButton.astro"; interface Props { minPlayers?: number; @@ -39,14 +38,13 @@ const { minPlayers = 3, serverError } = Astro.props; />
- + text="Añadir" + type="button" + scale={0.4} + disabled={true} + />
@@ -66,10 +64,10 @@ const { minPlayers = 3, serverError } = Astro.props; id="startGameForm" class="mt-6" > -
+
- +
{ @@ -94,11 +92,19 @@ const { minPlayers = 3, serverError } = Astro.props; const hiddenInputsContainer = document.getElementById( "hiddenInputsContainer", ); + const startGameForm = document.getElementById("startGameForm"); + const submitBtn = fieldset.querySelector('button[type="submit"]'); function updateUI() { playerCount.textContent = players.length; playersSection.classList.toggle("hidden", players.length === 0); - fieldset.disabled = players.length < minPlayers; + + const canStart = players.length >= minPlayers; + if (canStart) { + submitBtn.removeAttribute("data-disabled"); + } else { + submitBtn.setAttribute("data-disabled", "true"); + } playersList.innerHTML = players .map( @@ -130,18 +136,38 @@ const { minPlayers = 3, serverError } = Astro.props; players.push(val); playerNameInput.value = ""; updateUI(); + checkInput(); // Re-evaluar estado del botón tras limpiar input } } addPlayerBtn.addEventListener("click", handleAdd); - playerNameInput.addEventListener( - "input", - () => (addPlayerBtn.disabled = !playerNameInput.value.trim()), - ); + + // Función para comprobar el estado del botón + const checkInput = () => { + const hasInput = !!playerNameInput.value.trim(); + if (hasInput) { + addPlayerBtn.removeAttribute("data-disabled"); + } else { + addPlayerBtn.setAttribute("data-disabled", "true"); + } + }; + + playerNameInput.addEventListener("input", checkInput); + + // Comprobación inicial por si el navegador autorellena el campo + checkInput(); + updateUI(); + playerNameInput.addEventListener("keydown", (e) => { if (e.key === "Enter") { e.preventDefault(); handleAdd(); } }); + + startGameForm.addEventListener("submit", (e) => { + if (players.length < minPlayers) { + e.preventDefault(); + } + }); diff --git a/src/components/MyButton.astro b/src/components/MyButton.astro index d946176..72b14e8 100644 --- a/src/components/MyButton.astro +++ b/src/components/MyButton.astro @@ -6,6 +6,7 @@ interface Props { href?: string; id?: string; class?: string; + scale?: number; // 1. Nueva propiedad para controlar el tamaño } const { @@ -15,22 +16,182 @@ const { href, id, class: className, + scale = 1, // Por defecto es tamaño normal (1) ...rest } = Astro.props; const Tag = href ? "a" : "button"; -const props = href ? { href, ...rest } : { type, disabled, ...rest }; +const props = href ? { href, ...rest } : { type, ...rest }; --- - -
-
-
-
-
{text}
-
+
+ +
+
+
+
+
{text}
+
+
-
- + +
+ + diff --git a/src/styles/global.css b/src/styles/global.css index c934fa0..f610ed7 100644 --- a/src/styles/global.css +++ b/src/styles/global.css @@ -275,118 +275,7 @@ } @layer components { - .couche1 { - position: relative; - -webkit-border-radius: 11px; - -moz-border-radius: 11px; - border-radius: 11px; - width: 300px; - height: 100px; - background: black; - -webkit-box-shadow: 0px 11px 2px #301c09; - -moz-box-shadow: 0px 11px 2px #301c09; - box-shadow: 0px 11px 2px #301c09; - cursor: pointer; - margin: 20px auto; - border: none; - padding: 0; - display: block; - } - - .couche2 { - position: absolute; - -webkit-border-radius: 10px; - -moz-border-radius: 10px; - border-radius: 10px; - width: 294px; - height: 94px; - top: 3px; - left: 3px; - background: #fda80d; - -webkit-box-shadow: 0px 9px 0px #af6b06; - -moz-box-shadow: 0px 9px 0px #af6b06; - box-shadow: 0px 9px 0px #af6b06; - } - - .couche23 { - position: absolute; - -webkit-border-radius: 10px; - -moz-border-radius: 10px; - border-radius: 10px; - width: 292px; - height: 80px; - top: 5px; - left: 1px; - -webkit-box-shadow: 0px -4px 5px 0px #ffdc33; - -moz-box-shadow: 0px -4px 5px 0px #ffdc33; - box-shadow: 0px -4px 5px 0px #ffdc33; - } - - .couche3 { - position: absolute; - -webkit-border-radius: 10px; - -moz-border-radius: 10px; - border-radius: 10px; - top: 0px; - left: 5px; - width: 281px; - height: 82px; - background: rgba(255, 187, 42, 1); - -webkit-box-shadow: 0px 4px 3px 0px #fe8906; - -moz-box-shadow: 0px 4px 3px 0px #fe8906; - box-shadow: 0px 4px 3px 0px #fe8906; - } - - .couche4 { - position: absolute; - -webkit-border-radius: 10px; - -moz-border-radius: 10px; - border-radius: 10px; - top: 5px; - left: 3px; - width: 275px; - height: 38px; - background: #ffd053; - } - - .couche5 { - position: absolute; - -webkit-border-radius: 45%; - -moz-border-radius: 45%; - border-radius: 45%; - top: 0px; - left: 267px; - width: 7px; - height: 9px; - background: #fff1b6; - } - - .battle { - position: absolute; - font-style: normal; - font-weight: 400; - color: #ffffcc; - font-size: 1.7em; - top: 90%; - left: 50%; - transform: translate(-50%, -50%); - text-shadow: - -1px 0 1px #582e00, - 1px 0 1px #582e00, - 0 -1px 1px #582e00, - 0 4px 1px #582e00, - -2px 4px 1px #582e00, - 2px 3px 2px #582e00; - } - - /*effects*/ - .couche1:active { - transform: scale(0.93, 0.95) translateY(5px); - } - - .couche1:active .battle { - font-size: 1.55em; - } + } @layer base { From afb0e50e01a12c788e2628ddd62760ec6ee94b6e Mon Sep 17 00:00:00 2001 From: aek676 Date: Sat, 29 Nov 2025 23:07:20 +0100 Subject: [PATCH 05/17] feat: agregar componente MyInput con estilos personalizados y soporte para clases --- src/components/MyInput.astro | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 src/components/MyInput.astro diff --git a/src/components/MyInput.astro b/src/components/MyInput.astro new file mode 100644 index 0000000..173e43f --- /dev/null +++ b/src/components/MyInput.astro @@ -0,0 +1,19 @@ +--- +const { class: className, ...rest } = Astro.props; +--- + + + + From 818ab0aa0fef83b4ea93abe8f2729881247b6f43 Mon Sep 17 00:00:00 2001 From: aek676 Date: Sat, 29 Nov 2025 23:38:39 +0100 Subject: [PATCH 06/17] feat: reemplazar Input por MyInput en ConfigGame y ajustar estilos de MyButton --- src/components/ConfigGame.astro | 20 ++++++++------------ src/components/MyButton.astro | 4 ++-- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/src/components/ConfigGame.astro b/src/components/ConfigGame.astro index 41221f7..b20bbf0 100644 --- a/src/components/ConfigGame.astro +++ b/src/components/ConfigGame.astro @@ -3,8 +3,8 @@ import { actions } from "astro:actions"; import MyButton from "./MyButton.astro"; import { Card } from "./ui/card"; -import { Input } from "./ui/input"; import { Label } from "./ui/label"; +import MyInput from "./MyInput.astro"; interface Props { minPlayers?: number; @@ -28,21 +28,19 @@ const { minPlayers = 3, serverError } = Astro.props;
- Nombre - + +
@@ -136,13 +134,12 @@ const { minPlayers = 3, serverError } = Astro.props; players.push(val); playerNameInput.value = ""; updateUI(); - checkInput(); // Re-evaluar estado del botón tras limpiar input + checkInput(); } } addPlayerBtn.addEventListener("click", handleAdd); - // Función para comprobar el estado del botón const checkInput = () => { const hasInput = !!playerNameInput.value.trim(); if (hasInput) { @@ -154,7 +151,6 @@ const { minPlayers = 3, serverError } = Astro.props; playerNameInput.addEventListener("input", checkInput); - // Comprobación inicial por si el navegador autorellena el campo checkInput(); updateUI(); diff --git a/src/components/MyButton.astro b/src/components/MyButton.astro index 72b14e8..6b5eaf0 100644 --- a/src/components/MyButton.astro +++ b/src/components/MyButton.astro @@ -151,7 +151,7 @@ const props = href ? { href, ...rest } : { type, ...rest }; font-style: normal; font-weight: 400; color: #ffffcc; - font-size: 1.7em; + font-size: 2em; top: 90%; left: 50%; transform: translate(-50%, -50%); @@ -175,7 +175,7 @@ const props = href ? { href, ...rest } : { type, ...rest }; } .couche1:active .battle { - font-size: 1.55em; + font-size: 1.9em; } /* 5. ESTADO DISABLED */ From 36655381b996a2d560ecb2a1998eaef5e3e6d5af Mon Sep 17 00:00:00 2001 From: aek676 Date: Sat, 29 Nov 2025 23:46:21 +0100 Subject: [PATCH 07/17] =?UTF-8?q?feat:=20agregar=20componente=20PlayerList?= =?UTF-8?q?Item=20y=20mejorar=20la=20gesti=C3=B3n=20de=20jugadores=20en=20?= =?UTF-8?q?ConfigGame?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/ConfigGame.astro | 47 ++++---- src/components/PlayerListItem.astro | 163 ++++++++++++++++++++++++++++ 2 files changed, 190 insertions(+), 20 deletions(-) create mode 100644 src/components/PlayerListItem.astro diff --git a/src/components/ConfigGame.astro b/src/components/ConfigGame.astro index b20bbf0..d8213f4 100644 --- a/src/components/ConfigGame.astro +++ b/src/components/ConfigGame.astro @@ -1,10 +1,10 @@ --- -// src/components/ConfigGame.astro import { actions } from "astro:actions"; import MyButton from "./MyButton.astro"; import { Card } from "./ui/card"; import { Label } from "./ui/label"; import MyInput from "./MyInput.astro"; +import PlayerListItem from "./PlayerListItem.astro"; interface Props { minPlayers?: number; @@ -50,10 +50,14 @@ const { minPlayers = 3, serverError } = Astro.props;
+ +
` -
- ${p} - -
- `, - ) - .join(""); + playersList.innerHTML = ""; + + players.forEach((p, i) => { + const clone = playerTemplate.content.cloneNode(true); + const nameEl = clone.querySelector(".player-name-text"); + if (nameEl) nameEl.textContent = p; + + const deleteBtn = clone.querySelector(".delete-player-btn"); + if (deleteBtn) { + deleteBtn.dataset.index = i; + deleteBtn.addEventListener("click", (e) => { + const idx = parseInt( + e.target.closest("button").dataset.index, + ); + players = players.filter((_, index) => index !== idx); + updateUI(); + }); + } + playersList.appendChild(clone); + }); hiddenInputsContainer.innerHTML = players .map((p) => ``) .join(""); - - document.querySelectorAll(".delete-btn").forEach((btn) => { - btn.addEventListener("click", (e) => { - const idx = parseInt(e.target.dataset.index); - players = players.filter((_, i) => i !== idx); - updateUI(); - }); - }); } function handleAdd() { diff --git a/src/components/PlayerListItem.astro b/src/components/PlayerListItem.astro new file mode 100644 index 0000000..60d6b9a --- /dev/null +++ b/src/components/PlayerListItem.astro @@ -0,0 +1,163 @@ +--- +interface Props { + playerName?: string; + scale?: number; +} + +const { playerName = "", scale = 0.6 } = Astro.props; +--- + +
+
+
+
+
+
+
+
+ {playerName} +
+
+
+
+
+
+
+
+ + +
+ + From 0d2a8b732a66e3efb461c26bec5535d8c6360452 Mon Sep 17 00:00:00 2001 From: aek676 Date: Fri, 5 Dec 2025 18:27:47 +0100 Subject: [PATCH 08/17] =?UTF-8?q?feat:=20pulir=20componente=20PlayerListIt?= =?UTF-8?q?em=20eliminando=20el=20bot=C3=B3n=20de=20eliminar=20y=20ajustan?= =?UTF-8?q?do=20estilos?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/PlayerListItem.astro | 53 +++++++++-------------------- 1 file changed, 16 insertions(+), 37 deletions(-) diff --git a/src/components/PlayerListItem.astro b/src/components/PlayerListItem.astro index 60d6b9a..2bf0410 100644 --- a/src/components/PlayerListItem.astro +++ b/src/components/PlayerListItem.astro @@ -17,21 +17,12 @@ const { playerName = "", scale = 0.6 } = Astro.props;
{playerName}
-
- - diff --git a/src/pages/config.astro b/src/pages/config.astro index 0a21586..e15cceb 100644 --- a/src/pages/config.astro +++ b/src/pages/config.astro @@ -1,22 +1,16 @@ --- -// src/pages/config.astro import Layout from "@/layouts/Layout.astro"; -// Importa TU componente del formulario. Asumo que se llama ConfigGame.astro import ConfigGame from "@/components/ConfigGame.astro"; import { actions } from "astro:actions"; -// 1. CAPTURAMOS EL RESULTADO ANTES DE PINTAR NADA const result = Astro.getActionResult(actions.game.startGame); -// 2. SI TODO FUE BIEN, REDIRIGIMOS (Aquí aún no se ha enviado HTML) if (result && !result.error && result.data?.success) { return Astro.redirect( `/game/${encodeURIComponent(result.data.firstPlayer)}`, ); } -// 3. SI HUBO ERROR, LO PREPARAMOS -// Si result.error es un objeto complejo, sacamos el mensaje const errorMessage = result?.error ? JSON.stringify(result.error) : undefined; --- From 9ce93e58be220ca8a91e5eee144b02db9cc60144 Mon Sep 17 00:00:00 2001 From: aek676 Date: Fri, 5 Dec 2025 19:10:28 +0100 Subject: [PATCH 11/17] =?UTF-8?q?feat:=20eliminar=20bot=C3=B3n=20de=20elim?= =?UTF-8?q?inar=20en=20ConfigGame=20y=20agregar=20componente=20XButton?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/ConfigGame.astro | 11 --- src/components/PlayerListItem.astro | 2 + src/components/XButton.astro | 142 ++++++++++++++++++++++++++++ 3 files changed, 144 insertions(+), 11 deletions(-) create mode 100644 src/components/XButton.astro diff --git a/src/components/ConfigGame.astro b/src/components/ConfigGame.astro index d8213f4..fa904bc 100644 --- a/src/components/ConfigGame.astro +++ b/src/components/ConfigGame.astro @@ -116,17 +116,6 @@ const { minPlayers = 3, serverError } = Astro.props; const nameEl = clone.querySelector(".player-name-text"); if (nameEl) nameEl.textContent = p; - const deleteBtn = clone.querySelector(".delete-player-btn"); - if (deleteBtn) { - deleteBtn.dataset.index = i; - deleteBtn.addEventListener("click", (e) => { - const idx = parseInt( - e.target.closest("button").dataset.index, - ); - players = players.filter((_, index) => index !== idx); - updateUI(); - }); - } playersList.appendChild(clone); }); diff --git a/src/components/PlayerListItem.astro b/src/components/PlayerListItem.astro index 9b96779..f13552f 100644 --- a/src/components/PlayerListItem.astro +++ b/src/components/PlayerListItem.astro @@ -1,4 +1,6 @@ --- +import XButton from "./XButton.astro"; + interface Props { playerName?: string; scale?: number; diff --git a/src/components/XButton.astro b/src/components/XButton.astro new file mode 100644 index 0000000..cc473e4 --- /dev/null +++ b/src/components/XButton.astro @@ -0,0 +1,142 @@ +--- +const { scale = 1 } = Astro.props; +--- + +
+ +
+ + From 2496d883776556ab5aca269143501d1a6c5faa32 Mon Sep 17 00:00:00 2001 From: aek676 Date: Fri, 5 Dec 2025 19:19:18 +0100 Subject: [PATCH 12/17] =?UTF-8?q?feat:=20agregar=20componente=20XButton=20?= =?UTF-8?q?en=20PlayerListItem=20y=20crear=20p=C3=A1gina=20de=20prueba?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/PlayerListItem.astro | 7 +++++-- src/components/XButton.astro | 7 ------- src/pages/test.astro | 19 +++++++++++++++++++ 3 files changed, 24 insertions(+), 9 deletions(-) create mode 100644 src/pages/test.astro diff --git a/src/components/PlayerListItem.astro b/src/components/PlayerListItem.astro index f13552f..20a04d6 100644 --- a/src/components/PlayerListItem.astro +++ b/src/components/PlayerListItem.astro @@ -12,6 +12,9 @@ const { playerName = "", scale = 0.6 } = Astro.props;
+
+ +
@@ -58,12 +61,12 @@ const { playerName = "", scale = 0.6 } = Astro.props; transform-origin: center; } - .couche1:active { + .couche1:active:not(:has(.x-button-wrapper:active)) { transform: translate(-50%, -50%) scale(calc(var(--scale) * 0.95)) translateY(5px); } - .couche1:active .battle { + .couche1:active:not(:has(.x-button-wrapper:active)) .battle { font-size: 1.9em; } diff --git a/src/components/XButton.astro b/src/components/XButton.astro index cc473e4..ab9b250 100644 --- a/src/components/XButton.astro +++ b/src/components/XButton.astro @@ -132,11 +132,4 @@ const { scale = 1 } = Astro.props; .couche1:active .battle { font-size: 1.9em; } - - .couche1:disabled, - .couche1[data-disabled="true"] { - filter: grayscale(100%); - opacity: 0.7; - cursor: not-allowed; - } diff --git a/src/pages/test.astro b/src/pages/test.astro new file mode 100644 index 0000000..0c0bdca --- /dev/null +++ b/src/pages/test.astro @@ -0,0 +1,19 @@ +--- +import PlayerListItem from "@/components/PlayerListItem.astro"; +import Layout from "../layouts/Layout.astro"; +import { Card } from "@/components/ui/card"; +import XButton from "@/components/XButton.astro"; +--- + + +
+ +
+ + +
+
+
+
From 2be00c6e684cc3282ee5afb72e140834c17373bf Mon Sep 17 00:00:00 2001 From: aek676 Date: Fri, 5 Dec 2025 23:10:38 +0100 Subject: [PATCH 13/17] =?UTF-8?q?feat:=20agregar=20funcionalidad=20para=20?= =?UTF-8?q?eliminar=20jugadores=20en=20ConfigGame=20y=20ajustar=20posici?= =?UTF-8?q?=C3=B3n=20del=20bot=C3=B3n=20en=20PlayerListItem?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/ConfigGame.astro | 10 ++++++++++ src/components/PlayerListItem.astro | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/components/ConfigGame.astro b/src/components/ConfigGame.astro index fa904bc..e33f6b5 100644 --- a/src/components/ConfigGame.astro +++ b/src/components/ConfigGame.astro @@ -98,6 +98,11 @@ const { minPlayers = 3, serverError } = Astro.props; const submitBtn = fieldset.querySelector('button[type="submit"]'); const playerTemplate = document.getElementById("player-template"); + function removePlayer(index) { + players.splice(index, 1); + updateUI(); + } + function updateUI() { playerCount.textContent = players.length; playersSection.classList.toggle("hidden", players.length === 0); @@ -116,6 +121,11 @@ const { minPlayers = 3, serverError } = Astro.props; const nameEl = clone.querySelector(".player-name-text"); if (nameEl) nameEl.textContent = p; + const deleteBtn = clone.querySelector(".x-button-wrapper"); + if (deleteBtn) { + deleteBtn.addEventListener("click", () => removePlayer(i)); + } + playersList.appendChild(clone); }); diff --git a/src/components/PlayerListItem.astro b/src/components/PlayerListItem.astro index 20a04d6..06ffdc2 100644 --- a/src/components/PlayerListItem.astro +++ b/src/components/PlayerListItem.astro @@ -12,7 +12,7 @@ const { playerName = "", scale = 0.6 } = Astro.props;
-
+
From bd0ddf8ab5add03de2de8dac306034afe1b60745 Mon Sep 17 00:00:00 2001 From: aek676 Date: Fri, 5 Dec 2025 23:10:46 +0100 Subject: [PATCH 14/17] =?UTF-8?q?feat:=20pulir=20estilos=20del=20bot=C3=B3?= =?UTF-8?q?n=20MyButton=20y=20ajustar=20alineaci=C3=B3n=20en=20la=20p?= =?UTF-8?q?=C3=A1gina=20de=20inicio=20del=20juego?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/MyButton.astro | 5 ++++- src/pages/game/index.astro | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/components/MyButton.astro b/src/components/MyButton.astro index a966917..cf313cf 100644 --- a/src/components/MyButton.astro +++ b/src/components/MyButton.astro @@ -160,7 +160,10 @@ const props = href ? { href, ...rest } : { type, ...rest }; -2px 4px 1px #582e00, 2px 3px 2px #582e00; - white-space: nowrap; + white-space: normal; + text-align: center; + width: 100%; + line-height: 0.9; } .couche1:active { diff --git a/src/pages/game/index.astro b/src/pages/game/index.astro index b964910..a50a198 100644 --- a/src/pages/game/index.astro +++ b/src/pages/game/index.astro @@ -38,7 +38,7 @@ if (clearGame && !clearGame.error) { nameImpostor={impostor?.name || "Desconocido"} client:load /> -
+
{ playersNames.map((name) => ( From 616db1fd96af3ff1fe92e336adbab11e9292428c Mon Sep 17 00:00:00 2001 From: aek676 Date: Fri, 5 Dec 2025 23:23:07 +0100 Subject: [PATCH 15/17] =?UTF-8?q?feat:=20pulir=20estilos=20de=20la=20panta?= =?UTF-8?q?lla=20de=20configuraci=C3=B3n=20y=20mejorar=20la=20presentaci?= =?UTF-8?q?=C3=B3n=20de=20los=20jugadores?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/ConfigGame.astro | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/src/components/ConfigGame.astro b/src/components/ConfigGame.astro index e33f6b5..948014e 100644 --- a/src/components/ConfigGame.astro +++ b/src/components/ConfigGame.astro @@ -16,10 +16,10 @@ const { minPlayers = 3, serverError } = Astro.props;
-

Configuración

+

Configuración

Añade al menos {minPlayers} jugadores

@@ -47,7 +47,9 @@ const { minPlayers = 3, serverError } = Astro.props;