0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2025-12-24 22:52:40 +00:00

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.
This commit is contained in:
Trevor Buckner
2025-01-05 23:04:48 -05:00
parent c137d40037
commit 85cd7c7336

View File

@@ -1,6 +1,5 @@
require('./errorBar.less');
const React = require('react');
const _ = require('lodash');
import Dialog from '../../../components/dialog.jsx';
@@ -9,13 +8,15 @@ 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>
{_.map(props.errors, (err, idx)=>{
if(err.id === 'OPEN') hasOpenError = true;
if(err.id === 'CLOSE') hasCloseError = true;
if(err.id === 'MISMATCH') hasMatchError = true;
return (
{props.errors.map((err, idx)=>{
<li key={idx}>
Line {err.line} : {err.text}, '{err.type}' tag
</li>