import { Component, linkEvent } from 'inferno';
-import { Link } from 'inferno-router';
+import { Link, withRouter } from 'inferno-router';
import { Subscription } from 'rxjs';
import { retryWhen, delay, take } from 'rxjs/operators';
import { WebSocketService, UserService } from '../services';
GetPrivateMessagesForm,
PrivateMessagesResponse,
SortType,
+ SearchType,
GetSiteResponse,
Comment,
CommentResponse,
UserView,
PrivateMessageResponse,
WebSocketJsonResponse,
+ SearchForm,
} from '../interfaces';
import {
wsJsonToRes,
unreadCount: number;
siteName: string;
admins: Array<UserView>;
+ searchParam: string;
}
-export class Navbar extends Component<any, NavbarState> {
+class Navbar extends Component<any, NavbarState> {
private wsSub: Subscription;
private userSub: Subscription;
emptyState: NavbarState = {
expanded: false,
siteName: undefined,
admins: [],
+ searchParam: '',
};
constructor(props: any, context: any) {
}
WebSocketService.Instance.getSite();
+
+ this.handleSearchParam = this.handleSearchParam.bind(this);
+ }
+
+ handleSearchParam(i: Navbar, event: any) {
+ i.state.searchParam = event.target.value;
+ i.setState(i.state);
+ }
+
+ updateUrl() {
+ this.props.history.push(
+ `/search/q/${this.state.searchParam}/type/all/sort/topall/page/1`
+ );
+ this.setState({ searchParam: '' });
+ }
+
+ handleSearchSubmit(i: Navbar, event: any) {
+ event.preventDefault();
+ i.updateUrl();
}
render() {
{i18n.t('communities')}
</Link>
</li>
- <li class="nav-item">
- <Link class="nav-link" to="/search" title={i18n.t('search')}>
- {i18n.t('search')}
- </Link>
- </li>
<li class="nav-item">
<Link
class="nav-link"
</Link>
</li>
</ul>
- <ul class="navbar-nav ml-auto">
+ {!this.props.history.location.pathname.match(/^\/search/) && (
+ <div class="nav-item search-bar">
+ <form onSubmit={linkEvent(this, this.handleSearchSubmit)}>
+ <input
+ class="form-control mr-sm-2"
+ onInput={linkEvent(this, this.handleSearchParam)}
+ value={this.state.searchParam}
+ type="search"
+ placeholder={i18n.t('search')}
+ ></input>
+ </form>
+ </div>
+ )}
+ <ul class="navbar-nav ml-2">
{this.canAdmin && (
<li className="nav-item mt-1">
<Link
}
}
}
+
+export default withRouter(Navbar);
import { BrowserRouter, Route, Switch } from 'inferno-router';
import { Provider } from 'inferno-i18next';
import { Main } from './components/main';
-import { Navbar } from './components/navbar';
+import Navbar from './components/navbar';
import { Footer } from './components/footer';
import { Login } from './components/login';
import { CreatePost } from './components/create-post';