mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2025-10-29 02:07:55 +08:00
added button to the result page that allows you to update tags for the result
only shows up if user has tags closes #3642
This commit is contained in:
parent
ef923f3de2
commit
69b02569ee
5 changed files with 82 additions and 23 deletions
|
|
@ -447,6 +447,12 @@
|
|||
// "login login"
|
||||
// "ssw ssw";
|
||||
|
||||
.editTagsButton {
|
||||
display: inline-block;
|
||||
font-size: 0.75rem;
|
||||
padding-bottom: 0;
|
||||
}
|
||||
|
||||
&:focus {
|
||||
outline: none;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ export function updateButtons(): void {
|
|||
}
|
||||
|
||||
function updateActiveButtons(active: string[]): void {
|
||||
if (active === []) return;
|
||||
if (active.length === 0) return;
|
||||
$.each($("#resultEditTagsPanel .buttons .button"), (_, obj) => {
|
||||
const tagid: string = $(obj).attr("tagid") ?? "";
|
||||
if (active.includes(tagid)) {
|
||||
|
|
@ -57,6 +57,7 @@ $(document).on("click", ".pageAccount .group.history #resultEditTags", (f) => {
|
|||
const tags = $(f.target).parents("span").attr("tags") as string;
|
||||
$("#resultEditTagsPanel").attr("resultid", resultid);
|
||||
$("#resultEditTagsPanel").attr("tags", tags);
|
||||
$("#resultEditTagsPanel").attr("source", "accountPage");
|
||||
updateActiveButtons(JSON.parse(tags));
|
||||
show();
|
||||
} else {
|
||||
|
|
@ -68,6 +69,22 @@ $(document).on("click", ".pageAccount .group.history #resultEditTags", (f) => {
|
|||
}
|
||||
});
|
||||
|
||||
$(document).on("click", ".pageTest .tags .editTagsButton", () => {
|
||||
if (DB.getSnapshot().tags?.length ?? 0 > 0) {
|
||||
const resultid = $(".pageTest .tags .editTagsButton").attr(
|
||||
"result-id"
|
||||
) as string;
|
||||
const tags = $(".pageTest .tags .editTagsButton")
|
||||
.attr("active-tag-ids")
|
||||
?.split(",") as string[];
|
||||
$("#resultEditTagsPanel").attr("resultid", resultid);
|
||||
$("#resultEditTagsPanel").attr("tags", JSON.stringify(tags));
|
||||
$("#resultEditTagsPanel").attr("source", "resultPage");
|
||||
updateActiveButtons(tags);
|
||||
show();
|
||||
}
|
||||
});
|
||||
|
||||
$(document).on("click", "#resultEditTagsPanelWrapper .button.tag", (f) => {
|
||||
$(f.target).toggleClass("active");
|
||||
});
|
||||
|
|
@ -111,17 +128,16 @@ $("#resultEditTagsPanel .confirmButton").on("click", async () => {
|
|||
}
|
||||
);
|
||||
|
||||
let tagNames = "";
|
||||
const tagNames: string[] = [];
|
||||
|
||||
if (newTags.length > 0) {
|
||||
newTags.forEach((tag) => {
|
||||
DB.getSnapshot().tags?.forEach((snaptag) => {
|
||||
if (tag === snaptag._id) {
|
||||
tagNames += snaptag.display + ", ";
|
||||
tagNames.push(snaptag.display);
|
||||
}
|
||||
});
|
||||
});
|
||||
tagNames = tagNames.substring(0, tagNames.length - 2);
|
||||
}
|
||||
|
||||
let restags;
|
||||
|
|
@ -135,20 +151,29 @@ $("#resultEditTagsPanel .confirmButton").on("click", async () => {
|
|||
"tags",
|
||||
restags
|
||||
);
|
||||
if (newTags.length > 0) {
|
||||
$(`.pageAccount #resultEditTags[resultid='${resultId}']`).css("opacity", 1);
|
||||
$(`.pageAccount #resultEditTags[resultid='${resultId}']`).attr(
|
||||
"aria-label",
|
||||
tagNames
|
||||
);
|
||||
} else {
|
||||
$(`.pageAccount #resultEditTags[resultid='${resultId}']`).css(
|
||||
"opacity",
|
||||
0.25
|
||||
);
|
||||
$(`.pageAccount #resultEditTags[resultid='${resultId}']`).attr(
|
||||
"aria-label",
|
||||
"no tags"
|
||||
);
|
||||
const source = $("#resultEditTagsPanel").attr("source") as string;
|
||||
|
||||
if (source === "accountPage") {
|
||||
if (newTags.length > 0) {
|
||||
$(`.pageAccount #resultEditTags[resultid='${resultId}']`).css(
|
||||
"opacity",
|
||||
1
|
||||
);
|
||||
$(`.pageAccount #resultEditTags[resultid='${resultId}']`).attr(
|
||||
"aria-label",
|
||||
tagNames.join(", ")
|
||||
);
|
||||
} else {
|
||||
$(`.pageAccount #resultEditTags[resultid='${resultId}']`).css(
|
||||
"opacity",
|
||||
0.25
|
||||
);
|
||||
$(`.pageAccount #resultEditTags[resultid='${resultId}']`).attr(
|
||||
"aria-label",
|
||||
"no tags"
|
||||
);
|
||||
}
|
||||
} else if (source === "resultPage") {
|
||||
$(`.pageTest #result .tags .bottom`).html(tagNames.join("<br>"));
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -402,6 +402,7 @@ export async function updateCrown(): Promise<void> {
|
|||
|
||||
function updateTags(dontSave: boolean): void {
|
||||
const activeTags: MonkeyTypes.Tag[] = [];
|
||||
const userTagsCount = DB.getSnapshot().tags?.length ?? 0;
|
||||
try {
|
||||
DB.getSnapshot().tags?.forEach((tag) => {
|
||||
if (tag.active === true) {
|
||||
|
|
@ -410,13 +411,23 @@ function updateTags(dontSave: boolean): void {
|
|||
});
|
||||
} catch (e) {}
|
||||
|
||||
$("#result .stats .tags").addClass("hidden");
|
||||
if (activeTags.length == 0) {
|
||||
if (userTagsCount === 0) {
|
||||
$("#result .stats .tags").addClass("hidden");
|
||||
} else {
|
||||
$("#result .stats .tags").removeClass("hidden");
|
||||
}
|
||||
$("#result .stats .tags .bottom").text("");
|
||||
if (activeTags.length === 0) {
|
||||
$("#result .stats .tags .bottom").text("no tags");
|
||||
} else {
|
||||
$("#result .stats .tags .bottom").text("");
|
||||
}
|
||||
$("#result .stats .tags .editTagsButton").attr("result-id", "");
|
||||
$("#result .stats .tags .editTagsButton").attr(
|
||||
"active-tag-ids",
|
||||
activeTags.map((t) => t._id).join(",")
|
||||
);
|
||||
$("#result .stats .tags .editTagsButton").addClass("invisible");
|
||||
|
||||
let annotationSide = "start";
|
||||
let labelAdjust = 15;
|
||||
activeTags.forEach(async (tag) => {
|
||||
|
|
|
|||
|
|
@ -1746,6 +1746,12 @@ async function saveResult(
|
|||
return Notifications.add("Failed to save result: " + response.message, -1);
|
||||
}
|
||||
|
||||
$("#result .stats .tags .editTagsButton").attr(
|
||||
"result-id",
|
||||
response.data.insertedId
|
||||
);
|
||||
$("#result .stats .tags .editTagsButton").removeClass("invisible");
|
||||
|
||||
if (response?.data?.xp) {
|
||||
const snapxp = DB.getSnapshot().xp;
|
||||
AccountButton.updateXpBar(
|
||||
|
|
|
|||
|
|
@ -191,7 +191,18 @@
|
|||
<div class="top">test type</div>
|
||||
<div class="bottom">-</div>
|
||||
<div class="tags hidden" style="margin-top: 0.5rem">
|
||||
<div class="top">tags</div>
|
||||
<div class="top">
|
||||
tags
|
||||
<div
|
||||
class="textButton editTagsButton"
|
||||
result-id=""
|
||||
active-tag-ids=""
|
||||
aria-label="Edit tags"
|
||||
data-balloon-pos="right"
|
||||
>
|
||||
<i class="fas fa-pen fa-fw"></i>
|
||||
</div>
|
||||
</div>
|
||||
<div class="bottom">-</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue