Skip to content

Commit 95967ef

Browse files
authored
impr: validate tag name on tag creation and rename (@fehmer) (monkeytypegame#6264)
1 parent 5acdc6d commit 95967ef

File tree

5 files changed

+172
-258
lines changed

5 files changed

+172
-258
lines changed

frontend/src/html/popups.html

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -946,14 +946,6 @@
946946
<div class="quotes"></div>
947947
</div>
948948
</dialog>
949-
<dialog id="editTagModal" class="modalWrapper hidden">
950-
<form class="modal">
951-
<div class="title"></div>
952-
<input type="text" title="tag" />
953-
<div class="text"></div>
954-
<button type="submit"></button>
955-
</form>
956-
</dialog>
957949
<dialog id="streakHourOffsetModal" class="modalWrapper hidden">
958950
<div class="modal">
959951
<div class="title">Set streak hour offset</div>

frontend/src/styles/popups.scss

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1555,12 +1555,6 @@ body.darkMode {
15551555
}
15561556
}
15571557

1558-
#editTagModal {
1559-
.modal {
1560-
max-width: 450px;
1561-
}
1562-
}
1563-
15641558
#streakHourOffsetModal {
15651559
.modal {
15661560
max-width: 500px;

frontend/src/ts/commandline/lists/tags.ts

Lines changed: 43 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -30,64 +30,28 @@ const commands: Command[] = [
3030
function update(): void {
3131
const snapshot = DB.getSnapshot();
3232
subgroup.list = [];
33+
3334
if (
34-
snapshot === undefined ||
35-
snapshot.tags === undefined ||
36-
snapshot.tags.length === 0
35+
snapshot !== undefined &&
36+
snapshot.tags !== undefined &&
37+
snapshot.tags.length > 0
3738
) {
3839
subgroup.list.push({
39-
id: "createTag",
40-
display: "Create tag",
41-
icon: "fa-plus",
42-
shouldFocusTestUI: false,
43-
exec: ({ commandlineModal }): void => {
44-
EditTagsPopup.show("add", undefined, undefined, commandlineModal);
45-
},
46-
});
47-
return;
48-
}
49-
subgroup.list.push({
50-
id: "clearTags",
51-
display: `Clear tags`,
52-
icon: "fa-times",
53-
sticky: true,
54-
exec: async (): Promise<void> => {
55-
const snapshot = DB.getSnapshot();
56-
if (!snapshot) return;
57-
58-
snapshot.tags = snapshot.tags?.map((tag) => {
59-
tag.active = false;
60-
61-
return tag;
62-
});
63-
64-
DB.setSnapshot(snapshot);
65-
if (
66-
Config.paceCaret === "average" ||
67-
Config.paceCaret === "tagPb" ||
68-
Config.paceCaret === "daily"
69-
) {
70-
await PaceCaret.init();
71-
}
72-
void ModesNotice.update();
73-
TagController.saveActiveToLocalStorage();
74-
},
75-
});
76-
77-
for (const tag of snapshot.tags) {
78-
subgroup.list.push({
79-
id: "toggleTag" + tag._id,
80-
display: tag.display,
40+
id: "clearTags",
41+
display: `Clear tags`,
42+
icon: "fa-times",
8143
sticky: true,
82-
active: () => {
83-
return (
84-
DB.getSnapshot()?.tags?.find((t) => t._id === tag._id)?.active ??
85-
false
86-
);
87-
},
8844
exec: async (): Promise<void> => {
89-
TagController.toggle(tag._id);
45+
const snapshot = DB.getSnapshot();
46+
if (!snapshot) return;
47+
48+
snapshot.tags = snapshot.tags?.map((tag) => {
49+
tag.active = false;
9050

51+
return tag;
52+
});
53+
54+
DB.setSnapshot(snapshot);
9155
if (
9256
Config.paceCaret === "average" ||
9357
Config.paceCaret === "tagPb" ||
@@ -96,8 +60,35 @@ function update(): void {
9660
await PaceCaret.init();
9761
}
9862
void ModesNotice.update();
63+
TagController.saveActiveToLocalStorage();
9964
},
10065
});
66+
67+
for (const tag of snapshot.tags) {
68+
subgroup.list.push({
69+
id: "toggleTag" + tag._id,
70+
display: tag.display,
71+
sticky: true,
72+
active: () => {
73+
return (
74+
DB.getSnapshot()?.tags?.find((t) => t._id === tag._id)?.active ??
75+
false
76+
);
77+
},
78+
exec: async (): Promise<void> => {
79+
TagController.toggle(tag._id);
80+
81+
if (
82+
Config.paceCaret === "average" ||
83+
Config.paceCaret === "tagPb" ||
84+
Config.paceCaret === "daily"
85+
) {
86+
await PaceCaret.init();
87+
}
88+
void ModesNotice.update();
89+
},
90+
});
91+
}
10192
}
10293
subgroup.list.push({
10394
id: "createTag",

0 commit comments

Comments
 (0)