diff --git a/src/js/account.js b/src/js/account.js index 38693f110..6462fac34 100644 --- a/src/js/account.js +++ b/src/js/account.js @@ -136,8 +136,8 @@ firebase.auth().onAuthStateChanged(function (user) { `

Your account is not verified. Click here to resend the verification email.` ); } - updateAccountLoginButton(); - AccountIcon.loading(true); + AccountButton.updateAccountLoginButton(); + AccountButton.loading(true); getAccountDataAndInit(); var displayName = user.displayName; // var email = user.email; @@ -249,7 +249,7 @@ function getAccountDataAndInit() { } if (!Config.changedBeforeDb) { if (Config.cookieConfig === null) { - AccountIcon.loading(false); + AccountButton.loading(false); UpdateConfig.apply(DB.getSnapshot().config); Settings.update(); UpdateConfig.saveToCookie(true); @@ -290,7 +290,7 @@ function getAccountDataAndInit() { // }); // if (configsDifferent) { // console.log("applying config from db"); - // AccountIcon.loading(false); + // AccountButton.loading(false); // config = DB.getSnapshot().config; // applyConfig(config); // Settings.update(); @@ -300,7 +300,7 @@ function getAccountDataAndInit() { } UpdateConfig.setDbConfigLoaded(true); } else { - AccountIcon.loading(false); + AccountButton.loading(false); } if (Config.paceCaret === "pb" || Config.paceCaret === "average") { if (!TestLogic.active) { @@ -314,7 +314,7 @@ function getAccountDataAndInit() { changePage("account"); } ThemePicker.refreshButtons(); - AccountIcon.loading(false); + AccountButton.loading(false); ResultFilters.updateTags(); CommandlineLists.updateTagCommands(); TagController.loadActiveFromCookie(); @@ -322,7 +322,7 @@ function getAccountDataAndInit() { Settings.showAccountSection(); }) .catch((e) => { - AccountIcon.loading(false); + AccountButton.loading(false); console.error(e); Notifications.add( "Error downloading user data. Client likely could not connect to the backend - refresh to try again. If error persists try clearing your cache and website data or contact Miodec.", @@ -1051,22 +1051,6 @@ function refreshGlobalStats() { } } -function updateAccountLoginButton() { - if (firebase.auth().currentUser != null) { - UI.swapElements( - $("#menu .icon-button.login"), - $("#menu .icon-button.account"), - 250 - ); - } else { - UI.swapElements( - $("#menu .icon-button.account"), - $("#menu .icon-button.login"), - 250 - ); - } -} - let totalSecondsFiltered = 0; function refreshAccountPage() { diff --git a/src/js/db.js b/src/js/db.js index da5c7a65f..7b6315a4e 100644 --- a/src/js/db.js +++ b/src/js/db.js @@ -1,5 +1,5 @@ import { loadTags } from "./result-filters"; -import * as AccountIcon from "./account-icon"; +import * as AccountButton from "./account-icon"; import * as CloudFunctions from "./cloud-functions"; import * as Notifications from "./notifications"; @@ -453,12 +453,12 @@ export function updateLbMemory(mode, mode2, type, value) { export async function saveConfig(config) { if (firebase.auth().currentUser !== null) { - AccountIcon.loading(true); + AccountButton.loading(true); CloudFunctions.saveConfig({ uid: firebase.auth().currentUser.uid, obj: config, }).then((d) => { - AccountIcon.loading(false); + AccountButton.loading(false); if (d.data.returnCode !== 1) { Notifications.add(`Error saving config to DB! ${d.data.message}`, 4000); } diff --git a/src/js/elements/account-icon.js b/src/js/elements/account-icon.js index 0297053df..ddd1d5d89 100644 --- a/src/js/elements/account-icon.js +++ b/src/js/elements/account-icon.js @@ -9,3 +9,19 @@ export function loading(truefalse) { $("#top #menu .account").css("opacity", 1).css("pointer-events", "auto"); } } + +export function update() { + if (firebase.auth().currentUser != null) { + UI.swapElements( + $("#menu .icon-button.login"), + $("#menu .icon-button.account"), + 250 + ); + } else { + UI.swapElements( + $("#menu .icon-button.account"), + $("#menu .icon-button.login"), + 250 + ); + } +} diff --git a/src/js/global-dependencies.js b/src/js/global-dependencies.js index 2623888dd..4654bf7f1 100644 --- a/src/js/global-dependencies.js +++ b/src/js/global-dependencies.js @@ -24,7 +24,7 @@ import * as Caret from "./caret"; import * as ManualRestart from "./manual-restart-tracker"; import Config, * as UpdateConfig from "./config"; import * as Focus from "./focus"; -import * as AccountIcon from "./account-icon"; +import * as AccountButton from "./account-icon"; import * as TestUI from "./test-ui"; import * as Keymap from "./keymap"; import "./caps-warning"; diff --git a/src/js/test/test-logic.js b/src/js/test/test-logic.js index ea9200dbf..a311a3564 100644 --- a/src/js/test/test-logic.js +++ b/src/js/test/test-logic.js @@ -22,7 +22,7 @@ import * as QuoteSearchPopup from "./quote-search-popup"; import * as PbCrown from "./pb-crown"; import * as TestTimer from "./test-timer"; import * as OutOfFocus from "./out-of-focus"; -import * as AccountIcon from "./account-icon"; +import * as AccountButton from "./account-icon"; import * as DB from "./db"; import * as ThemeColors from "./theme-colors"; import * as CloudFunctions from "./cloud-functions"; @@ -1320,7 +1320,7 @@ export function finish(difficultyFailed = false) { if (firebase.auth().currentUser != null) { completedEvent.uid = firebase.auth().currentUser.uid; //check local pb - AccountIcon.loading(true); + AccountButton.loading(true); let dontShowCrown = false; let pbDiff = 0; DB.getLocalPB( @@ -1480,7 +1480,7 @@ export function finish(difficultyFailed = false) { obj: completedEvent, }) .then((e) => { - AccountIcon.loading(false); + AccountButton.loading(false); if (e.data == null) { Notifications.add( "Unexpected response from the server: " + e.data, @@ -1583,7 +1583,7 @@ export function finish(difficultyFailed = false) { } }) .catch((e) => { - AccountIcon.loading(false); + AccountButton.loading(false); console.error(e); Notifications.add("Could not save result. " + e, -1); });