Skip to content

Commit ec928e8

Browse files
authored
Merge pull request #30 from LENpolygon/votingSystem
Voting system
2 parents 24d2454 + 53212f5 commit ec928e8

File tree

6 files changed

+77
-12
lines changed

6 files changed

+77
-12
lines changed

public/css/global.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ section {
191191

192192
.icon {
193193
cursor: move;
194-
height: 4.8rem;
194+
width: 4.8rem;
195195
margin: 0.2rem;
196196
max-height: 4.8rem;
197197
max-width: 4.8rem;

public/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ <h4 id="civilizationFocus"></h4>
168168
</article>
169169
</main>
170170
<footer>
171-
age4builder.com v0.9.1 for the latest Age of Empires instalment. Copyright 2022 <a target="_blank"
171+
age4builder.com v0.9.3 for the latest Age of Empires instalment. Copyright 2022 <a target="_blank"
172172
rel="noopener" data-track-outgoing="true" href="http://lenpolygon.com">LEN polygon</a>.
173173
Age of Empires IV and all its icons, artwork, and flair are property of Relic Entertainment, World's Edge &
174174
Xbox Game Studios. This website is for educational purposes only.

public/js/build.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,7 @@ async function GetYourBuilds(uid) {
487487
// doc.data() is never undefined for query doc snapshots
488488
var docId = doc.id;
489489
var docData = doc.data();
490-
html += `<tr><td><a href="#" class="delete-builds" bid="${docId}" style="color: red">Delete Build?</a></td>`;
490+
html += `<tr><td><a href="#" class="delete-builds" bid="${docId}" style="color: red" onmouseover="this.style['text-decoration']='underline';" onmouseout="this.style['text-decoration']='none';">Delete Build?</a></td>`;
491491
html += "<td><img src=\"img/flag" + docData.civ + ".png\" height=\"24\" onerror=\"this.src = 'assets/placeholder.png';\"><a href=\"view.html?f=" + docId + "\"></img> " + escapeHtml(docData.title).substring(0, titleLength) + " (by " + escapeHtml(docData.user).substring(0, nameLength) + ")</a></td></tr>";
492492
});
493493
document.querySelector('#yourBuilds').innerHTML = `
@@ -502,13 +502,14 @@ async function GetYourBuilds(uid) {
502502
${html}
503503
</tbody>
504504
</table>
505-
<p style="color: red">Deleting builds cannot be undone! Click once, then refresh page and your build is gone!</p>
505+
<p style="color: red">Deleting builds cannot be undone!!</p>
506506
`
507507
const deleteYourDocs = document.querySelectorAll('.delete-builds');
508508
deleteYourDocs.forEach(link => {
509509
link.addEventListener('click', (e) => {
510510
//console.log(link.getAttribute('bid'));
511511
deleteDoc(doc(db, "Age4Builds", link.getAttribute('bid')));
512+
location.reload();
512513
})
513514
});
514515
}
@@ -605,6 +606,7 @@ auth.onAuthStateChanged(user => {
605606
version: save[1],
606607
patch: "14681",
607608
likers: [],
609+
dislikers: [],
608610
likes: parseInt(document.getElementById("scoreU").value),
609611
option: document.getElementById("optionsU").value,
610612
score: 30

public/js/index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ async function GetYourBuilds(uid) {
173173
// doc.data() is never undefined for query doc snapshots
174174
var docId = doc.id;
175175
var docData = doc.data();
176-
html += `<tr><td><a href="#" class="delete-builds" bid="${docId}" style="color: red">Delete Build?</a></td>`;
176+
html += `<tr><td><a href="#" class="delete-builds" bid="${docId}" style="color: red" onmouseover="this.style['text-decoration']='underline';" onmouseout="this.style['text-decoration']='none';">Delete Build?</a></td>`;
177177
html += "<td><img src=\"img/flag" + docData.civ + ".png\" height=\"24\" onerror=\"this.src = 'assets/placeholder.png';\"><a href=\"view.html?f=" + docId + "\"></img> " + escapeHtml(docData.title).substring(0, titleLength) + " (by " + escapeHtml(docData.user).substring(0, nameLength) + ")</a></td></tr>";
178178
});
179179
document.querySelector('#yourBuilds').innerHTML = `
@@ -188,13 +188,14 @@ async function GetYourBuilds(uid) {
188188
${html}
189189
</tbody>
190190
</table>
191-
<p style="color: red">Deleting builds cannot be undone! Click once, then refresh page and your build is gone!</p>
191+
<p style="color: red">Deleting builds cannot be undone!!</p>
192192
`
193193
const deleteYourDocs = document.querySelectorAll('.delete-builds');
194194
deleteYourDocs.forEach(link => {
195195
link.addEventListener('click', (e) => {
196196
//console.log(link.getAttribute('bid'));
197197
deleteDoc(doc(db, "Age4Builds", link.getAttribute('bid')));
198+
location.reload();
198199
})
199200
});
200201
}

