diff --git a/client/homebrew/editor/metadataEditor/metadataEditor.jsx b/client/homebrew/editor/metadataEditor/metadataEditor.jsx index 91da62aa0..0ae308fc8 100644 --- a/client/homebrew/editor/metadataEditor/metadataEditor.jsx +++ b/client/homebrew/editor/metadataEditor/metadataEditor.jsx @@ -9,21 +9,13 @@ const Nav = require('naturalcrit/nav/nav.jsx'); const StringArrayEditor = require('../stringArrayEditor/stringArrayEditor.jsx'); const Themes = require('themes/themes.json'); +const validations = require('./validations.js') const SYSTEMS = ['5e', '4e', '3.5e', 'Pathfinder']; const homebreweryThumbnail = require('../../thumbnail.png'); -const validators = { - thumbnail : [ - (value)=>{ - return value?.length > 5 ? 'Max URL length of 5 characters' : null; - }, - (value)=>{ - return (value ?? '')[0] !== 'W' ? 'URL must start with W' : null; - } - ] -}; + const MetadataEditor = createClass({ displayName : 'MetadataEditor', @@ -33,6 +25,7 @@ const MetadataEditor = createClass({ editId : null, title : '', description : '', + thumbnail : '', tags : [], published : false, authors : [], @@ -46,8 +39,8 @@ const MetadataEditor = createClass({ getInitialState : function(){ return { - showThumbnail : true, - validationError : null + showThumbnail : true, + errs : null }; }, @@ -63,20 +56,20 @@ const MetadataEditor = createClass({ }, handleFieldChange : function(name, e){ - const inputRules = validators[name] ?? []; + const inputRules = validations[name] ?? []; const validationErr = inputRules.map((rule)=>rule(e.target.value)).filter(Boolean); this.setState((prevState)=>({ - validationError : { - ...(prevState.validationError ?? {}), + errs : { + ...(prevState.errs ?? {}), [name] : validationErr.length > 0 ? validationErr : undefined } })); - if(Object.values(this.state.validationError ?? {}).filter(Boolean).length === 0){ + if(Object.values(this.state.errs ?? {}).filter(Boolean).length === 0){ this.props.onChange({ ...this.props.metadata, [name] : e.target.value }); - } + }; }, diff --git a/client/homebrew/editor/metadataEditor/validations.js b/client/homebrew/editor/metadataEditor/validations.js new file mode 100644 index 000000000..48d037b54 --- /dev/null +++ b/client/homebrew/editor/metadataEditor/validations.js @@ -0,0 +1,23 @@ +module.exports = { + title : [ + (value)=>{ + return value?.length > 10 ? 'Max URL length of 10 characters' : null; + } + ], + description : [ + (value)=>{ + return value?.length > 10 ? 'Max URL length of 10 characters' : null; + } + ], + thumbnail : [ + (value)=>{ + return value?.length > 5 ? 'Max URL length of 5 characters' : null; + }, + (value)=>{ + return (value ?? '')[0] !== 'W' ? 'URL must start with W' : null; + } + ] +}; + + +