fix validation order

This commit is contained in:
f0x 2022-11-07 16:00:51 +00:00
parent 886e663382
commit 41f25653d1

View file

@ -20,7 +20,6 @@
const Promise = require("bluebird"); const Promise = require("bluebird");
const React = require("react"); const React = require("react");
const Redux = require("react-redux");
const {Link} = require("wouter"); const {Link} = require("wouter");
const defaultValue = require('default-value'); const defaultValue = require('default-value');
const prettierBytes = require("prettier-bytes"); const prettierBytes = require("prettier-bytes");
@ -166,28 +165,26 @@ function NewEmoji({emoji}) {
function onShortChange(e) { function onShortChange(e) {
let input = e.target.value; let input = e.target.value;
setShortcode(input); setShortcode(input);
validateShortcode(input);
} }
function validateShortcode(code) { React.useEffect(() => {
console.log("code: (%s)", code); if (emojiCodes.has(shortcode)) {
if (emojiCodes.has(code)) {
shortcodeRef.current.setCustomValidity("Shortcode already in use"); shortcodeRef.current.setCustomValidity("Shortcode already in use");
} else { } else {
shortcodeRef.current.setCustomValidity(""); shortcodeRef.current.setCustomValidity("");
} }
shortcodeRef.current.reportValidity(); shortcodeRef.current.reportValidity();
} }, [shortcode, shortcodeRef, emojiCodes]);
React.useEffect(() => { React.useEffect(() => {
if (shortcode.length == 0) { if (shortcode.length == 0) {
if (file != undefined) { if (file != undefined) {
let [name, _ext] = file.name.split("."); let [name, _ext] = file.name.split(".");
setShortcode(name); setShortcode(name);
validateShortcode(name);
} }
} }
}, [file, shortcode]); // eslint-disable-next-line react-hooks/exhaustive-deps
}, [file]);
function uploadEmoji(e) { function uploadEmoji(e) {
if (e) { if (e) {