public/js/view.js

Lines changed: 64 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const loadLimit = 20;
2121
const titleLength = 48;
2222
const nameLength = 24;
2323
var usp = new URLSearchParams(window.location.search);
24-
import { initializeApp } from "https://www.gstatic.com/firebasejs/9.8.1/firebase-app.js"; import firebaseConfig from '../json/fs.js'; const app = initializeApp(firebaseConfig);
24+
import { initializeApp } from "https://www.gstatic.com/firebasejs/9.8.1/firebase-app.js"; import firebaseConfig from '../json/fs.js'; const app = initializeApp(firebaseConfig);
2525
import { getFirestore, doc, getDoc, setDoc, getDocs, collection, deleteDoc, query, updateDoc, addDoc, where, orderBy, limit } from "https://www.gstatic.com/firebasejs/9.8.1/firebase-firestore.js"; const db = getFirestore();
2626
import { getAuth, createUserWithEmailAndPassword, signInWithEmailAndPassword } from "https://www.gstatic.com/firebasejs/9.8.1/firebase-auth.js"; const auth = getAuth();
2727
if (isNaN(usp.get("f"))) { // Update View counter
@@ -32,7 +32,7 @@ if (isNaN(usp.get("f"))) { // Update View counter
3232
//console.log(docData.timestamp);
3333
//console.log(Date.now());
3434
//console.log((Date.now()-docData.timestamp)/(1000*60*60*24));
35-
var newScore = Math.max(docData.score - 10, Math.min(docData.score + 10, docData.views + docData.likes * 10 - Math.pow(Math.floor((Date.now() - docData.timestamp) / (1000 * 60 * 60 * 24)),1.337)));
35+
var newScore = Math.max(docData.score - 10, Math.min(docData.score + 10, docData.views + Math.pow(docData.likes * 10, 1.069) - Math.pow(Math.floor((Date.now() - docData.timestamp) / (1000 * 60 * 60 * 24)), 1.337)));
3636
await updateDoc(
3737
ref, {
3838
views: docData.views + 1,
@@ -256,6 +256,63 @@ if (isNaN(usp.get("f"))) { // Update View counter
256256
document.getElementById("copyForOverlayBtn").addEventListener("click", copyForOverlay);
257257
document.getElementById("copyForOverlayBtnMobile").addEventListener("click", copyForOverlay);
258258

259+
//////////////////////////////////////////////////
260+
// UPVOTE / DOWNVOTE SYSTEM
261+
//////////////////////////////////////////////////
262+
const usr = auth.currentUser;
263+
if (usr != null) {
264+
var liked = false;
265+
var disliked = false;
266+
var newDislikers = [];
267+
if (docData.likers.includes(usr.uid)) {
268+
liked = true;
269+
} else if (docData.hasOwnProperty("dislikers")) {
270+
newDislikers = docData.dislikers;
271+
if (docData.dislikers.includes(usr.uid)) {
272+
disliked = true;
273+
}
274+
}
275+
if (liked == false) {
276+
document.querySelector('#upvote').addEventListener('click', (e) => {
277+
var newLikers = docData.likers;
278+
newLikers.push(usr.uid);
279+
var newLikes = docData.likes + 1;
280+
if (disliked == true) {
281+
newDislikers = newDislikers.filter(item => item !== usr.uid)
282+
newLikes += 1;
283+
}
284+
return updateDoc(
285+
ref, {
286+
likers: newLikers,
287+
dislikers: newDislikers,
288+
likes: newLikes
289+
}).catch((error) => {
290+
console.log("Unsuccesful operation, error: " + error);
291+
});
292+
});
293+
}
294+
if (disliked == false) {
295+
document.querySelector('#downvote').addEventListener('click', (e) => {
296+
297+
newDislikers.push(usr.uid);
298+
var newLikes = docData.likes - 1;
299+
var newLikers = docData.likers;
300+
if (liked == true) {
301+
newLikers = newLikers.filter(item => item !== usr.uid)
302+
newLikes -= 1;
303+
}
304+
return updateDoc(
305+
ref, {
306+
likers: newLikers,
307+
dislikers: newDislikers,
308+
likes: newLikes
309+
}).catch((error) => {
310+
console.log("Unsuccesful operation, error: " + error);
311+
});
312+
});
313+
}
314+
}
315+
259316
//////////////////////////////////////////////////
260317
// READ json/icons.json data
261318
//////////////////////////////////////////////////
@@ -385,7 +442,7 @@ async function GetYourBuilds(uid) {
385442
// doc.data() is never undefined for query doc snapshots
386443
var docId = doc.id;
387444
var docData = doc.data();
388-
html += `<tr><td><a href="#" class="delete-builds" bid="${docId}" style="color: red">Delete Build?</a></td>`;
445+
html += `<tr><td><a href="#" class="delete-builds" bid="${docId}" style="color: red" onmouseover="this.style['text-decoration']='underline';" onmouseout="this.style['text-decoration']='none';">Delete Build?</a></td>`;
389446
html += "<td><img src=\"img/flag" + docData.civ + ".png\" height=\"24\" onerror=\"this.src = 'assets/placeholder.png';\"><a href=\"view.html?f=" + docId + "\"></img> " + escapeHtml(docData.title).substring(0, titleLength) + " (by " + escapeHtml(docData.user).substring(0, nameLength) + ")</a></td></tr>";
390447
});
391448
document.querySelector('#yourBuilds').innerHTML = `
@@ -400,13 +457,14 @@ async function GetYourBuilds(uid) {
400457
${html}
401458
</tbody>
402459
</table>
403-
<p style="color: red">Deleting builds cannot be undone! Click once, then refresh page and your build is gone!</p>
460+
<p style="color: red">Deleting builds cannot be undone!!</p>
404461
`
405462
const deleteYourDocs = document.querySelectorAll('.delete-builds');
406463
deleteYourDocs.forEach(link => {
407464
link.addEventListener('click', (e) => {
408465
//console.log(link.getAttribute('bid'));
409466
deleteDoc(doc(db, "Age4Builds", link.getAttribute('bid')));
467+
location.reload();
410468
})
411469
});
412470
}
@@ -492,4 +550,5 @@ const setupUI = (user) => {
492550
document.addEventListener('DOMContentLoaded', function () {
493551
var modals = document.querySelectorAll('.modal');
494552
M.Modal.init(modals);
495-
});
553+
});
554+

public/view.html

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,9 @@ <h2 class="title gold">Account details</h2><br />
134134
<h1 id="civilizationName"></h1>
135135
<h4 id="civilizationFocus"></h4>
136136
</div>
137+
<h3 class="logged-out" style="text-align: right; margin-right: 1rem;">only <span class="gold">logged in users</span> can<br/><span class="gold">vote</span> for this build order</h3>
138+
<h2 class="logged-in" style="text-align: right; margin-right: 1rem;">Vote:</h2>
139+
<h3 class="logged-in" style="text-align: right; margin-right: 1rem;"><a href="#" class="gold" id="upvote" onmouseover="this.style['text-decoration']='underline';" onmouseout="this.style['text-decoration']='none';">++ good build order</a><br/><a href="#" style="color:crimson" id="downvote" onmouseover="this.style['text-decoration']='underline';" onmouseout="this.style['text-decoration']='none';">---&nbsp;&nbsp;&nbsp;bad build order</a></h3>
137140
</div>
138141
<table id="buildTable">
139142
<thead>
@@ -169,7 +172,7 @@ <h4 id="civilizationFocus"></h4>
169172
<div class="push"></div>
170173
</main>
171174
<footer>
172-
age4builder.com v0.9.1 for the latest Age of Empires instalment. Copyright 2022 <a target="_blank" rel="noopener"
175+
age4builder.com v0.9.3 for the latest Age of Empires instalment. Copyright 2022 <a target="_blank" rel="noopener"
173176
data-track-outgoing="true" href="http://lenpolygon.com">LEN polygon</a>.
174177
Age of Empires IV and all its icons, artwork, and flair are property of Relic Entertainment, World's Edge &
175178
Xbox Game Studios. This website is for educational purposes only.

0 commit comments

Comments
 (0)