Skip to content

Commit

Permalink
api upgraded to v5
Browse files Browse the repository at this point in the history
  • Loading branch information
Blank-09 committed Sep 8, 2022
1 parent 1bd48e8 commit b4b5173
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/scss/_root.scss
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ body > section {
}

.pointer {
cursor: pointer!important;
cursor: pointer !important;
}

.place-items-end {
Expand Down
7 changes: 4 additions & 3 deletions src/ts/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
}
Expand Down
7 changes: 2 additions & 5 deletions src/ts/eventHandlers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { IUserData } from "@/interface/ILocalStorage";
import { getLocalStorageData, register } from "./api";
import {
createQuestion,
Expand Down Expand Up @@ -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");
Expand All @@ -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");
Expand Down
9 changes: 4 additions & 5 deletions src/ts/functions.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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`;
}

Expand Down

0 comments on commit b4b5173

Please sign in to comment.