diff --git a/pages/index.js b/pages/index.js index 57f5301..4a3e9a4 100644 --- a/pages/index.js +++ b/pages/index.js @@ -12,37 +12,37 @@ const Home = ({ loading }) => { const router = useRouter(); const [newGameLoading, setNewGameLoading] = useState(false); const t = useI18n(); - // const onNewGame = async (e) => { - // e.preventDefault(); - // setNewGameLoading(true); + const onNewGame = async (e) => { + e.preventDefault(); + setNewGameLoading(true); - // try { - // const res = await fetch(window.location.origin + "/new", { - // method: "POST", - // headers: { - // Accept: "application/json", - // "Content-Type": "application/json", - // }, - // body: JSON.stringify({ name }), - // }); + try { + const res = await fetch(window.location.origin + "/new", { + method: "POST", + headers: { + Accept: "application/json", + "Content-Type": "application/json", + }, + body: JSON.stringify({ name }), + }); - // if (res.status === 200) { - // const { gameCode } = await res.json(); - // router.push("/" + gameCode); - // } else if (res.status === 423) { - // const { minutes } = await res.json(); - // setNewGameLoading(false); + if (res.status === 200) { + const { gameCode } = await res.json(); + router.push("/" + gameCode); + } else if (res.status === 423) { + const { minutes } = await res.json(); + setNewGameLoading(false); - // Swal.fire(lockedMessage(minutes)); - // } else { - // throw res.status + " " + res.statusText; - // } - // } catch (error) { - // console.error(error); - // Swal.fire(error); - // setNewGameLoading(false); - // } - // }; + Swal.fire(lockedMessage(minutes)); + } else { + throw res.status + " " + res.statusText; + } + } catch (error) { + console.error(error); + Swal.fire(error); + setNewGameLoading(false); + } + }; return (
@@ -62,16 +62,14 @@ const Home = ({ loading }) => { {!loading && ( <>
- + - - - +

Powered by 🚀🦀