diff --git a/src/scss/_root.scss b/src/scss/_root.scss index 0600888..c085344 100644 --- a/src/scss/_root.scss +++ b/src/scss/_root.scss @@ -91,7 +91,7 @@ body > section { } .pointer { - cursor: pointer!important; + cursor: pointer !important; } .place-items-end { diff --git a/src/ts/api.ts b/src/ts/api.ts index bace568..99b824a 100644 --- a/src/ts/api.ts +++ b/src/ts/api.ts @@ -4,9 +4,9 @@ import { userScore } from "./functions"; const location = window.location.hostname; const apiURL = - "https://script.google.com/macros/s/AKfycbz8vXR3g9KmyXHVlxFcLfcJn6yEYdX96PKEyPf8vFRuhgCfqkhThgegD48Az1fpMOdncg/exec"; + "https://script.google.com/macros/s/AKfycbzUSI74vHRuJQev7m0X2Bf5pG97hYvY3Vwroi3dpOL1OgMf1JM7F62YT06bqgrLQgoNSQ/exec"; -export const localStorageKey = "app-user-details"; +export const localStorageKey = "maths-quiz-v2"; export function register(username: string) { @@ -92,7 +92,8 @@ export async function updateScore() { } export async function getLeaderboardScores() { - const request = await fetch(apiURL); + const url = apiURL + "?limit=10"; + const request = await fetch(url); const data: IAPIData = await request.json(); return data.data; } diff --git a/src/ts/eventHandlers.ts b/src/ts/eventHandlers.ts index 02120c1..6706b64 100644 --- a/src/ts/eventHandlers.ts +++ b/src/ts/eventHandlers.ts @@ -1,4 +1,3 @@ -import { IUserData } from "@/interface/ILocalStorage"; import { getLocalStorageData, register } from "./api"; import { createQuestion, @@ -46,7 +45,7 @@ import { startBtn.onclick = () => { start_div.classList.remove("active"); - const dataObj = JSON.parse(localStorage.getItem("app-user-details")!); + const dataObj = getLocalStorageData(); if (dataObj && dataObj.name) info_box_div.classList.add("active"); else register_box_div.classList.add("active"); @@ -61,9 +60,7 @@ leaderboardBtn.onclick = () => { }; userDetailsBtn.onclick = () => { - const dataObj: IUserData = JSON.parse( - localStorage.getItem("app-user-details")! - ); + const dataObj = getLocalStorageData(); if (!(dataObj && dataObj.name)) return register_box_div.classList.add("active"); diff --git a/src/ts/functions.ts b/src/ts/functions.ts index c4a3ef7..f4c9eb6 100644 --- a/src/ts/functions.ts +++ b/src/ts/functions.ts @@ -1,6 +1,6 @@ import { IUserData } from "@/interface/ILocalStorage"; import rankListTemplate from "../template/rankListTemplate"; -import { getLeaderboardScores, updateScore } from "./api"; +import { getLeaderboardScores, getLocalStorageData, updateScore } from "./api"; import { averageScoreText, completeText, @@ -103,10 +103,9 @@ export function showResultBox() { scoreText.innerText = `You got ${userScore} Points`; changeResultText(); - var dataStr = localStorage.getItem("app-user-details"); - if (!dataStr) return; + var data = getLocalStorageData(); + if (!data) return; - var data: IUserData = JSON.parse(dataStr); highScoreText.innerText = String(data.highscore); } @@ -147,7 +146,7 @@ function addZeroToSingleDigit(num: number) { } function changeResultText() { - // TODO: Adding different text for different situations + // TODO: Adding different text message for different situations completeText.innerText = `You've completed The Quiz`; }