Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature #3

Merged
merged 3 commits into from
Mar 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 22 additions & 2 deletions dist/index.bundle.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

51 changes: 25 additions & 26 deletions dist/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,32 @@
<title>Leaderboard</title>
<script defer src="index.bundle.js"></script></head>
<body>
<header>
<h1>Leaderboard</h1>
</header>
<div class="wrapper">
<section id="score-table">
<div class="head">
<h2>Recent Scores</h2>
<button id="refresh" type="button">Refresh</button>
<div class="container">
<header>
<h1 class="neonText">Arcade Leaderboard</h1>
</header>
<div class="wrapper">
<section id="points-table">
<div class="head">
<h2>Recent Points</h2>
<button id="refresh-btn" type="button">Refresh</button>
</div>
<ul class="points">
</ul>
</section>
<section id="add">
<div class="add-heading">
<h2>Add your Points</h2>
</div>
<form class="add-input">
<label for="name"></label>
<input required type="text" id="name" name="name" placeholder="Your Name">
<label for="score"></label>
<input required type="number" id="score" name="score" placeholder="Your Points" >
<button type="submit" id="submit-btn">Add Score</button>
</form>
</section>
</div>
<ul class="scores-list">
<li class="list-item">
<p class="player">Thiago:</p>
<p class="score-number">10</p>
</li>
</ul>
</section>
<section id="add">
<div class="add-heading">
<h2>Add your Score</h2>
</div>
<form class="add-input">
<input required type="text" id="name" name="name" placeholder="Your name" class="input">
<input required type="number" id="score" name="score" placeholder="Your score" class="input">
<button type="submit" id="submit-btn">Submit</button>
<p></p>
</form>
</section>
</div>
</body>
</html>
4 changes: 2 additions & 2 deletions src/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
padding: 50px;
}

#score-table {
#points-table {
display: flex;
flex-direction: column;
justify-content: center;
Expand All @@ -26,7 +26,7 @@
gap: 10px;
}

#refresh {
#refresh-btn {
padding: 0;
width: 150px;
height: 20px;
Expand Down
53 changes: 26 additions & 27 deletions src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,32 @@
<title>Leaderboard</title>
</head>
<body>
<header>
<h1>Leaderboard</h1>
</header>
<div class="wrapper">
<section id="score-table">
<div class="head">
<h2>Recent Scores</h2>
<button id="refresh" type="button">Refresh</button>
</div>
<ul class="scores-list">
<li class="list-item">
<p class="player">Thiago:</p>
<p class="score-number">10</p>
</li>
</ul>
</section>
<section id="add">
<div class="add-heading">
<h2>Add your Score</h2>
</div>
<form class="add-input">
<input required type="text" id="name" name="name" placeholder="Your name" class="input">
<input required type="number" id="score" name="score" placeholder="Your score" class="input">
<button type="submit" id="submit-btn">Submit</button>
<p></p>
</form>
</section>
<div class="container">
<header>
<h1 class="neonText">Arcade Leaderboard</h1>
</header>
<div class="wrapper">
<section id="points-table">
<div class="head">
<h2>Recent Points</h2>
<button id="refresh-btn" type="button">Refresh</button>
</div>
<ul class="points">
</ul>
</section>
<section id="add">
<div class="add-heading">
<h2>Add your Points</h2>
</div>
<form class="add-input">
<label for="name"></label>
<input required type="text" id="name" name="name" placeholder="Your Name">
<label for="score"></label>
<input required type="number" id="score" name="score" placeholder="Your Points" >
<button type="submit" id="submit-btn">Add Score</button>
</form>
</section>
</div>
</div>
</body>
</html>
26 changes: 25 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
@@ -1 +1,25 @@
import './index.css';
import './index.css';
import * as app from './modules/app.js';

const inputName = document.getElementById('name');
const inputScore = document.getElementById('score');
const submitBtn = document.getElementById('submit-btn');
const refreshBtn = document.getElementById('refresh-btn');

submitBtn.addEventListener('click', (e) => {
e.preventDefault();
app.add({ user: inputName.value, score: inputScore.value });
inputScore.value = '';
inputName.value = '';
setTimeout(() => {
refreshBtn.click();
}, 1500);
});

refreshBtn.addEventListener('click', () => {
app.show();
});

window.addEventListener('load', () => {
app.show();
});
23 changes: 23 additions & 0 deletions src/modules/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import * as projectAPI from './projectAPI.js';

const show = () => {
const pointsTable = document.querySelector('.points');
pointsTable.innerHTML = '';
projectAPI.getData().then((dataList) => {
if (!dataList) {
return;
}
const higherFirst = dataList.result.sort((a, b) => b.score - a.score);
higherFirst.forEach((data) => {
const li = document.createElement('li');
li.innerHTML = `<p class="text-y">${data.user}: ${data.score}</p>`;
pointsTable.appendChild(li);
});
});
};

const add = (data) => {
projectAPI.setData(data.user, data.score);
};

export { add, show };
20 changes: 20 additions & 0 deletions src/modules/projectAPI.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const baseURL = 'https://us-central1-js-capstone-backend.cloudfunctions.net/api/games';
const currentGameID = 'MWUpUmiHxzETYYcYdFqF';

const setData = async (userName, userScore) => {
const connect = await fetch(`${baseURL}/${currentGameID}/scores`, {
method: 'POST',
body: JSON.stringify({ user: userName, score: userScore }),
headers: { 'Content-type': 'application/JSON' },
});
const receivedData = await connect.json();
return receivedData;
};

const getData = async () => {
const connect = await fetch(`${baseURL}/${currentGameID}/scores`);
const scoreList = await connect.json();
return scoreList;
};

export { getData, setData };