mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-01-07 05:32:41 +00:00
Variable name changes for clarity
Followed suggestions on the PR.
This commit is contained in:
@@ -4,12 +4,12 @@ const { useState, useEffect } = React;
|
|||||||
const _ = require('lodash');
|
const _ = require('lodash');
|
||||||
|
|
||||||
const TagInput = ({ unique = true, values = [], ...props }) => {
|
const TagInput = ({ unique = true, values = [], ...props }) => {
|
||||||
const [temporaryValue, setTemporaryValue] = useState('');
|
const [tempInputText, setTempInputText] = useState('');
|
||||||
const [valueContext, setValueContext] = useState(values.map((value) => ({ value, editing: false })));
|
const [tagList, setTagList] = useState(values.map((value) => ({ value, editing: false })));
|
||||||
|
|
||||||
useEffect(()=>{
|
useEffect(()=>{
|
||||||
handleChange(valueContext.map((context)=>context.value))
|
handleChange(tagList.map((context)=>context.value))
|
||||||
}, [valueContext])
|
}, [tagList])
|
||||||
|
|
||||||
const handleChange = (value)=>{
|
const handleChange = (value)=>{
|
||||||
props.onChange({
|
props.onChange({
|
||||||
@@ -22,13 +22,13 @@ const TagInput = ({ unique = true, values = [], ...props }) => {
|
|||||||
evt.preventDefault();
|
evt.preventDefault();
|
||||||
submitTag(evt.target.value, value, index);
|
submitTag(evt.target.value, value, index);
|
||||||
if (options.clear) {
|
if (options.clear) {
|
||||||
setTemporaryValue('');
|
setTempInputText('');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const submitTag = (newValue, originalValue, index) => {
|
const submitTag = (newValue, originalValue, index) => {
|
||||||
setValueContext((prevContext) => {
|
setTagList((prevContext) => {
|
||||||
// remove existing tag
|
// remove existing tag
|
||||||
if(newValue === null){
|
if(newValue === null){
|
||||||
return [...prevContext].filter((context, i)=>i !== index);
|
return [...prevContext].filter((context, i)=>i !== index);
|
||||||
@@ -48,7 +48,7 @@ const TagInput = ({ unique = true, values = [], ...props }) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const editTag = (index) => {
|
const editTag = (index) => {
|
||||||
setValueContext((prevContext) => {
|
setTagList((prevContext) => {
|
||||||
return prevContext.map((context, i) => {
|
return prevContext.map((context, i) => {
|
||||||
if (i === index) {
|
if (i === index) {
|
||||||
return { ...context, editing: true };
|
return { ...context, editing: true };
|
||||||
@@ -86,15 +86,15 @@ const TagInput = ({ unique = true, values = [], ...props }) => {
|
|||||||
<label>{props.label}</label>
|
<label>{props.label}</label>
|
||||||
<div className='value'>
|
<div className='value'>
|
||||||
<ul className='list'>
|
<ul className='list'>
|
||||||
{valueContext.map((context, index) => { return context.editing ? renderWriteTag(context, index) : renderReadTag(context, index); })}
|
{tagList.map((context, index) => { return context.editing ? renderWriteTag(context, index) : renderReadTag(context, index); })}
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
<input
|
<input
|
||||||
type='text'
|
type='text'
|
||||||
className='value'
|
className='value'
|
||||||
placeholder={props.placeholder}
|
placeholder={props.placeholder}
|
||||||
value={temporaryValue}
|
value={tempInputText}
|
||||||
onChange={(e) => setTemporaryValue(e.target.value)}
|
onChange={(e) => setTempInputText(e.target.value)}
|
||||||
onKeyDown={(evt) => handleInputKeyDown({ evt, value: null, options: { clear: true } })}
|
onKeyDown={(evt) => handleInputKeyDown({ evt, value: null, options: { clear: true } })}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user