import React, { Component } from "react"; import { useNavigate } from "react-router-dom"; import { useAppDispatch } from "../../app/hooks"; import DataUtils, { SearchResults } from "../data/DataUtils"; import { setTitle } from "../page-title/pageTitleSlice"; import { setResults } from "../search-results/searchResultsSlice"; import styles from "./SearchForm.module.css"; interface FCProps {} interface Props extends FCProps { navigate: any; dispatch: any; } interface State { pdStart: string; pdEnd: string; widthMin: string; widthMax: string; depthMin: string; depthMax: string; cellType: string; area: string; geneType: string; keyword: string; } class SearchForm extends Component { constructor(props: Props) { super(props); this.state = { pdStart: "44", pdEnd: "100", widthMin: "317", widthMax: "512", depthMin: "90", depthMax: "230", cellType: "any", area: "all", geneType: "all", keyword: "", }; this.handleInputChange = this.handleInputChange.bind(this); this.handleSelectChange = this.handleSelectChange.bind(this); this.handleSubmit = this.handleSubmit.bind(this); } componentDidMount() { this.props.dispatch(setTitle("Database Search")); } doSearch(): SearchResults { const toNumber = (v: string): number => parseInt(v.trim(), 10); const params = { pdStart: toNumber(this.state.pdStart), pdEnd: toNumber(this.state.pdEnd), widthMin: toNumber(this.state.widthMin), widthMax: toNumber(this.state.widthMax), depthMin: toNumber(this.state.depthMin), depthMax: toNumber(this.state.depthMax), cellType: this.state.cellType.trim(), area: this.state.area.trim(), geneType: this.state.geneType.trim(), keyword: this.state.keyword.trim(), }; return DataUtils.search(params); } handleInputChange: React.ChangeEventHandler = (event: React.ChangeEvent) => { const target = event.target; const value = target.value; const name = target.name; switch (name) { case "pdStart": this.setState({ pdStart: value }); break; case "pdEnd": this.setState({ pdStart: value }); break; case "widthMin": this.setState({ widthMin: value }); break; case "widthMax": this.setState({ widthMax: value }); break; case "depthMin": this.setState({ depthMin: value }); break; case "depthMax": this.setState({ depthMax: value }); break; case "cellType": this.setState({ cellType: value }); break; case "keyword": this.setState({ keyword: value }); break; } }; handleSelectChange: React.ChangeEventHandler = (event: React.ChangeEvent) => { const target = event.target; const value = target.value; const name = target.name; switch (name) { case "area": this.setState({ area: value }); break; case "geneType": this.setState({ geneType: value }); break; } }; handleSubmit: React.FormEventHandler = (event: React.FormEvent) => { event.preventDefault(); const results = this.doSearch(); this.props.dispatch(setResults(results)); this.props.navigate("/search/results"); }; render() { return (
-
-
-
); } } const SearchFormFC: React.FC = (props: FCProps) => { const navigate = useNavigate(); const dispatch = useAppDispatch(); return ; }; export default SearchFormFC;