From 41f25653d14c3952f7a3e9a95405340b4150b2e6 Mon Sep 17 00:00:00 2001 From: f0x Date: Mon, 7 Nov 2022 16:00:51 +0000 Subject: [PATCH] fix validation order --- web/source/settings/admin/emoji/overview.js | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/web/source/settings/admin/emoji/overview.js b/web/source/settings/admin/emoji/overview.js index e637ba3da..5d116f15d 100644 --- a/web/source/settings/admin/emoji/overview.js +++ b/web/source/settings/admin/emoji/overview.js @@ -20,7 +20,6 @@ const Promise = require("bluebird"); const React = require("react"); -const Redux = require("react-redux"); const {Link} = require("wouter"); const defaultValue = require('default-value'); const prettierBytes = require("prettier-bytes"); @@ -166,28 +165,26 @@ function NewEmoji({emoji}) { function onShortChange(e) { let input = e.target.value; setShortcode(input); - validateShortcode(input); } - function validateShortcode(code) { - console.log("code: (%s)", code); - if (emojiCodes.has(code)) { + React.useEffect(() => { + if (emojiCodes.has(shortcode)) { shortcodeRef.current.setCustomValidity("Shortcode already in use"); } else { shortcodeRef.current.setCustomValidity(""); } shortcodeRef.current.reportValidity(); - } + }, [shortcode, shortcodeRef, emojiCodes]); React.useEffect(() => { if (shortcode.length == 0) { if (file != undefined) { let [name, _ext] = file.name.split("."); setShortcode(name); - validateShortcode(name); } } - }, [file, shortcode]); + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [file]); function uploadEmoji(e) { if (e) {