From 02cfd1180cc07312134e223dd12e5e65c7dfea9c Mon Sep 17 00:00:00 2001 From: Ernst Widerberg Date: Wed, 8 Jun 2022 10:57:01 +0200 Subject: Make functional: SearchForm --- src/components/SearchForm.js | 150 +++++++++++++++++++------------------------ 1 file changed, 66 insertions(+), 84 deletions(-) diff --git a/src/components/SearchForm.js b/src/components/SearchForm.js index 6f626c2..1e56fc7 100644 --- a/src/components/SearchForm.js +++ b/src/components/SearchForm.js @@ -1,102 +1,84 @@ -import React from "react"; +import React, { useState } from "react"; import PropTypes from "prop-types"; import Button from "@mui/material/Button"; import ClearIcon from "@mui/icons-material/Clear"; -import FormControl from "@mui/material/FormControl"; -import IconButton from "@mui/material/IconButton"; import InputAdornment from "@mui/material/InputAdornment"; import MenuItem from "@mui/material/MenuItem"; import Select from "@mui/material/Select"; import TextField from "@mui/material/TextField"; -class SearchForm extends React.Component { - static propTypes = { - filter: PropTypes.func.isRequired - }; +function SearchForm(props) { + // NOTE: This state is for UI only, ListView's "filter" is used for requests. + let [searchField, setSearchField] = useState("port"); + let [searchValue, setSearchValue] = useState(""); - constructor(props) { - super(props); - // NOTE: This state is for UI only, List state's "filter" is used for requests. - this.state = { - searchField: "port", - searchValue: "" - }; - - this.clearSearch = this.clearSearch.bind(this); - this.submitSearch = this.submitSearch.bind(this); - } - - clearSearch(_) { - this.setState({ searchValue: "" }); - this.props.filter(null, null); + function clearSearch(_) { + setSearchValue(""); + props.filter(null, null); } - submitSearch() { + function submitSearch() { // e.preventDefault(); - if (this.state.searchValue === "") this.clearSearch(); - else this.props.filter(this.state.searchField, this.state.searchValue); + if (searchValue === "") clearSearch(); + else props.filter(searchField, searchValue); } - render() { - return ( - - ); - } + return ( + + ); } +SearchForm.propTypes = { + filter: PropTypes.func.isRequired +}; + export default SearchForm; -- cgit v1.1