import { PictrsImage } from "../common/pictrs-image";
interface NavbarProps {
- siteRes: GetSiteResponse;
+ siteRes?: GetSiteResponse;
}
interface NavbarState {
unreadInboxCount: number;
unreadReportCount: number;
unreadApplicationCount: number;
- searchParam: string;
showDropdown: boolean;
onSiteBanner?(url: string): any;
}
unreadReportCount: 0,
unreadApplicationCount: 0,
expanded: false,
- searchParam: "",
showDropdown: false,
};
subscription: any;
this.unreadApplicationCountSub.unsubscribe();
}
- updateUrl() {
- const searchParam = this.state.searchParam;
- this.setState({ searchParam: "" });
- this.setState({ showDropdown: false, expanded: false });
- if (searchParam === "") {
- this.context.router.history.push(`/search/`);
- } else {
- const searchParamEncoded = encodeURIComponent(searchParam);
- this.context.router.history.push(
- `/search/q/${searchParamEncoded}/type/All/sort/TopAll/listing_type/All/community_id/0/creator_id/0/page/1`
- );
- }
- }
-
render() {
return this.navbar();
}
// TODO class active corresponding to current page
navbar() {
- let siteView = this.props.siteRes.site_view;
+ let siteView = this.props.siteRes?.site_view;
let person = UserService.Instance.myUserInfo?.local_user_view.person;
return (
<nav className="navbar navbar-expand-md navbar-light shadow-sm p-0 px-3">
<NavLink
to="/"
onMouseUp={linkEvent(this, this.handleHideExpandNavbar)}
- title={siteView.site.description ?? siteView.site.name}
+ title={siteView?.site.description ?? siteView?.site.name ?? "Lemmy"}
className="d-flex align-items-center navbar-brand mr-md-3"
>
- {siteView.site.icon && showAvatars() && (
+ {siteView?.site.icon && showAvatars() && (
<PictrsImage src={siteView.site.icon} icon />
)}
- {siteView.site.name}
+ {siteView?.site.name ?? "Lemmy"}
</NavLink>
{UserService.Instance.myUserInfo && (
<>
className="p-1 navbar-toggler nav-link border-0"
onMouseUp={linkEvent(this, this.handleHideExpandNavbar)}
title={i18n.t("unread_messages", {
- count: this.state.unreadInboxCount,
+ count: Number(this.state.unreadInboxCount),
formattedCount: numToSI(this.state.unreadInboxCount),
})}
>
className="p-1 navbar-toggler nav-link border-0"
onMouseUp={linkEvent(this, this.handleHideExpandNavbar)}
title={i18n.t("unread_reports", {
- count: this.state.unreadReportCount,
+ count: Number(this.state.unreadReportCount),
formattedCount: numToSI(this.state.unreadReportCount),
})}
>
className="p-1 navbar-toggler nav-link border-0"
onMouseUp={linkEvent(this, this.handleHideExpandNavbar)}
title={i18n.t("unread_registration_applications", {
- count: this.state.unreadApplicationCount,
+ count: Number(this.state.unreadApplicationCount),
formattedCount: numToSI(
this.state.unreadApplicationCount
),
{i18n.t("create_post")}
</NavLink>
</li>
- {canCreateCommunity(this.props.siteRes) && (
+ {this.props.siteRes && canCreateCommunity(this.props.siteRes) && (
<li className="nav-item">
<NavLink
to="/create_community"
to="/inbox"
onMouseUp={linkEvent(this, this.handleHideExpandNavbar)}
title={i18n.t("unread_messages", {
- count: this.state.unreadInboxCount,
+ count: Number(this.state.unreadInboxCount),
formattedCount: numToSI(this.state.unreadInboxCount),
})}
>
to="/reports"
onMouseUp={linkEvent(this, this.handleHideExpandNavbar)}
title={i18n.t("unread_reports", {
- count: this.state.unreadReportCount,
+ count: Number(this.state.unreadReportCount),
formattedCount: numToSI(this.state.unreadReportCount),
})}
>
className="nav-link"
onMouseUp={linkEvent(this, this.handleHideExpandNavbar)}
title={i18n.t("unread_registration_applications", {
- count: this.state.unreadApplicationCount,
+ count: Number(this.state.unreadApplicationCount),
formattedCount: numToSI(
this.state.unreadApplicationCount
),
i.setState({ expanded: false, showDropdown: false });
}
- handleSearchParam(i: Navbar, event: any) {
- i.setState({ searchParam: event.target.value });
- }
-
handleLogoutClick(i: Navbar) {
i.setState({ showDropdown: false, expanded: false });
UserService.Instance.logout();