From e404d818c1f9e987177ad421bbf1262ce16b4100 Mon Sep 17 00:00:00 2001 From: Jack Date: Mon, 5 Jul 2021 23:31:17 +0100 Subject: [PATCH] added a button to clear tag pb --- functions/index.js | 2 +- src/js/popups/edit-tags-popup.js | 28 ++++++++++++++++++++++++++++ src/js/settings.js | 29 ++++++++++++++++++++--------- 3 files changed, 49 insertions(+), 10 deletions(-) diff --git a/functions/index.js b/functions/index.js index 4d8f08fe5..0237a74b0 100644 --- a/functions/index.js +++ b/functions/index.js @@ -781,7 +781,7 @@ exports.clearTagPb = functions.https.onCall((request, response) => { .collection(`users/${request.uid}/tags`) .doc(request.tagid) .update({ - pb: 0, + personalBests: admin.firestore.FieldValue.delete(), }) .then((e) => { return { diff --git a/src/js/popups/edit-tags-popup.js b/src/js/popups/edit-tags-popup.js index f71cacc30..89d659201 100644 --- a/src/js/popups/edit-tags-popup.js +++ b/src/js/popups/edit-tags-popup.js @@ -26,6 +26,12 @@ export function show(action, id, name) { $("#tagsWrapper #tagsEdit .title").html("Remove tag " + name); $("#tagsWrapper #tagsEdit .button").html(``); $("#tagsWrapper #tagsEdit input").addClass("hidden"); + } else if (action === "clearPb") { + $("#tagsWrapper #tagsEdit").attr("action", "clearPb"); + $("#tagsWrapper #tagsEdit").attr("tagid", id); + $("#tagsWrapper #tagsEdit .title").html("Clear PB for tag " + name); + $("#tagsWrapper #tagsEdit .button").html(``); + $("#tagsWrapper #tagsEdit input").addClass("hidden"); } if ($("#tagsWrapper").hasClass("hidden")) { @@ -134,6 +140,28 @@ function apply() { Notifications.add("Unknown error: " + e.data.message, -1); } }); + } else if (action === "clearPb") { + Loader.show(); + CloudFunctions.clearTagPb({ + uid: firebase.auth().currentUser.uid, + tagid: tagid, + }).then((e) => { + Loader.hide(); + let status = e.data.resultCode; + if (status === 1) { + Notifications.add("PB cleared", 1); + DB.getSnapshot().tags.forEach((tag, index) => { + if (tag.id === tagid) { + tag.personalBests = {}; + } + }); + ResultTagsPopup.updateButtons(); + Settings.update(); + ResultFilters.updateTags(); + } else if (status < -1) { + Notifications.add("Unknown error: " + e.data.message, -1); + } + }); } } diff --git a/src/js/settings.js b/src/js/settings.js index 18616889e..06746b2aa 100644 --- a/src/js/settings.js +++ b/src/js/settings.js @@ -427,6 +427,9 @@ function refreshTagsSettingsSection() { }">
${tag.name}
+
+ +
@@ -715,22 +718,27 @@ $(document).on( $(document).on( "click", - ".pageSettings .section.tags .tagsList .tag .clearPbButton", + ".pageSettings .section.tags .tagsList .tag .editButton", (e) => { - let target = e.currentTarget; - let tagid = $(target).parent(".tag").attr("id"); - let tagname = $(target).siblings(".title")[0].innerHTML; - SimplePopups.list.clearTagPb.show([tagid, tagname]); + let tagid = $(e.currentTarget).parent(".tag").attr("id"); + let name = $(e.currentTarget) + .siblings(".tagButton") + .children(".title") + .text(); + EditTagsPopup.show("edit", tagid, name); } ); $(document).on( "click", - ".pageSettings .section.tags .tagsList .tag .editButton", + ".pageSettings .section.tags .tagsList .tag .clearPbButton", (e) => { let tagid = $(e.currentTarget).parent(".tag").attr("id"); - let name = $(e.currentTarget).siblings(".title").text(); - EditTagsPopup.show("edit", tagid, name); + let name = $(e.currentTarget) + .siblings(".tagButton") + .children(".title") + .text(); + EditTagsPopup.show("clearPb", tagid, name); } ); @@ -739,7 +747,10 @@ $(document).on( ".pageSettings .section.tags .tagsList .tag .removeButton", (e) => { let tagid = $(e.currentTarget).parent(".tag").attr("id"); - let name = $(e.currentTarget).siblings(".title").text(); + let name = $(e.currentTarget) + .siblings(".tagButton") + .children(".title") + .text(); EditTagsPopup.show("remove", tagid, name); } );