mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2025-02-04 04:51:16 +08:00
db snapshot now includes personal bests
This commit is contained in:
parent
259171f9e2
commit
4de72d2bff
3 changed files with 24 additions and 13 deletions
|
@ -470,7 +470,7 @@ function refreshAccountPage() {
|
|||
|
||||
filteredResults = [];
|
||||
$(".pageAccount .history table tbody").empty();
|
||||
dbSnapshot.forEach(result => {
|
||||
dbSnapshot.results.forEach(result => {
|
||||
|
||||
|
||||
let tt = 0;
|
||||
|
@ -683,7 +683,7 @@ function refreshAccountPage() {
|
|||
swapElements($(".pageAccount .preloader"), $(".pageAccount .content"), 250);
|
||||
}
|
||||
|
||||
if (dbSnapshot == null) {
|
||||
if (dbSnapshot.length == 0) {
|
||||
// console.log('no db snap');
|
||||
// db_getUserResults().then(data => {
|
||||
// if(!data) return;
|
||||
|
|
|
@ -6,7 +6,10 @@ let dbSnapshot = [];
|
|||
async function db_getUserSnapshot() {
|
||||
let user = firebase.auth().currentUser;
|
||||
if (user == null) return false;
|
||||
let ret = [];
|
||||
let snap = {
|
||||
results: [],
|
||||
personalBests: {}
|
||||
};
|
||||
// await db.collection('results')
|
||||
// .orderBy('timestamp', 'desc')
|
||||
// .where('uid', '==', user.uid)
|
||||
|
@ -18,16 +21,24 @@ async function db_getUserSnapshot() {
|
|||
// })
|
||||
// })
|
||||
await db.collection(`users/${user.uid}/results/`)
|
||||
.orderBy('timestamp', 'desc')
|
||||
.get()
|
||||
.then(data => {
|
||||
// console.log('getting data from db!');
|
||||
data.docs.forEach(doc => {
|
||||
ret.push(doc.data());
|
||||
})
|
||||
.orderBy('timestamp', 'desc')
|
||||
.get()
|
||||
.then(data => {
|
||||
// console.log('getting data from db!');
|
||||
data.docs.forEach(doc => {
|
||||
let result = doc.data();
|
||||
result.id = doc.id;
|
||||
snap.results.push(result);
|
||||
})
|
||||
dbSnapshot = ret;
|
||||
return ret;
|
||||
})
|
||||
await db.collection('users').doc(user.uid)
|
||||
.get()
|
||||
.then(data => {
|
||||
// console.log('getting data from db!');
|
||||
snap.personalBests = data.data().personalBests;
|
||||
})
|
||||
dbSnapshot = snap;
|
||||
return dbSnapshot;
|
||||
}
|
||||
|
||||
async function db_getUserHighestWpm(mode, mode2, punctuation, language, difficulty) {
|
||||
|
|
|
@ -675,7 +675,7 @@ function showResult(difficultyFailed = false) {
|
|||
if(e.data === -1){
|
||||
showNotification('Could not save result',3000);
|
||||
}else if(e.data === 1 || e.data === 2){
|
||||
dbSnapshot.unshift(completedEvent);
|
||||
dbSnapshot.results.unshift(completedEvent);
|
||||
try{
|
||||
firebase.analytics().logEvent('testCompleted', completedEvent);
|
||||
}catch(e){
|
||||
|
|
Loading…
Reference in a new issue