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() { }">