Skip to content

Commit

Permalink
[bugfix] fix 'steal this look' form, uncheck entries after processing (
Browse files Browse the repository at this point in the history
  • Loading branch information
f0x52 authored Feb 7, 2023
1 parent 4e4da19 commit 52fbb3e
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 6 deletions.
18 changes: 16 additions & 2 deletions web/source/settings/admin/emoji/remote/parse-from-toot.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
? {}
Expand Down
2 changes: 1 addition & 1 deletion web/source/settings/lib/form/check-list.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
11 changes: 9 additions & 2 deletions web/source/settings/lib/form/submit.js
Original file line number Diff line number Diff line change
Expand Up @@ -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?");
}
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion web/source/settings/lib/query/admin/custom-emoji.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 52fbb3e

Please sign in to comment.