add layouts to refactored file & lint refactored files

This commit is contained in:
Benjamin Kinga 2020-12-14 16:17:35 -06:00
parent 5080733b7f
commit 8b9636a440
5 changed files with 88 additions and 86 deletions

View file

@ -90,6 +90,7 @@ const refactoredSrc = [
"./src/js/dom-util.js",
"./src/js/cloud-functions.js",
"./src/js/misc.js",
"./src/js/layouts.js",
];
//legacy files
@ -98,7 +99,6 @@ const globalSrc = [
"./src/js/global-dependencies.js",
"./src/js/simple-popups.js",
"./src/js/words.js",
"./src/js/layouts.js",
"./src/js/userconfig.js",
"./src/js/commandline.js",
"./src/js/leaderboards.js",

View file

@ -94,7 +94,7 @@ export async function db_getUserResults() {
.get()
.then((data) => {
dbSnapshot.results = [];
data.docs.forEach((doc, index) => {
data.docs.forEach((doc) => {
let result = doc.data();
result.id = doc.id;
dbSnapshot.results.push(result);
@ -172,6 +172,7 @@ export async function db_getLocalPB(
let retval;
if (dbSnapshot == null) {
retval = 0;
} else {
retval = cont();
}
@ -240,8 +241,7 @@ export async function db_saveLocalPB(
}
}
if (dbSnapshot == null) {
} else {
if (dbSnapshot != null) {
cont();
}
}

View file

@ -20,3 +20,4 @@ import {
import { showBackgroundLoader, hideBackgroundLoader } from "./dom-util";
import * as Misc from "./misc";
import * as CloudFunctions from "./cloud-functions";
import layouts from "./layouts";

View file

@ -236,3 +236,4 @@ const layouts = {
]
},
}
export default layouts;

View file

@ -1,4 +1,52 @@
import { showBackgroundLoader, hideBackgroundLoader } from "./dom-util";
function hexToHSL(H) {
// Convert hex to RGB first
let r = 0,
g = 0,
b = 0;
if (H.length == 4) {
r = "0x" + H[1] + H[1];
g = "0x" + H[2] + H[2];
b = "0x" + H[3] + H[3];
} else if (H.length == 7) {
r = "0x" + H[1] + H[2];
g = "0x" + H[3] + H[4];
b = "0x" + H[5] + H[6];
}
// Then to HSL
r /= 255;
g /= 255;
b /= 255;
let cmin = Math.min(r, g, b),
cmax = Math.max(r, g, b),
delta = cmax - cmin,
h = 0,
s = 0,
l = 0;
if (delta == 0) h = 0;
else if (cmax == r) h = ((g - b) / delta) % 6;
else if (cmax == g) h = (b - r) / delta + 2;
else h = (r - g) / delta + 4;
h = Math.round(h * 60);
if (h < 0) h += 360;
l = (cmax + cmin) / 2;
s = delta == 0 ? 0 : delta / (1 - Math.abs(2 * l - 1));
s = +(s * 100).toFixed(1);
l = +(l * 100).toFixed(1);
return {
hue: h,
sat: s,
lgt: l,
string: "hsl(" + h + "," + s + "%," + l + "%)",
};
}
let themesList = null;
export async function getThemesList() {
if (themesList == null) {
@ -96,8 +144,40 @@ export async function getChallengeList() {
}
}
let currentLanguage = null;
export function showNotification(text, time) {
let noti = $(".notification");
noti.text(text);
noti.css("top", `-${noti.outerHeight()}px`);
noti.stop(true, false).animate(
{
top: "1rem",
},
250,
"swing",
() => {
noti.stop(true, false).animate(
{
opacity: 1,
},
time,
() => {
noti.stop(true, false).animate(
{
top: `-${noti.outerHeight()}px`,
},
250,
"swing",
() => {
noti.text("");
}
);
}
);
}
);
}
let currentLanguage = null;
export function getCurrentLanguage() {
return currentLanguage;
}
@ -149,7 +229,7 @@ export function sendVerificationEmail() {
showBackgroundLoader();
let cu = firebase.auth().currentUser;
cu.sendEmailVerification()
.then((e) => {
.then(() => {
hideBackgroundLoader();
showNotification("Email sent to " + cu.email, 4000);
})
@ -204,39 +284,6 @@ export function mean(array) {
}
}
export function showNotification(text, time) {
let noti = $(".notification");
noti.text(text);
noti.css("top", `-${noti.outerHeight()}px`);
noti.stop(true, false).animate(
{
top: "1rem",
},
250,
"swing",
() => {
noti.stop(true, false).animate(
{
opacity: 1,
},
time,
() => {
noti.stop(true, false).animate(
{
top: `-${noti.outerHeight()}px`,
},
250,
"swing",
() => {
noti.text("");
}
);
}
);
}
);
}
export function getReleasesFromGitHub() {
$.getJSON(
"https://api.github.com/repos/Miodec/monkeytype/releases",
@ -291,53 +338,6 @@ export function kogasa(cov) {
);
}
function hexToHSL(H) {
// Convert hex to RGB first
let r = 0,
g = 0,
b = 0;
if (H.length == 4) {
r = "0x" + H[1] + H[1];
g = "0x" + H[2] + H[2];
b = "0x" + H[3] + H[3];
} else if (H.length == 7) {
r = "0x" + H[1] + H[2];
g = "0x" + H[3] + H[4];
b = "0x" + H[5] + H[6];
}
// Then to HSL
r /= 255;
g /= 255;
b /= 255;
let cmin = Math.min(r, g, b),
cmax = Math.max(r, g, b),
delta = cmax - cmin,
h = 0,
s = 0,
l = 0;
if (delta == 0) h = 0;
else if (cmax == r) h = ((g - b) / delta) % 6;
else if (cmax == g) h = (b - r) / delta + 2;
else h = (r - g) / delta + 4;
h = Math.round(h * 60);
if (h < 0) h += 360;
l = (cmax + cmin) / 2;
s = delta == 0 ? 0 : delta / (1 - Math.abs(2 * l - 1));
s = +(s * 100).toFixed(1);
l = +(l * 100).toFixed(1);
return {
hue: h,
sat: s,
lgt: l,
string: "hsl(" + h + "," + s + "%," + l + "%)",
};
}
export function roundTo2(num) {
return Math.round((num + Number.EPSILON) * 100) / 100;
}