mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2025-10-29 18:27:33 +08:00
fix(challenge): loading challenges from the URL
This commit is contained in:
parent
5d6cf32f1a
commit
1a0e9ecfc6
3 changed files with 30 additions and 18 deletions
|
|
@ -253,24 +253,9 @@ if (Auth && ConnectionState.get()) {
|
|||
|
||||
URLHandler.loadCustomThemeFromUrl(search);
|
||||
URLHandler.loadTestSettingsFromUrl(search);
|
||||
URLHandler.loadChallengeFromUrl(search);
|
||||
void URLHandler.linkDiscord(hash);
|
||||
|
||||
if (/challenge_.+/g.test(window.location.pathname)) {
|
||||
Notifications.add(
|
||||
"Challenge links temporarily disabled. Please use the command line to load the challenge manually",
|
||||
0,
|
||||
{
|
||||
duration: 7,
|
||||
}
|
||||
);
|
||||
return;
|
||||
// Notifications.add("Loading challenge", 0);
|
||||
// let challengeName = window.location.pathname.split("_")[1];
|
||||
// setTimeout(() => {
|
||||
// ChallengeController.setup(challengeName);
|
||||
// }, 1000);
|
||||
}
|
||||
|
||||
Settings.updateAuthSections();
|
||||
});
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -222,7 +222,9 @@ export async function setup(challengeName: string): Promise<boolean> {
|
|||
return false;
|
||||
}
|
||||
|
||||
const challenge = list.filter((c) => c.name === challengeName)[0];
|
||||
const challenge = list.filter(
|
||||
(c) => c.name.toLowerCase() === challengeName.toLowerCase()
|
||||
)[0];
|
||||
let notitext;
|
||||
try {
|
||||
if (challenge === undefined) {
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ import * as DB from "../db";
|
|||
import * as Loader from "../elements/loader";
|
||||
import * as AccountButton from "../elements/account-button";
|
||||
import { restart as restartTest } from "../test/test-logic";
|
||||
import * as ChallengeController from "../controllers/challenge-controller";
|
||||
|
||||
export async function linkDiscord(hashOverride: string): Promise<void> {
|
||||
if (!hashOverride) return;
|
||||
|
|
@ -179,7 +180,9 @@ export function loadTestSettingsFromUrl(getOverride?: string): void {
|
|||
applied["funbox"] = de[7];
|
||||
}
|
||||
|
||||
restartTest();
|
||||
restartTest({
|
||||
nosave: true,
|
||||
});
|
||||
|
||||
let appliedString = "";
|
||||
|
||||
|
|
@ -197,3 +200,25 @@ export function loadTestSettingsFromUrl(getOverride?: string): void {
|
|||
});
|
||||
}
|
||||
}
|
||||
|
||||
export function loadChallengeFromUrl(getOverride?: string): void {
|
||||
const getValue = (
|
||||
Misc.findGetParameter("challenge", getOverride) ?? ""
|
||||
).toLowerCase();
|
||||
if (getValue === "") return;
|
||||
|
||||
Notifications.add("Loading challenge", 0);
|
||||
ChallengeController.setup(getValue)
|
||||
.then((result) => {
|
||||
if (result === true) {
|
||||
Notifications.add("Challenge loaded", 1);
|
||||
restartTest({
|
||||
nosave: true,
|
||||
});
|
||||
}
|
||||
})
|
||||
.catch((e) => {
|
||||
Notifications.add("Failed to load challenge", -1);
|
||||
console.error(e);
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue