mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2025-12-30 13:12:40 +00:00
Add in handlers for TagInput value changes
Now brew metadata is actually updated and preserved across reloads to match updated tag values. useEffect calls the props.onChange event from the parent component on every change to the valueContext state of this component (right now, after hitting Enter in a tag input).
This commit is contained in:
@@ -347,7 +347,7 @@ const MetadataEditor = createClass({
|
||||
<TagInput label='tags' valuePatterns={[/^(?:(?:group|meta|system|type):)?[A-Za-z0-9][A-Za-z0-9 \/.\-]{0,40}$/]}
|
||||
placeholder='add tag' unique={true}
|
||||
values={this.props.metadata.tags}
|
||||
// onChange={(e)=>this.handleFieldChange('tags', e)}
|
||||
onChange={(e)=>this.handleFieldChange('tags', e)}
|
||||
/>
|
||||
|
||||
<div className='field systems'>
|
||||
@@ -373,9 +373,8 @@ const MetadataEditor = createClass({
|
||||
validators={[(v)=>!this.props.metadata.authors?.includes(v)]}
|
||||
placeholder='invite author' unique={true}
|
||||
values={this.props.metadata.invitedAuthors}
|
||||
values={['cat', 'dog', 'fish']}
|
||||
notes={['Invited author usernames are case sensitive.', 'After adding an invited author, send them the edit link. There, they can choose to accept or decline the invitation.']}
|
||||
// onChange={(e)=>this.handleFieldChange('invitedAuthors', e)}
|
||||
onChange={(e)=>this.handleFieldChange('invitedAuthors', e)}
|
||||
/>
|
||||
|
||||
<hr/>
|
||||
|
||||
@@ -1,16 +1,28 @@
|
||||
const React = require('react');
|
||||
const { useState } = React;
|
||||
const { useState, useEffect } = React;
|
||||
|
||||
const TagInput = ({ unique = true, values = [], ...props }) => {
|
||||
const [temporaryValue, setTemporaryValue] = useState('');
|
||||
const [valueContext, setValueContext] = useState(values.map((value) => ({ value, editing: false })));
|
||||
|
||||
useEffect(()=>{
|
||||
handleChange(valueContext.map((context)=>context.value))
|
||||
}, [valueContext])
|
||||
|
||||
const handleChange = (value)=>{
|
||||
props.onChange({
|
||||
target : { value }
|
||||
})
|
||||
};
|
||||
|
||||
const handleInputKeyDown = (evt, value) => {
|
||||
if (evt.key === 'Enter') {
|
||||
submitTag(evt.target.value, value);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
const submitTag = (newValue, originalValue) => {
|
||||
setValueContext((prevContext) => {
|
||||
return prevContext.map((context) => {
|
||||
|
||||
Reference in New Issue
Block a user