mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2025-02-05 05:17:51 +08:00
replaced all the active page class checks with a stored variable of which page is active
This commit is contained in:
parent
1dc22c6fa6
commit
a7f5f1dc35
8 changed files with 48 additions and 29 deletions
|
@ -64,7 +64,7 @@ const authListener = firebase.auth().onAuthStateChanged(async function (user) {
|
|||
await loadUser(user);
|
||||
} else {
|
||||
UI.setPageTransition(false);
|
||||
if ($(".pageLoading").hasClass("active")) UI.changePage("");
|
||||
if (UI.getActivePage() == "pageLoading") UI.changePage("");
|
||||
}
|
||||
let theme = Misc.findGetParameter("customTheme");
|
||||
if (theme !== null) {
|
||||
|
@ -278,11 +278,15 @@ export function linkWithGoogle() {
|
|||
}
|
||||
|
||||
export function unlinkGoogle() {
|
||||
firebase.auth().currentUser.unlink("google.com").then((result) => {
|
||||
console.log(result);
|
||||
}).catch((error) => {
|
||||
console.log(error);
|
||||
});
|
||||
firebase
|
||||
.auth()
|
||||
.currentUser.unlink("google.com")
|
||||
.then((result) => {
|
||||
console.log(result);
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log(error);
|
||||
});
|
||||
}
|
||||
|
||||
export function linkWithEmail(email, password) {
|
||||
|
|
|
@ -54,11 +54,11 @@ export async function getDataAndInit() {
|
|||
|
||||
// $("#top #menu .account .icon").html('<i class="fas fa-fw fa-times"></i>');
|
||||
$("#top #menu .account").css("opacity", 1);
|
||||
if ($(".pageLoading").hasClass("active")) UI.changePage("");
|
||||
if (UI.getActivePage() == "pageLoading") UI.changePage("");
|
||||
AccountController.signOut();
|
||||
return;
|
||||
}
|
||||
if ($(".pageLoading").hasClass("active")) {
|
||||
if (UI.getActivePage() == "pageLoading") {
|
||||
LoadingPage.updateBar(90);
|
||||
} else {
|
||||
LoadingPage.updateBar(65.9);
|
||||
|
@ -139,8 +139,6 @@ export async function getDataAndInit() {
|
|||
}
|
||||
}
|
||||
}
|
||||
// if($(".pageAccount").hasClass('active')) update();
|
||||
// if ($(".pageLogin").hasClass("active")) UI.changePage("account");
|
||||
if (!UpdateConfig.changedBeforeDb) {
|
||||
//config didnt change before db loaded
|
||||
if (Config.localStorageConfig === null) {
|
||||
|
@ -192,7 +190,7 @@ export async function getDataAndInit() {
|
|||
UpdateConfig.apply(DB.getSnapshot().config);
|
||||
Settings.update();
|
||||
UpdateConfig.saveToLocalStorage(true);
|
||||
if ($(".page.pageTest").hasClass("active")) {
|
||||
if (UI.getActivePage() == "pageTest") {
|
||||
TestLogic.restart(false, true);
|
||||
}
|
||||
DB.saveConfig(Config);
|
||||
|
@ -209,7 +207,7 @@ export async function getDataAndInit() {
|
|||
}
|
||||
}
|
||||
if (
|
||||
$(".pageLogin").hasClass("active") ||
|
||||
UI.getActivePage() == "pageLogin" ||
|
||||
window.location.pathname === "/account"
|
||||
) {
|
||||
UI.changePage("account");
|
||||
|
@ -223,7 +221,7 @@ export async function getDataAndInit() {
|
|||
Settings.showAccountSection();
|
||||
UI.setPageTransition(false);
|
||||
console.log("account loading finished");
|
||||
if ($(".pageLoading").hasClass("active")) {
|
||||
if (UI.getActivePage() == "pageLoading") {
|
||||
LoadingPage.updateBar(100);
|
||||
UI.changePage("");
|
||||
} else {
|
||||
|
|
|
@ -139,7 +139,7 @@ export function verify(result) {
|
|||
|
||||
export async function setup(challengeName) {
|
||||
challengeLoading = true;
|
||||
if (!$(".page.pageTest").hasClass("active")) {
|
||||
if (UI.getActivePage() !== "pageTest") {
|
||||
UI.changePage("", true);
|
||||
}
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@ import * as Notifications from "./notifications";
|
|||
import axiosInstance from "./axios-instance";
|
||||
import * as TodayTracker from "./today-tracker";
|
||||
import * as LoadingPage from "./loading-page";
|
||||
import * as UI from "./ui";
|
||||
|
||||
let dbSnapshot = null;
|
||||
|
||||
|
@ -52,7 +53,7 @@ export async function initSnapshot() {
|
|||
let snap = defaultSnap;
|
||||
try {
|
||||
if (firebase.auth().currentUser == null) return false;
|
||||
if ($(".pageLoading").hasClass("active")) {
|
||||
if (UI.getActivePage() == "pageLoading") {
|
||||
LoadingPage.updateBar(18);
|
||||
} else {
|
||||
LoadingPage.updateBar(13.3);
|
||||
|
@ -81,7 +82,7 @@ export async function initSnapshot() {
|
|||
} else if (userData.lbMemory) {
|
||||
snap.lbMemory = userData.lbMemory;
|
||||
}
|
||||
if ($(".pageLoading").hasClass("active")) {
|
||||
if (UI.getActivePage() == "pageLoading") {
|
||||
LoadingPage.updateBar(36);
|
||||
} else {
|
||||
LoadingPage.updateBar(26.6);
|
||||
|
@ -92,7 +93,7 @@ export async function initSnapshot() {
|
|||
if (configData) {
|
||||
snap.config = configData.config;
|
||||
}
|
||||
if ($(".pageLoading").hasClass("active")) {
|
||||
if (UI.getActivePage() == "pageLoading") {
|
||||
LoadingPage.updateBar(54);
|
||||
} else {
|
||||
LoadingPage.updateBar(39.9);
|
||||
|
@ -109,7 +110,7 @@ export async function initSnapshot() {
|
|||
return 0;
|
||||
}
|
||||
});
|
||||
if ($(".pageLoading").hasClass("active")) {
|
||||
if (UI.getActivePage() == "pageLoading") {
|
||||
LoadingPage.updateBar(72);
|
||||
} else {
|
||||
LoadingPage.updateBar(52.6);
|
||||
|
|
|
@ -599,9 +599,9 @@ function handleTab(event) {
|
|||
$("#commandLineWrapper").hasClass("hidden") &&
|
||||
$("#simplePopupWrapper").hasClass("hidden") &&
|
||||
$("#quoteSubmitPopupWrapper").hasClass("hidden") &&
|
||||
!$(".page.pageLogin").hasClass("active")
|
||||
UI.getActivePage() != "pageLogin"
|
||||
) {
|
||||
if ($(".pageTest").hasClass("active")) {
|
||||
if (UI.getActivePage() == "pageTest") {
|
||||
if (Config.quickTab) {
|
||||
if (
|
||||
TestUI.resultVisible ||
|
||||
|
@ -651,7 +651,7 @@ function handleTab(event) {
|
|||
}
|
||||
|
||||
$(document).keydown((event) => {
|
||||
if ($(".pageLoading").hasClass("active")) return event.preventDefault();
|
||||
if (UI.getActivePage() == "pageLoading") return event.preventDefault();
|
||||
|
||||
//autofocus
|
||||
const wordsFocused = $("#wordsInput").is(":focus");
|
||||
|
|
|
@ -18,6 +18,7 @@ export function handleInitialPageClasses(pathname) {
|
|||
let el = $(".page." + mappedRoutes[pathname]);
|
||||
$(el).removeClass("hidden");
|
||||
$(el).addClass("active");
|
||||
UI.setActivePage(mappedRoutes[pathname]);
|
||||
}
|
||||
|
||||
(function (history) {
|
||||
|
|
|
@ -466,7 +466,7 @@ export function restart(
|
|||
} catch {}
|
||||
return;
|
||||
}
|
||||
if ($(".pageTest").hasClass("active") && !TestUI.resultVisible) {
|
||||
if (UI.getActivePage() == "pageTest" && !TestUI.resultVisible) {
|
||||
if (!ManualRestart.get()) {
|
||||
if (hasTab) {
|
||||
try {
|
||||
|
@ -1089,7 +1089,7 @@ export async function init() {
|
|||
// $("#words").css("height", "auto");
|
||||
// $("#wordsWrapper").css("height", "auto");
|
||||
// } else {
|
||||
if ($(".pageTest").hasClass("active")) {
|
||||
if (UI.getActivePage() == "pageTest") {
|
||||
await Funbox.activate();
|
||||
}
|
||||
TestUI.showWords();
|
||||
|
|
27
src/js/ui.js
27
src/js/ui.js
|
@ -14,8 +14,18 @@ import * as Settings from "./settings";
|
|||
import * as Account from "./account";
|
||||
import * as Leaderboards from "./leaderboards";
|
||||
import * as Funbox from "./funbox";
|
||||
import { active } from "./challenge-controller";
|
||||
|
||||
export let pageTransition = true;
|
||||
let activePage = "pageLoading";
|
||||
|
||||
export function getActivePage() {
|
||||
return activePage;
|
||||
}
|
||||
|
||||
export function setActivePage(active) {
|
||||
activePage = active;
|
||||
}
|
||||
|
||||
export function setPageTransition(val) {
|
||||
pageTransition = val;
|
||||
|
@ -113,19 +123,20 @@ export function changePage(page, norestart = false) {
|
|||
return;
|
||||
}
|
||||
console.log(`change page ${page}`);
|
||||
let activePage = $(".page.active");
|
||||
let activePageElement = $(".page.active");
|
||||
$(".page").removeClass("active");
|
||||
$("#wordsInput").focusout();
|
||||
if (page == "test" || page == "") {
|
||||
setPageTransition(true);
|
||||
swapElements(
|
||||
activePage,
|
||||
activePageElement,
|
||||
$(".page.pageTest"),
|
||||
250,
|
||||
() => {
|
||||
setPageTransition(false);
|
||||
TestUI.focusWords();
|
||||
$(".page.pageTest").addClass("active");
|
||||
activePage = "pageTest";
|
||||
history.pushState("/", null, "/");
|
||||
},
|
||||
() => {
|
||||
|
@ -142,10 +153,11 @@ export function changePage(page, norestart = false) {
|
|||
} else if (page == "about") {
|
||||
setPageTransition(true);
|
||||
TestLogic.restart();
|
||||
swapElements(activePage, $(".page.pageAbout"), 250, () => {
|
||||
swapElements(activePageElement, $(".page.pageAbout"), 250, () => {
|
||||
setPageTransition(false);
|
||||
history.pushState("about", null, "about");
|
||||
$(".page.pageAbout").addClass("active");
|
||||
activePage = "pageAbout";
|
||||
});
|
||||
Funbox.activate("none");
|
||||
TestConfig.hide();
|
||||
|
@ -153,10 +165,11 @@ export function changePage(page, norestart = false) {
|
|||
} else if (page == "settings") {
|
||||
setPageTransition(true);
|
||||
TestLogic.restart();
|
||||
swapElements(activePage, $(".page.pageSettings"), 250, () => {
|
||||
swapElements(activePageElement, $(".page.pageSettings"), 250, () => {
|
||||
setPageTransition(false);
|
||||
history.pushState("settings", null, "settings");
|
||||
$(".page.pageSettings").addClass("active");
|
||||
activePage = "pageSettings";
|
||||
});
|
||||
Funbox.activate("none");
|
||||
Settings.update();
|
||||
|
@ -172,13 +185,14 @@ export function changePage(page, norestart = false) {
|
|||
setPageTransition(true);
|
||||
TestLogic.restart();
|
||||
swapElements(
|
||||
activePage,
|
||||
activePageElement,
|
||||
$(".page.pageAccount"),
|
||||
250,
|
||||
() => {
|
||||
setPageTransition(false);
|
||||
history.pushState("account", null, "account");
|
||||
$(".page.pageAccount").addClass("active");
|
||||
activePage = "pageAccount";
|
||||
},
|
||||
() => {
|
||||
SignOutButton.show();
|
||||
|
@ -194,10 +208,11 @@ export function changePage(page, norestart = false) {
|
|||
} else {
|
||||
setPageTransition(true);
|
||||
TestLogic.restart();
|
||||
swapElements(activePage, $(".page.pageLogin"), 250, () => {
|
||||
swapElements(activePageElement, $(".page.pageLogin"), 250, () => {
|
||||
setPageTransition(false);
|
||||
history.pushState("login", null, "login");
|
||||
$(".page.pageLogin").addClass("active");
|
||||
activePage = "pageLogin";
|
||||
});
|
||||
Funbox.activate("none");
|
||||
TestConfig.hide();
|
||||
|
|
Loading…
Reference in a new issue