0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2025-12-26 00:52:48 +00:00
Files
homebrewery/client/homebrew/brewRenderer/errorBar/errorBar.jsx
Trevor Buckner 85cd7c7336 Move calculation of error states outside of render
Our previous approach was technically bad practice to calculate side-effects inside of the render step. We can separate that out as part of this refactor.

Also use native javascript map instead of lodash.
2025-01-05 23:04:48 -05:00

57 lines
1.5 KiB
JavaScript

require('./errorBar.less');
const React = require('react');
import Dialog from '../../../components/dialog.jsx';
const DISMISS_BUTTON = <i className='fas fa-times dismiss' />;
const ErrorBar = (props)=>{
let hasOpenError = false, hasCloseError = false, hasMatchError = false;
props.errors.map( err => {
if(err.id === 'OPEN') hasOpenError = true;
if(err.id === 'CLOSE') hasCloseError = true;
if(err.id === 'MISMATCH') hasMatchError = true;
});
const renderErrors = ()=>(
<ul>
{props.errors.map((err, idx)=>{
<li key={idx}>
Line {err.line} : {err.text}, '{err.type}' tag
</li>
);
})}
</ul>
);
const renderProtip = ()=>(
<div className='protips'>
<h4>Protips!</h4>
{hasOpenError && <div>Unmatched opening tag. Close your tags, like this {'</div>'}. Match types!</div>}
{hasCloseError && <div>Unmatched closing tag. Either remove it or check where it was opened.</div>}
{hasMatchError && <div>Type mismatch. Closed a tag with a different type.</div>}
</div>
);
if(!props.errors.length) return null;
return (
<Dialog className='errorBar' closeText={DISMISS_BUTTON} >
<div>
<i className='fas fa-exclamation-triangle' />
<h2> There are HTML errors in your markup</h2>
<small>
If these aren't fixed your brew will not render properly when you print it to PDF or share it
</small>
{renderErrors()}
</div>
<hr />
{renderProtip()}
</Dialog>
);
};
module.exports = ErrorBar;