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 925117be3..dc56ae48a 100644 --- a/web/source/settings/admin/emoji/remote/parse-from-toot.js +++ b/web/source/settings/admin/emoji/remote/parse-from-toot.js @@ -29,11 +29,15 @@ const { useCheckListInput } = require("../../../lib/form"); +const useFormSubmit = require("../../../lib/form/submit"); + const CheckList = require("../../../components/check-list"); const { CategorySelect } = require('../category-select'); const query = require("../../../lib/query"); const Loading = require("../../../components/loading"); +const { TextInput } = require("../../../components/form/inputs"); +const MutationButton = require("../../../components/form/mutation-button"); module.exports = function ParseFromToot({ emojiCodes }) { const [searchStatus, { data, isLoading, isSuccess, error }] = query.useSearchStatusForEmojiMutation(); @@ -70,7 +74,9 @@ module.exports = function ParseFromToot({ emojiCodes }) { function submitSearch(e) { e.preventDefault(); - searchStatus(url); + if (url.trim().length != 0) { + searchStatus(url); + } } return ( @@ -91,7 +97,7 @@ module.exports = function ParseFromToot({ emojiCodes }) { /> - {isLoading && } {error &&
{error.data.error}
} @@ -119,22 +124,25 @@ function CopyEmojiForm({ localEmojiCodes, type, domain, emojiList }) { const [categoryState, resetCategory, { category }] = useComboBoxInput("category"); + const buttonsInactive = emojiCheckList.someSelected + ? {} + : { + disabled: true, + title: "No emoji selected, cannot perform any actions" + }; + function submit(action) { Promise.try(() => { setError(null); - const selectedShortcodes = syncpipe(emojiCheckList.value, [ - (_) => Object.entries(_), - (_) => _.filter(([_shortcode, entry]) => entry.checked), - (_) => _.map(([shortcode, entry]) => { - if (action == "copy" && !entry.valid) { - throw `One or more selected emoji have non-unique shortcodes (${shortcode}), unselect them or pick a different local shortcode`; - } - return { - shortcode, - localShortcode: entry.shortcode - }; - }) - ]); + const selectedShortcodes = emojiCheckList.selectedValues.map(([shortcode, entry]) => { + if (action == "copy" && !entry.valid) { + throw `One or more selected emoji have non-unique shortcodes (${shortcode}), unselect them or pick a different local shortcode`; + } + return { + shortcode, + localShortcode: entry.shortcode + }; + }); return patchRemoteEmojis({ action, @@ -166,15 +174,6 @@ function CopyEmojiForm({ localEmojiCodes, type, domain, emojiList }) { Component={EmojiEntry} localEmojiCodes={localEmojiCodes} /> - {/* {emojiList.map((emoji) => ( - updateEmoji(emoji.shortcode, value)} - checked={emojiState[emoji.shortcode].checked} - /> - ))} */}
- - + +
{err &&
{err} @@ -196,7 +195,7 @@ function CopyEmojiForm({ localEmojiCodes, type, domain, emojiList }) { } function EmojiEntry({ entry: emoji, localEmojiCodes, onChange }) { - const [onShortcodeChange, _resetShortcode, { shortcode, shortcodeRef, shortcodeValid }] = useTextInput("shortcode", { + const shortcodeField = useTextInput("shortcode", { defaultValue: emoji.shortcode, validator: function validateShortcode(code) { return (emoji.checked && localEmojiCodes.has(code)) @@ -206,24 +205,20 @@ function EmojiEntry({ entry: emoji, localEmojiCodes, onChange }) { }); React.useEffect(() => { - onChange({ valid: shortcodeValid }); + onChange({ valid: shortcodeField.valid }); /* eslint-disable-next-line react-hooks/exhaustive-deps */ - }, [shortcodeValid]); + }, [shortcodeField.valid]); return ( <> - { - onShortcodeChange(e); + shortcodeField.onChange(e); onChange({ shortcode: e.target.value, checked: true }); }} - value={shortcode} /> ); diff --git a/web/source/settings/components/check-list.jsx b/web/source/settings/components/check-list.jsx index 980ca45b6..4281c2110 100644 --- a/web/source/settings/components/check-list.jsx +++ b/web/source/settings/components/check-list.jsx @@ -22,7 +22,7 @@ const React = require("react"); module.exports = function CheckList({ field, Component, ...componentProps }) { return ( -
+