import { Component, linkEvent } from 'inferno'; import { SearchParams } from '../interfaces'; import { repoUrl } from '../utils'; interface State { searchParams: SearchParams; } export class Navbar extends Component { state: State = { searchParams: { page: 1, q: "", type_: "torrent" } } constructor(props, context) { super(props, context); this.fillSearchField(); } render() { return (
{this.navbar()}
) } navbar() { return ( ); } searchForm() { return (
); } search(i: Navbar, event) { event.preventDefault(); i.context.router.history.push(`/search/${i.state.searchParams.type_}/${i.state.searchParams.q}/${i.state.searchParams.page}`); } searchChange(i: Navbar, event) { let searchParams: SearchParams = { q: event.target.value, page: 1, type_: i.state.searchParams.type_ } i.setState({ searchParams: searchParams }); } searchTypeChange(i: Navbar, event) { let searchParams: SearchParams = { q: i.state.searchParams.q, page: 1, type_: event.target.value } i.setState({ searchParams: searchParams }); } fillSearchField() { let splitPath: Array = this.context.router.route.location.pathname.split("/"); if (splitPath.length == 5 && splitPath[1] == 'search') this.state.searchParams = { page: Number(splitPath[4]), q: splitPath[3], type_: splitPath[2] }; } }