From 52fbb3e58472657289b4ea3583393a91ebf853d8 Mon Sep 17 00:00:00 2001 From: f0x52 Date: Tue, 7 Feb 2023 18:34:54 +0100 Subject: [PATCH] [bugfix] fix 'steal this look' form, uncheck entries after processing (#1454) --- .../admin/emoji/remote/parse-from-toot.js | 18 ++++++++++++++++-- web/source/settings/lib/form/check-list.jsx | 2 +- web/source/settings/lib/form/submit.js | 11 +++++++++-- .../settings/lib/query/admin/custom-emoji.js | 2 +- 4 files changed, 27 insertions(+), 6 deletions(-) diff --git a/web/source/settings/admin/emoji/remote/parse-from-toot.js b/web/source/settings/admin/emoji/remote/parse-from-toot.js index 84bbbdc92..905deee30 100644 --- a/web/source/settings/admin/emoji/remote/parse-from-toot.js +++ b/web/source/settings/admin/emoji/remote/parse-from-toot.js @@ -115,12 +115,26 @@ function CopyEmojiForm({ localEmojiCodes, type, emojiList }) { const form = { selectedEmoji: useCheckListInput("selectedEmoji", { entries: emojiList, - uniqueKey: "shortcode" + uniqueKey: "id" }), category: useComboBoxInput("category") }; - const [formSubmit, result] = useFormSubmit(form, query.usePatchRemoteEmojisMutation(), { changedOnly: false }); + const [formSubmit, result] = useFormSubmit( + form, + query.usePatchRemoteEmojisMutation(), + { + changedOnly: false, + onFinish: ({ data }) => { + if (data != undefined) { + form.selectedEmoji.updateMultiple( + // uncheck all successfully processed emoji + data.map(([id]) => [id, { checked: false }]) + ); + } + } + } + ); const buttonsInactive = form.selectedEmoji.someSelected ? {} diff --git a/web/source/settings/lib/form/check-list.jsx b/web/source/settings/lib/form/check-list.jsx index 7827671be..8412df077 100644 --- a/web/source/settings/lib/form/check-list.jsx +++ b/web/source/settings/lib/form/check-list.jsx @@ -171,7 +171,7 @@ module.exports = function useCheckListInput({ name }, { entries, uniqueKey = "ke onChange, selectedValues, reset, - someSelected: state.someChecked, + someSelected: state.selectedEntries.size > 0, updateMultiple, toggleAll: { ref: toggleAllRef, diff --git a/web/source/settings/lib/form/submit.js b/web/source/settings/lib/form/submit.js index 2a81307c5..46a182885 100644 --- a/web/source/settings/lib/form/submit.js +++ b/web/source/settings/lib/form/submit.js @@ -18,10 +18,11 @@ "use strict"; +const Promise = require("bluebird"); const React = require("react"); const syncpipe = require("syncpipe"); -module.exports = function useFormSubmit(form, mutationQuery, { changedOnly = true } = {}) { +module.exports = function useFormSubmit(form, mutationQuery, { changedOnly = true, onFinish } = {}) { if (!Array.isArray(mutationQuery)) { throw new ("useFormSubmit: mutationQuery was not an Array. Is a valid useMutation RTK Query provided?"); } @@ -64,7 +65,13 @@ module.exports = function useFormSubmit(form, mutationQuery, { changedOnly = tru mutationData.action = action; - return runMutation(mutationData); + return Promise.try(() => { + return runMutation(mutationData); + }).then((res) => { + if (onFinish) { + return onFinish(res); + } + }); }, { ...result, diff --git a/web/source/settings/lib/query/admin/custom-emoji.js b/web/source/settings/lib/query/admin/custom-emoji.js index e8fe08852..163c1f61a 100644 --- a/web/source/settings/lib/query/admin/custom-emoji.js +++ b/web/source/settings/lib/query/admin/custom-emoji.js @@ -149,7 +149,7 @@ module.exports = (build) => ({ body: body }).then(unwrapRes); }).then((res) => { - data.push([emoji.shortcode, res]); + data.push([emoji.id, res]); }).catch((e) => { let msg = e.message ?? e; if (e.data.error) {