2018-11-27 21:29:56 +00:00
|
|
|
import { Component, linkEvent } from 'inferno';
|
|
|
|
import { SearchParams } from '../interfaces';
|
2018-11-29 04:57:35 +00:00
|
|
|
import { repoUrl } from '../utils';
|
2018-11-27 21:29:56 +00:00
|
|
|
|
|
|
|
|
|
|
|
interface State {
|
|
|
|
searchParams: SearchParams;
|
|
|
|
}
|
|
|
|
|
|
|
|
export class Navbar extends Component<any, State> {
|
|
|
|
|
|
|
|
state: State = {
|
|
|
|
searchParams: {
|
|
|
|
page: 1,
|
|
|
|
q: ""
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
constructor(props, context) {
|
|
|
|
super(props, context);
|
2018-11-29 23:59:03 +00:00
|
|
|
this.fillSearchField();
|
2018-11-27 21:29:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<div>{this.navbar()}</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
navbar() {
|
|
|
|
return (
|
2018-11-30 18:41:16 +00:00
|
|
|
<nav class="navbar navbar-dark navbar-purple py-1">
|
|
|
|
<a class="navbar-brand mx-1" href="#">
|
2018-11-29 04:57:35 +00:00
|
|
|
<i class="fas fa-fw fa-database mr-1"></i>
|
|
|
|
Torrents.csv
|
|
|
|
</a>
|
2018-11-30 18:41:16 +00:00
|
|
|
{this.searchForm()}
|
|
|
|
<ul class="navbar-nav mx-1">
|
2018-11-29 04:57:35 +00:00
|
|
|
<li class="nav-item">
|
|
|
|
<a class="nav-link" href={repoUrl}><i class="fab fa-fw fa-github"></i></a>
|
|
|
|
</li>
|
|
|
|
</ul>
|
2018-11-27 21:29:56 +00:00
|
|
|
</nav>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
searchForm() {
|
|
|
|
return (
|
2018-11-30 18:41:16 +00:00
|
|
|
<form class="form-inline col-7 col-sm-8 col-xl-10 mx-1 my-0" onSubmit={linkEvent(this, this.search)}>
|
|
|
|
<div class="input-group w-100">
|
|
|
|
<input class="form-control border-0 rounded-0 no-outline" type="search" placeholder="Search..." aria-label="Search..." required
|
|
|
|
value={this.state.searchParams.q}
|
|
|
|
onInput={linkEvent(this, this.searchChange)}></input>
|
|
|
|
<button class="btn btn-secondary border-0 rounded-0 no-outline" type="submit">
|
2018-11-27 21:29:56 +00:00
|
|
|
<i className="fas fa-fw fa-search"></i>
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
</form>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
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 });
|
|
|
|
}
|
2018-11-29 23:59:03 +00:00
|
|
|
|
|
|
|
fillSearchField() {
|
|
|
|
let splitPath: Array<string> = this.context.router.route.location.pathname.split("/");
|
|
|
|
if (splitPath.length == 4 && splitPath[1] == 'search')
|
|
|
|
this.state.searchParams = {
|
|
|
|
page: Number(splitPath[3]),
|
|
|
|
q: splitPath[2]
|
|
|
|
};
|
|
|
|
}
|
2018-11-29 04:36:12 +00:00
|
|
|
}
|