Skip to content

Commit

Permalink
fix: username field disabled problem
Browse files Browse the repository at this point in the history
  • Loading branch information
gdsc0301 committed Jul 4, 2023
1 parent cb06a14 commit 326d439
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<canvas id="app" width="640" height="360"></canvas>
<form id="loginForm">
<input type="text" placeholder="ip-address:port" value="https://best-multiplayer-game-possible-pvenbf56dq-uc.a.run.app/" readonly disabled>
<input type="text" autocomplete="false"><input type="submit" value="GO!">
<input type="text" autocomplete="false" placeholder="Your username"><input type="submit" value="GO!">
<span class="error"></span>
</form>
<script type="module" src="./src/index.js"></script>
Expand Down
12 changes: 6 additions & 6 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,22 @@ let currentRoom;

let gameplayLoop;
function init() {
welcomeMessage.innerHTML = 'Insert the IP address and username to start';
welcomeMessage.innerHTML = 'Insert your username to start';

loginForm.addEventListener('submit', e => {
e.preventDefault();

server.ipAddress = e.target.elements[0].value;
const username = e.target.elements[1].value;

Object.keys(e.target.elements).forEach(elm => {
e.target.elements[elm].setAttribute('disabled', '');
})

if(server.URL && username) {
fetch(`${server.URL}/login?player_email=${encodeURIComponent(username)}`).then(res => {
res.json().then(body => {
if(body?.status === 200) {
Object.keys(e.target.elements).forEach(elm => {
e.target.elements[elm].setAttribute('disabled', '');
});

canvas.focus({preventScroll: true});
emailErrorField.classList.remove('active');

Expand Down

0 comments on commit 326d439

Please sign in to comment.