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: "" } } constructor(props, context) { super(props, context); this.fillSearchField(); } render() { return (
{this.navbar()}
) } navbar() { return ( ); } // TODO // https://www.codeply.com/go/xBVaM3q5X4/bootstrap-4-navbar-search-full-width searchForm() { return (
); } search(i: Navbar, event) { event.preventDefault(); i.context.router.history.push(`/search/${i.state.searchParams.q}/${i.state.searchParams.page}`); } searchChange(i: Navbar, event) { let searchParams: SearchParams = { q: event.target.value, page: 1 } i.setState({ searchParams: searchParams }); } fillSearchField() { let splitPath: Array = this.context.router.route.location.pathname.split("/"); if (splitPath.length == 4 && splitPath[1] == 'search') this.state.searchParams = { page: Number(splitPath[3]), q: splitPath[2] }; } }