From db2de0c7b757ace27224b8a17e18424dffa3dcce Mon Sep 17 00:00:00 2001 From: David Martin Date: Mon, 26 Oct 2020 19:33:41 -0500 Subject: [PATCH 1/3] Properly save when manually choosing layout --- public/js/commandline.js | 2 +- public/js/settings.js | 2 +- public/js/userconfig.js | 10 +++++++++- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/public/js/commandline.js b/public/js/commandline.js index 95fcaa482..64c0b12cc 100644 --- a/public/js/commandline.js +++ b/public/js/commandline.js @@ -1510,7 +1510,7 @@ if (Object.keys(layouts).length > 0) { id: "changeLayout" + capitalizeFirstLetter(layout), display: layout.replace(/_/g, " "), exec: () => { - changeLayout(layout); + changeSavedLayout(layout); restartTest(); saveConfigToCookie(); }, diff --git a/public/js/settings.js b/public/js/settings.js index e19cd1198..f052a9d0c 100644 --- a/public/js/settings.js +++ b/public/js/settings.js @@ -229,7 +229,7 @@ settingsGroups.capsLockBackspace = new SettingsGroup( "capsLockBackspace", setCapsLockBackspace ); -settingsGroups.layout = new SettingsGroup("layout", changeLayout); +settingsGroups.layout = new SettingsGroup("layout", changeSavedLayout); settingsGroups.language = new SettingsGroup("language", changeLanguage); settingsGroups.fontSize = new SettingsGroup("fontSize", changeFontSize); settingsGroups.pageWidth = new SettingsGroup("pageWidth", setPageWidth); diff --git a/public/js/userconfig.js b/public/js/userconfig.js index 799b57d0a..02904a2b9 100644 --- a/public/js/userconfig.js +++ b/public/js/userconfig.js @@ -167,7 +167,7 @@ function applyConfig(configObj) { changeWordCount(configObj.words, true); changeLanguage(configObj.language, true); setCapsLockBackspace(configObj.capsLockBackspace, true); - changeLayout(configObj.savedLayout, true); + changeSavedLayout(configObj.savedLayout, true); changeFontSize(configObj.fontSize, true); setFreedomMode(configObj.freedomMode, true); setCaretStyle(configObj.caretStyle, true); @@ -1181,6 +1181,14 @@ function changeLayout(layout, nosave) { if (!nosave) saveConfigToCookie(); } +function changeSavedLayout(layout, nosave) { + if (layout == null || layout == undefined) { + layout = "qwerty"; + } + config.savedLayout = layout; + changeLayout(layout, nosave); +} + function changeKeymapMode(mode, nosave) { if (mode == null || mode == undefined) { mode = "off"; From 4487bbf2e7bc28e1bedf441aac0811598fb7ab89 Mon Sep 17 00:00:00 2001 From: David Martin Date: Mon, 26 Oct 2020 20:10:58 -0500 Subject: [PATCH 2/3] Make buttons show layout after exiting layoutfluid --- public/js/script.js | 1 + 1 file changed, 1 insertion(+) diff --git a/public/js/script.js b/public/js/script.js index fcd8b9909..76e74eec5 100644 --- a/public/js/script.js +++ b/public/js/script.js @@ -358,6 +358,7 @@ function activateFunbox(funbox, mode) { if (funbox !== "layoutfluid" || mode !== "script") { if (config.layout !== config.savedLayout) { changeLayout(config.savedLayout); + settingsGroups.layout.updateButton(); } } updateTestModesNotice(); From 9a9b4f3a632188086b843ddc569ed96603b1139f Mon Sep 17 00:00:00 2001 From: David Martin Date: Mon, 26 Oct 2020 20:33:20 -0500 Subject: [PATCH 3/3] Ran prettier --- functions/index.js | 188 +++++++++++++++++++++++------------------- public/css/style.scss | 8 +- public/index.html | 36 ++++---- public/js/script.js | 20 ++--- 4 files changed, 136 insertions(+), 116 deletions(-) diff --git a/functions/index.js b/functions/index.js index 8318194c8..74524a594 100644 --- a/functions/index.js +++ b/functions/index.js @@ -61,7 +61,6 @@ async function getAllUsers() { let ret = []; async function getAll(nextPageToken) { - // List batch of users, 1000 at a time. let listUsersResult = await auth.listUsers(1000, nextPageToken); for (let i = 0; i < listUsersResult.users.length; i++) { @@ -70,7 +69,7 @@ async function getAllUsers() { //if custom claim is undefined check, if its true then ignore // if (loopuser === undefined || loopuser.customClaims === undefined || loopuser.customClaims['nameChecked'] === undefined) { - ret.push(listUsersResult.users[i]); + ret.push(listUsersResult.users[i]); // } // console.log(loopuser.customClaims['asd']); @@ -105,65 +104,67 @@ function isUsernameValid(name) { return /^[0-9a-zA-Z_.-]+$/.test(name); } -exports.reserveDisplayName = functions.https.onCall(async (request, response) => { - let udata = await db.collection('users').doc(request.uid).get(); - udata = udata.data(); - if (request.name.toLowerCase() === udata.name.toLowerCase()) { - db.collection('takenNames') - .doc(request.name.toLowerCase()) - .set({ - taken: true - }, { merge: true }); +exports.reserveDisplayName = functions.https.onCall( + async (request, response) => { + let udata = await db.collection("users").doc(request.uid).get(); + udata = udata.data(); + if (request.name.toLowerCase() === udata.name.toLowerCase()) { + db.collection("takenNames").doc(request.name.toLowerCase()).set( + { + taken: true, + }, + { merge: true } + ); + } } -}) +); exports.clearName = functions.auth.user().onDelete((user) => { - db.collection('takenNames') - .doc(user.displayName.toLowerCase()) - .delete(); - db.collection('users') - .doc(user.uid) - .delete(); + db.collection("takenNames").doc(user.displayName.toLowerCase()).delete(); + db.collection("users").doc(user.uid).delete(); }); -exports.checkNameAvailability = functions.https.onCall(async (request, response) => { - // 1 - available - // -1 - unavailable (taken) - // -2 - not valid name - // -999 - unknown error - try { - if (!isUsernameValid(request.name)) return -2; +exports.checkNameAvailability = functions.https.onCall( + async (request, response) => { + // 1 - available + // -1 - unavailable (taken) + // -2 - not valid name + // -999 - unknown error + try { + if (!isUsernameValid(request.name)) return -2; - let takendata = await db.collection('takenNames') - .doc(request.name.toLowerCase()) - .get(); - - takendata = takendata.data(); + let takendata = await db + .collection("takenNames") + .doc(request.name.toLowerCase()) + .get(); - if (takendata !== undefined && takendata.taken) { - return -1; - } else { - return 1; + takendata = takendata.data(); + + if (takendata !== undefined && takendata.taken) { + return -1; + } else { + return 1; + } + + // return getAllNames().then((data) => { + // let available = 1; + // data.forEach((name) => { + // try { + // if (name.toLowerCase() === request.name.toLowerCase()) available = -1; + // } catch (e) { + // // + // } + // }); + // return available; + // }); + } catch (e) { + console.log(e.message); + return -999; } - - // return getAllNames().then((data) => { - // let available = 1; - // data.forEach((name) => { - // try { - // if (name.toLowerCase() === request.name.toLowerCase()) available = -1; - // } catch (e) { - // // - // } - // }); - // return available; - // }); - } catch (e) { - console.log(e.message); - return -999; } -}); +); - // exports.changeName = functions.https.onCall((request, response) => { +// exports.changeName = functions.https.onCall((request, response) => { // try { // if (!isUsernameValid(request.name)) { // console.warn( @@ -337,7 +338,7 @@ function checkIfPB(uid, obj, userdata) { acc: obj.acc, raw: obj.rawWpm, timestamp: Date.now(), - consistency: obj.consistency + consistency: obj.consistency, }, ], }, @@ -362,7 +363,7 @@ function checkIfPB(uid, obj, userdata) { acc: obj.acc, raw: obj.rawWpm, timestamp: Date.now(), - consistency: obj.consistency + consistency: obj.consistency, }, ], }, @@ -413,7 +414,7 @@ function checkIfPB(uid, obj, userdata) { acc: obj.acc, raw: obj.rawWpm, timestamp: Date.now(), - consistency: obj.consistency + consistency: obj.consistency, }); toUpdate = true; } @@ -429,7 +430,7 @@ function checkIfPB(uid, obj, userdata) { acc: obj.acc, raw: obj.rawWpm, timestamp: Date.now(), - consistency: obj.consistency + consistency: obj.consistency, }, ]; toUpdate = true; @@ -573,7 +574,9 @@ exports.verifyUser = functions.https.onRequest(async (request, response) => { } request = request.body.data; if (request.uid == undefined) { - response.status(200).send({ data: { status: -1, message: "Need to provide uid" } }); + response + .status(200) + .send({ data: { status: -1, message: "Need to provide uid" } }); return; } try { @@ -585,20 +588,24 @@ exports.verifyUser = functions.https.onRequest(async (request, response) => { .then((res) => res.json()) .then(async (res2) => { let did = res2.id; - await db.collection('users').doc(request.uid).update({ - discordId: did - }) + await db.collection("users").doc(request.uid).update({ + discordId: did, + }); await db.collection("bot-commands").add({ command: "verify", - arguments: [did,request.uid], + arguments: [did, request.uid], executed: false, requestTimestamp: Date.now(), }); - response.status(200).send({ data: { status: 1, message: "Verified", did: did } }); + response + .status(200) + .send({ data: { status: 1, message: "Verified", did: did } }); return; }) .catch((e) => { - console.error('Something went wrong when trying to verify user ' + e.message); + console.error( + "Something went wrong when trying to verify user " + e.message + ); response.status(200).send({ data: { status: -1, message: e.message } }); return; }); @@ -612,39 +619,52 @@ function incrementT60Bananas(uid, result, userData) { try { let best60; try { - best60 = Math.max(...userData.personalBests.time[60].map(best => best.wpm)); + best60 = Math.max( + ...userData.personalBests.time[60].map((best) => best.wpm) + ); if (!Number.isFinite(best60)) { - throw 'Not finite' + throw "Not finite"; } } catch (e) { best60 = undefined; } - + if (best60 != undefined && result.wpm < best60 - best60 * 0.25) { - console.log('returning'); + console.log("returning"); return; } else { //increment - console.log('checking'); - db.collection(`users/${uid}/bananas`).doc('bananas').get().then(docRef => { - let data = docRef.data(); - if (data === undefined) { - //create doc - db.collection(`users/${uid}/bananas`).doc('bananas') - .set({ - t60bananas: 1, - }, { merge: true }); - } else { - //increment - db.collection(`users/${uid}/bananas`).doc('bananas') - .set({ - t60bananas: admin.firestore.FieldValue.increment(1), - }, { merge: true }); - } - }) + console.log("checking"); + db.collection(`users/${uid}/bananas`) + .doc("bananas") + .get() + .then((docRef) => { + let data = docRef.data(); + if (data === undefined) { + //create doc + db.collection(`users/${uid}/bananas`).doc("bananas").set( + { + t60bananas: 1, + }, + { merge: true } + ); + } else { + //increment + db.collection(`users/${uid}/bananas`) + .doc("bananas") + .set( + { + t60bananas: admin.firestore.FieldValue.increment(1), + }, + { merge: true } + ); + } + }); } } catch (e) { - console.log('something went wrong when trying to increment bananas ' + e.message); + console.log( + "something went wrong when trying to increment bananas " + e.message + ); } } diff --git a/public/css/style.scss b/public/css/style.scss index ad2f74bf9..94ccf01f0 100644 --- a/public/css/style.scss +++ b/public/css/style.scss @@ -1525,8 +1525,8 @@ key { flex-direction: row-reverse; } } - &.withLigatures{ - letter{ + &.withLigatures { + letter { display: inline; } } @@ -1808,9 +1808,9 @@ key { border-bottom: 2px solid var(--error-color); text-shadow: 1px 0px 0px var(--bg-color), // 2px 0px 0px var(--bg-color), - -1px 0px 0px var(--bg-color), + -1px 0px 0px var(--bg-color), // -2px 0px 0px var(--bg-color), - 0px 1px 0px var(--bg-color), + 0px 1px 0px var(--bg-color), 1px 1px 0px var(--bg-color), -1px 1px 0px var(--bg-color); } diff --git a/public/index.html b/public/index.html index 8c7335edd..b843e0fe4 100644 --- a/public/index.html +++ b/public/index.html @@ -42,7 +42,7 @@ - +
-
+
@@ -916,7 +916,7 @@