ReactDOM.render(
<BrowserRouter>
<Switch>
<Route exact path="/" component={App}/>
<Route path="/search" component={SearchTable}/>
</Switch>
</BrowserRouter>
, document.getElementById('root'));
class InputResult extends React.Component {
constructor(props) {
super(props);
this.state = {
error: null,
isLoaded: false,
items: [],
searchValue: '',
};
}
componentDidMount(){
fetch("http://localhost:8080/api/users?offset=0&count=15")
.then(res => res.json())
.then(
(result) => {
this.setState({
isLoaded: true,
items: result.items
}
);
},
(error) => {
this.setState({
isLoaded: true,
error
});
}
)
.catch(error => console.log('parsing failed', error));
}
onSearchChange = (event, searchValue) => {
this.setState({ searchValue });
};
onSearchClick = () => {
const { searchValue } = this.state;
fetch("http://localhost:8080/api/users/?name="+searchValue)
.then(res => res.json())
.then(
(result) => {
this.setState({
isLoaded: true,
items: result.items
}
);
},
(error) => {
this.setState({
isLoaded: true,
error
});
}
)
.catch(error => console.log('parsing failed', error));
}
onSearchPress = (e) => {
if (e.key === 'Enter'){
this.onSearchClick();
}
}
render() {
const { items, error , isLoaded, searchValue} = this.state;
console.log(searchValue);
return (
<div>
<div className={styles.parentResult}>
<Center>
<div className={styles.input}>
<Input leftIcon={<Icon name="search" />}
value={this.state.searchValue}
width="700px"
placeholder="Введите Фамилию и Имя"
onChange={this.onSearchChange}
onKeyPress={this.onSearchPress}
/> {' '}
<Button use="primary" onClick={this.onSearchClick}>Найти</Button>
</div>
</Center>
</div>
<SearchHub error={error} isLoaded={isLoaded} items={items} searchValue={searchValue}/>
</div>
)
}
}
export default InputResult;
onSearchChange = (event, searchInputValue) => {
this.setState({ searchInputValue });
};
onSearchClick = () => {
this.setState(prevState => ({
searchValue: prevState.searchInputValue,
}), this.onSearchClick);
};
onSearchClick = () => {
const { searchInputValue } = this.state;
fetch("http://localhost:8080/api/users/?name="+searchInputValue)
.then(res => res.json())
.then(
(result) => {
this.setState({
isLoaded: true,
items: result.items
}
);
},
(error) => {
this.setState({
isLoaded: true,
error
});
}
)
.catch(error => console.log('parsing failed', error));
}
render() {
const { items, error , isLoaded, searchValue} = this.state;
console.log(searchValue);
return (
<div>
<div className={styles.input}>
<Input leftIcon={<Icon name="search" />}
value={this.state.searchInputValue}
width="700px"
placeholder="Введите Фамилию и Имя"
onChange={this.onSearchChange}
/> {' '}
<Button use="primary" onClick={this.onSearchClick}>Найти</Button>
</div>
</div>
<SearchHub error={error} isLoaded={isLoaded} items={items} searchValue={searchValue}/>
</div>
)
}
}
onSearchClick = () => {
const { searchValue } = this.state;
fetch("http://localhost:8080/api/users/?name="+searchValue)
.then(res => res.json())
.then(
(result) => {
this.setState({
isLoaded: true,
items: result.items
}
);
},
(error) => {
this.setState({
isLoaded: true,
error
});
}
)
.catch(error => console.log('parsing failed', error));
constructor(props) {
super(props);
this.state = {
error: null,
isLoaded: false,
items: [],
searchValue: ''
};
}
onSearchChange = (event, searchValue) => {
this.setState({ searchValue })
}
render() {
const { items, error , isLoaded, searchValue } = this.state;
return (
<div>
<div className={styles.input}>
<Input leftIcon={<Icon name="search" />}
value={this.state.searchValue}
width="700px"
placeholder="Введите Фамилию и Имя"
onChange={this.onSearchChange}
/> {' '}
<Button use="primary" onClick={this.onSearchClick}>Найти</Button>
</div>
</div>
<div>
<SearchHub error={error} isLoaded={isLoaded} items={items} searchValue={searchValue}/>
</div>
)
}
}