mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2025-02-05 13:27:49 +08:00
added offline message
This commit is contained in:
parent
974088926f
commit
ffe92b6c98
2 changed files with 119 additions and 118 deletions
2
package-lock.json
generated
2
package-lock.json
generated
|
@ -2301,7 +2301,6 @@
|
|||
"dependencies": {
|
||||
"anymatch": "~3.1.1",
|
||||
"braces": "~3.0.2",
|
||||
"fsevents": "~2.3.1",
|
||||
"glob-parent": "~5.1.0",
|
||||
"is-binary-path": "~2.1.0",
|
||||
"is-glob": "~4.0.1",
|
||||
|
@ -4739,7 +4738,6 @@
|
|||
"anymatch": "^2.0.0",
|
||||
"async-each": "^1.0.1",
|
||||
"braces": "^2.3.2",
|
||||
"fsevents": "^1.2.7",
|
||||
"glob-parent": "^3.1.0",
|
||||
"inherits": "^2.0.3",
|
||||
"is-binary-path": "^1.0.0",
|
||||
|
|
|
@ -342,10 +342,7 @@ export function startTest() {
|
|||
}
|
||||
|
||||
try {
|
||||
if (
|
||||
Config.paceCaret !== "off" ||
|
||||
(Config.repeatedPace && isPaceRepeat)
|
||||
)
|
||||
if (Config.paceCaret !== "off" || (Config.repeatedPace && isPaceRepeat))
|
||||
PaceCaret.start();
|
||||
} catch (e) {}
|
||||
//use a recursive self-adjusting timer to avoid time drift
|
||||
|
@ -616,7 +613,6 @@ export async function init() {
|
|||
}
|
||||
TestUI.showWords();
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
export function restart(
|
||||
|
@ -1566,118 +1562,125 @@ export function finish(difficultyFailed = false) {
|
|||
`checking <i class="fas fa-spin fa-fw fa-circle-notch"></i>`
|
||||
);
|
||||
}
|
||||
CloudFunctions.testCompleted({
|
||||
uid: firebase.auth().currentUser.uid,
|
||||
obj: completedEvent,
|
||||
})
|
||||
.then((e) => {
|
||||
AccountButton.loading(false);
|
||||
if (e.data == null) {
|
||||
Notifications.add(
|
||||
"Unexpected response from the server: " + e.data,
|
||||
-1
|
||||
);
|
||||
return;
|
||||
}
|
||||
if (e.data.resultCode === -1) {
|
||||
Notifications.add("Could not save result", -1);
|
||||
} else if (e.data.resultCode === -2) {
|
||||
Notifications.add(
|
||||
"Possible bot detected. Result not saved.",
|
||||
-1
|
||||
);
|
||||
} else if (e.data.resultCode === -3) {
|
||||
Notifications.add(
|
||||
"Could not verify keypress stats. Result not saved.",
|
||||
-1
|
||||
);
|
||||
} else if (e.data.resultCode === -4) {
|
||||
Notifications.add(
|
||||
"Result data does not make sense. Result not saved.",
|
||||
-1
|
||||
);
|
||||
} else if (e.data.resultCode === -5) {
|
||||
Notifications.add("Test too short. Result not saved.", -1);
|
||||
} else if (e.data.resultCode === -999) {
|
||||
console.error("internal error: " + e.data.message);
|
||||
Notifications.add(
|
||||
"Internal error. Result might not be saved. " +
|
||||
e.data.message,
|
||||
-1
|
||||
);
|
||||
} else if (e.data.resultCode === 1 || e.data.resultCode === 2) {
|
||||
completedEvent.id = e.data.createdId;
|
||||
TestLeaderboards.check(completedEvent);
|
||||
if (e.data.resultCode === 2) {
|
||||
completedEvent.isPb = true;
|
||||
}
|
||||
if (
|
||||
DB.getSnapshot() !== null &&
|
||||
DB.getSnapshot().results !== undefined
|
||||
) {
|
||||
DB.getSnapshot().results.unshift(completedEvent);
|
||||
if (DB.getSnapshot().globalStats.time == undefined) {
|
||||
DB.getSnapshot().globalStats.time =
|
||||
testtime +
|
||||
completedEvent.incompleteTestSeconds -
|
||||
afkseconds;
|
||||
} else {
|
||||
DB.getSnapshot().globalStats.time +=
|
||||
testtime +
|
||||
completedEvent.incompleteTestSeconds -
|
||||
afkseconds;
|
||||
}
|
||||
if (DB.getSnapshot().globalStats.started == undefined) {
|
||||
DB.getSnapshot().globalStats.started =
|
||||
TestStats.restartCount + 1;
|
||||
} else {
|
||||
DB.getSnapshot().globalStats.started +=
|
||||
TestStats.restartCount + 1;
|
||||
}
|
||||
if (DB.getSnapshot().globalStats.completed == undefined) {
|
||||
DB.getSnapshot().globalStats.completed = 1;
|
||||
} else {
|
||||
DB.getSnapshot().globalStats.completed += 1;
|
||||
}
|
||||
}
|
||||
try {
|
||||
firebase
|
||||
.analytics()
|
||||
.logEvent("testCompleted", completedEvent);
|
||||
} catch (e) {
|
||||
console.log("Analytics unavailable");
|
||||
}
|
||||
|
||||
if (e.data.resultCode === 2) {
|
||||
//new pb
|
||||
PbCrown.show();
|
||||
DB.saveLocalPB(
|
||||
Config.mode,
|
||||
mode2,
|
||||
Config.punctuation,
|
||||
Config.language,
|
||||
Config.difficulty,
|
||||
stats.wpm,
|
||||
stats.acc,
|
||||
stats.wpmRaw,
|
||||
consistency
|
||||
);
|
||||
} else if (e.data.resultCode === 1) {
|
||||
PbCrown.hide();
|
||||
// if (localPb) {
|
||||
// Notifications.add(
|
||||
// "Local PB data is out of sync! Refresh the page to resync it or contact Miodec on Discord.",
|
||||
// 15000
|
||||
// );
|
||||
// }
|
||||
}
|
||||
}
|
||||
if (!window.navigator.onLine) {
|
||||
Notifications.add("You are offline. Result not saved.", -1);
|
||||
} else {
|
||||
CloudFunctions.testCompleted({
|
||||
uid: firebase.auth().currentUser.uid,
|
||||
obj: completedEvent,
|
||||
})
|
||||
.catch((e) => {
|
||||
AccountButton.loading(false);
|
||||
console.error(e);
|
||||
Notifications.add("Could not save result. " + e, -1);
|
||||
});
|
||||
.then((e) => {
|
||||
AccountButton.loading(false);
|
||||
if (e.data == null) {
|
||||
Notifications.add(
|
||||
"Unexpected response from the server: " + e.data,
|
||||
-1
|
||||
);
|
||||
return;
|
||||
}
|
||||
if (e.data.resultCode === -1) {
|
||||
Notifications.add("Could not save result", -1);
|
||||
} else if (e.data.resultCode === -2) {
|
||||
Notifications.add(
|
||||
"Possible bot detected. Result not saved.",
|
||||
-1
|
||||
);
|
||||
} else if (e.data.resultCode === -3) {
|
||||
Notifications.add(
|
||||
"Could not verify keypress stats. Result not saved.",
|
||||
-1
|
||||
);
|
||||
} else if (e.data.resultCode === -4) {
|
||||
Notifications.add(
|
||||
"Result data does not make sense. Result not saved.",
|
||||
-1
|
||||
);
|
||||
} else if (e.data.resultCode === -5) {
|
||||
Notifications.add("Test too short. Result not saved.", -1);
|
||||
} else if (e.data.resultCode === -999) {
|
||||
console.error("internal error: " + e.data.message);
|
||||
Notifications.add(
|
||||
"Internal error. Result might not be saved. " +
|
||||
e.data.message,
|
||||
-1
|
||||
);
|
||||
} else if (
|
||||
e.data.resultCode === 1 ||
|
||||
e.data.resultCode === 2
|
||||
) {
|
||||
completedEvent.id = e.data.createdId;
|
||||
TestLeaderboards.check(completedEvent);
|
||||
if (e.data.resultCode === 2) {
|
||||
completedEvent.isPb = true;
|
||||
}
|
||||
if (
|
||||
DB.getSnapshot() !== null &&
|
||||
DB.getSnapshot().results !== undefined
|
||||
) {
|
||||
DB.getSnapshot().results.unshift(completedEvent);
|
||||
if (DB.getSnapshot().globalStats.time == undefined) {
|
||||
DB.getSnapshot().globalStats.time =
|
||||
testtime +
|
||||
completedEvent.incompleteTestSeconds -
|
||||
afkseconds;
|
||||
} else {
|
||||
DB.getSnapshot().globalStats.time +=
|
||||
testtime +
|
||||
completedEvent.incompleteTestSeconds -
|
||||
afkseconds;
|
||||
}
|
||||
if (DB.getSnapshot().globalStats.started == undefined) {
|
||||
DB.getSnapshot().globalStats.started =
|
||||
TestStats.restartCount + 1;
|
||||
} else {
|
||||
DB.getSnapshot().globalStats.started +=
|
||||
TestStats.restartCount + 1;
|
||||
}
|
||||
if (DB.getSnapshot().globalStats.completed == undefined) {
|
||||
DB.getSnapshot().globalStats.completed = 1;
|
||||
} else {
|
||||
DB.getSnapshot().globalStats.completed += 1;
|
||||
}
|
||||
}
|
||||
try {
|
||||
firebase
|
||||
.analytics()
|
||||
.logEvent("testCompleted", completedEvent);
|
||||
} catch (e) {
|
||||
console.log("Analytics unavailable");
|
||||
}
|
||||
|
||||
if (e.data.resultCode === 2) {
|
||||
//new pb
|
||||
PbCrown.show();
|
||||
DB.saveLocalPB(
|
||||
Config.mode,
|
||||
mode2,
|
||||
Config.punctuation,
|
||||
Config.language,
|
||||
Config.difficulty,
|
||||
stats.wpm,
|
||||
stats.acc,
|
||||
stats.wpmRaw,
|
||||
consistency
|
||||
);
|
||||
} else if (e.data.resultCode === 1) {
|
||||
PbCrown.hide();
|
||||
// if (localPb) {
|
||||
// Notifications.add(
|
||||
// "Local PB data is out of sync! Refresh the page to resync it or contact Miodec on Discord.",
|
||||
// 15000
|
||||
// );
|
||||
// }
|
||||
}
|
||||
}
|
||||
})
|
||||
.catch((e) => {
|
||||
AccountButton.loading(false);
|
||||
console.error(e);
|
||||
Notifications.add("Could not save result. " + e, -1);
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
} else {
|
||||
|
|
Loading…
Reference in a new issue