mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-01-04 08:12:39 +00:00
Use index to find and remove tags
Fixes issue in last commit, so removing a tag that has duplicate value of other tags only removes the correct one, not the others as well.
This commit is contained in:
@@ -24,12 +24,12 @@ const TagInput = ({ unique = true, values = [], ...props }) => {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
const submitTag = (newValue, originalValue) => {
|
const submitTag = (newValue, originalValue, index) => {
|
||||||
setValueContext((prevContext) => {
|
setValueContext((prevContext) => {
|
||||||
// remove existing tag
|
// remove existing tag
|
||||||
if(newValue === null){
|
if(newValue === null){
|
||||||
console.log('remove');
|
console.log('remove');
|
||||||
return [...prevContext].filter((context)=>context.value !== originalValue);
|
return [...prevContext].filter((context, i)=>i !== index);
|
||||||
}
|
}
|
||||||
// add new tag
|
// add new tag
|
||||||
if(originalValue === null){
|
if(originalValue === null){
|
||||||
@@ -63,7 +63,7 @@ const TagInput = ({ unique = true, values = [], ...props }) => {
|
|||||||
className='tag'
|
className='tag'
|
||||||
onClick={() => editTag(context.value)}>
|
onClick={() => editTag(context.value)}>
|
||||||
{context.value}
|
{context.value}
|
||||||
<button onClick={(evt)=>{evt.stopPropagation(); submitTag(null, context.value)}}><i className='fa fa-times fa-fw'/></button>
|
<button onClick={(evt)=>{evt.stopPropagation(); submitTag(null, context.value, index)}}><i className='fa fa-times fa-fw'/></button>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user