Skip to content

Commit 9438e3e

Browse files
fix: invalid monkeytype name error
1 parent 3ccca4d commit 9438e3e

File tree

4 files changed

+89
-15
lines changed

4 files changed

+89
-15
lines changed

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.css linguist-detectable=false

app.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ app.get("/generate-svg/:userId/:themeName", async (req, res) => {
8888
req.query.lbpb == "true" ? (leaderBoards = personalBests = true) : null;
8989
const userData = await getUserData(userId);
9090
const theme = getTheme(themeName);
91-
if (userData === undefined) {
91+
if (userData === undefined || userData.name === undefined) {
9292
const svg = await getSvg(null, theme, null, false, false);
9393
res.set("Content-Type", "image/svg+xml");
9494
res.send(svg);

public/script/index.js

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,22 +31,34 @@ $("#personalBestBtn").click(function () {
3131
});
3232

3333
$("#generateReadmeBtn").click(async function () {
34-
if (monkeytypeName === "" || themeListState.themeName === "") {
35-
if (monkeytypeName === "") {
36-
$("#monkeytypeNameError").removeClass("absolute hidden");
37-
} else {
38-
$("#monkeytypeNameError").addClass("absolute hidden");
39-
}
34+
$("#monkeytypeNameError").addClass("absolute hidden");
35+
$("#themeNameError").addClass("absolute hidden");
36+
$("#monkeytypeNameInvalidError").addClass("absolute hidden");
4037

41-
if (themeListState.themeName === "") {
42-
$("#themeNameError").removeClass("absolute hidden");
43-
} else {
44-
$("#themeNameError").addClass("absolute hidden");
45-
}
38+
let svgDataCheck = false;
39+
const VALID_NAME_PATTERN = /^[\da-zA-Z_.-]+$/;
40+
41+
if (monkeytypeName === "") {
42+
$("#monkeytypeNameError").removeClass("absolute hidden");
43+
svgDataCheck = true;
44+
}
45+
46+
if (themeListState.themeName === "") {
47+
$("#themeNameError").removeClass("absolute hidden");
48+
svgDataCheck = true;
49+
}
50+
51+
if (
52+
monkeytypeName !== "" &&
53+
(!VALID_NAME_PATTERN.test(monkeytypeName) ||
54+
!(monkeytypeName.length > 1 && monkeytypeName.length < 16))
55+
) {
56+
$("#monkeytypeNameInvalidError").removeClass("absolute hidden");
57+
svgDataCheck = true;
58+
}
59+
60+
if (svgDataCheck) {
4661
return;
47-
} else {
48-
$("#monkeytypeNameError").addClass("absolute hidden");
49-
$("#themeNameError").addClass("absolute hidden");
5062
}
5163

5264
$("#generateReadmeBtn").prop("disabled", true);
@@ -135,6 +147,14 @@ $("#themeNameError").mouseleave(function () {
135147
$("#themeNameErrorHover").addClass("hidden");
136148
});
137149

150+
$("#monkeytypeNameInvalidError").mouseenter(function () {
151+
$("#monkeytypeNameInvalidErrorHover").removeClass("hidden");
152+
});
153+
154+
$("#monkeytypeNameInvalidError").mouseleave(function () {
155+
$("#monkeytypeNameInvalidErrorHover").addClass("hidden");
156+
});
157+
138158
function errorHoverClick(id) {
139159
$(`#${id}`).addClass("hidden");
140160
}

public/views/index.ejs

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -590,6 +590,59 @@
590590
</div>
591591
</div>
592592
</button>
593+
<button
594+
id="monkeytypeNameInvalidError"
595+
class="relative mt-2 hidden h-12 md:h-16 overflow-hidden rounded-xl border-4 border-nord-light-subAlt lg:ml-2 lg:mt-0"
596+
style="width: 280px"
597+
onclick="errorHoverClick('monkeytypeNameInvalidError')"
598+
>
599+
<div
600+
class="absolute left-0 top-0 flex h-full w-full bg-nord-light-error bg-opacity-40 p-4"
601+
>
602+
<div
603+
class="flex h-full items-center justify-center"
604+
>
605+
<svg
606+
xmlns="http://www.w3.org/2000/svg"
607+
viewBox="0 0 384 512"
608+
fill="#eceff4"
609+
style="height: 20px; width: 20px"
610+
>
611+
<path
612+
d="M342.6 150.6c12.5-12.5 12.5-32.8 0-45.3s-32.8-12.5-45.3 0L192 210.7 86.6 105.4c-12.5-12.5-32.8-12.5-45.3 0s-12.5 32.8 0 45.3L146.7 256 41.4 361.4c-12.5 12.5-12.5 32.8 0 45.3s32.8 12.5 45.3 0L192 301.3 297.4 406.6c12.5 12.5 32.8 12.5 45.3 0s12.5-32.8 0-45.3L237.3 256 342.6 150.6z"
613+
/>
614+
</svg>
615+
</div>
616+
<div
617+
class="ml-3 flex h-full items-center justify-center tracking-wide"
618+
>
619+
<div
620+
class="text-left text-sm md:text-base font-medium text-nord-light-bg"
621+
>
622+
Invalid Monkeytype Name
623+
</div>
624+
</div>
625+
</div>
626+
<div
627+
id="monkeytypeNameInvalidErrorHover"
628+
class="absolute left-0 top-0 hidden h-full w-full border-4 border-transparent bg-black bg-opacity-20"
629+
>
630+
<div
631+
class="flex h-full w-full items-center justify-center"
632+
>
633+
<svg
634+
xmlns="http://www.w3.org/2000/svg"
635+
viewBox="0 0 384 512"
636+
fill="#eceff4"
637+
style="height: 40px; width: 40px"
638+
>
639+
<path
640+
d="M342.6 150.6c12.5-12.5 12.5-32.8 0-45.3s-32.8-12.5-45.3 0L192 210.7 86.6 105.4c-12.5-12.5-32.8-12.5-45.3 0s-12.5 32.8 0 45.3L146.7 256 41.4 361.4c-12.5 12.5-12.5 32.8 0 45.3s32.8 12.5 45.3 0L192 301.3 297.4 406.6c12.5 12.5 32.8 12.5 45.3 0s12.5-32.8 0-45.3L237.3 256 342.6 150.6z"
641+
/>
642+
</svg>
643+
</div>
644+
</div>
645+
</button>
593646
</div>
594647
</div>
595648
<div class="mt-6 flex justify-start">

0 commit comments

Comments
 (0)