mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-11-04 22:38:43 +00:00
simplify functions and reorder imports
This commit is contained in:
@@ -2,13 +2,14 @@
|
|||||||
import '../uiEditor.less';
|
import '../uiEditor.less';
|
||||||
import React, { useState } from 'react';
|
import React, { useState } from 'react';
|
||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
import request from '../../utils/request-middleware.js';
|
|
||||||
import Combobox from '@components/combobox.jsx';
|
|
||||||
import TagInput from '../tagInput/tagInput.jsx';
|
|
||||||
|
|
||||||
|
import request from '../../utils/request-middleware.js';
|
||||||
import Themes from '@themes/themes.json';
|
import Themes from '@themes/themes.json';
|
||||||
import validations from './validations.js';
|
import validations from './validations.js';
|
||||||
|
|
||||||
|
import Combobox from '@components/combobox.jsx';
|
||||||
|
import TagInput from '../tagInput/tagInput.jsx';
|
||||||
|
|
||||||
import homebreweryThumbnail from '../../thumbnail.png';
|
import homebreweryThumbnail from '../../thumbnail.png';
|
||||||
|
|
||||||
const callIfExists = (val, fn, ...args)=>{
|
const callIfExists = (val, fn, ...args)=>{
|
||||||
@@ -31,20 +32,12 @@ const MetadataEditor = ({
|
|||||||
theme : '5ePHB',
|
theme : '5ePHB',
|
||||||
lang : 'en',
|
lang : 'en',
|
||||||
},
|
},
|
||||||
|
|
||||||
onChange = ()=>{},
|
onChange = ()=>{},
|
||||||
reportError = ()=>{},
|
reportError = ()=>{},
|
||||||
...props
|
...props
|
||||||
})=>{
|
})=>{
|
||||||
const [showThumbnail, setShowThumbnail] = useState(true);
|
const [showThumbnail, setShowThumbnail] = useState(true);
|
||||||
|
|
||||||
const toggleThumbnailDisplay = ()=>{
|
|
||||||
setShowThumbnail(!showThumbnail);
|
|
||||||
};
|
|
||||||
const renderThumbnail = ()=>{
|
|
||||||
if(!showThumbnail) return;
|
|
||||||
return <img className='thumbnail-preview' src={metadata.thumbnail || homebreweryThumbnail}></img>;
|
|
||||||
};
|
|
||||||
const handleFieldChange = (name, e)=>{
|
const handleFieldChange = (name, e)=>{
|
||||||
// load validation rules, and check input value against them
|
// load validation rules, and check input value against them
|
||||||
const inputRules = validations[name] ?? [];
|
const inputRules = validations[name] ?? [];
|
||||||
@@ -141,18 +134,6 @@ const MetadataEditor = ({
|
|||||||
</button>;
|
</button>;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
const renderDelete = ()=>{
|
|
||||||
if(!metadata.editId) return;
|
|
||||||
|
|
||||||
return <div className='field delete'>
|
|
||||||
<label htmlFor='delete-button'>delete</label>
|
|
||||||
<div className='value'>
|
|
||||||
<button id='delete-button' onClick={handleDelete}>
|
|
||||||
<i className='fas fa-trash-alt' /> delete brew
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
</div>;
|
|
||||||
};
|
|
||||||
const renderAuthors = ()=>{
|
const renderAuthors = ()=>{
|
||||||
const authors = metadata.authors;
|
const authors = metadata.authors;
|
||||||
const isOwner = global.account?.username && global.account?.username === authors[0];
|
const isOwner = global.account?.username && global.account?.username === authors[0];
|
||||||
@@ -296,7 +277,6 @@ const MetadataEditor = ({
|
|||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>;
|
</div>;
|
||||||
};
|
};
|
||||||
const renderRenderOptions = ()=>{
|
const renderRenderOptions = ()=>{
|
||||||
@@ -364,13 +344,13 @@ const MetadataEditor = ({
|
|||||||
/>
|
/>
|
||||||
<button
|
<button
|
||||||
className='display'
|
className='display'
|
||||||
onClick={toggleThumbnailDisplay}
|
onClick={()=>setShowThumbnail(!showThumbnail)}
|
||||||
aria-label={`${showThumbnail ? 'hide thumbnail' : 'show thumbnail'}`}>
|
aria-label={`${showThumbnail ? 'hide thumbnail' : 'show thumbnail'}`}>
|
||||||
<i className={`fas fa-caret-${showThumbnail ? 'right' : 'left'}`} />
|
<i className={`fas fa-caret-${showThumbnail ? 'right' : 'left'}`} />
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{renderThumbnail()}
|
{showThumbnail && <img className='thumbnail-preview' src={metadata.thumbnail || homebreweryThumbnail}></img>}
|
||||||
</fieldset>
|
</fieldset>
|
||||||
|
|
||||||
<div className='field tags'>
|
<div className='field tags'>
|
||||||
@@ -431,7 +411,14 @@ const MetadataEditor = ({
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{renderDelete()}
|
{metadata.editId && <div className='field delete'>
|
||||||
|
<label htmlFor='delete-button'>delete</label>
|
||||||
|
<div className='value'>
|
||||||
|
<button id='delete-button' onClick={handleDelete}>
|
||||||
|
<i className='fas fa-trash-alt' /> delete brew
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user