}
function handleCollapseClick(i: Navbar) {
- if (i.collapseButtonRef.current?.ariaExpanded === "true") {
- i.collapseButtonRef.current?.click();
- }
+ i.collapseButtonRef.current?.click();
}
-function handleLogOut() {
+function handleLogOut(i: Navbar) {
UserService.Instance.logout();
+ handleCollapseClick(i);
}
export class Navbar extends Component<NavbarProps, NavbarState> {
};
subscription: any;
collapseButtonRef = createRef<HTMLButtonElement>();
+ mobileMenuRef = createRef<HTMLDivElement>();
constructor(props: any, context: any) {
super(props, context);
this.parseMessage = this.parseMessage.bind(this);
this.subscription = wsSubscribe(this.parseMessage);
+ this.handleOutsideMenuClick = this.handleOutsideMenuClick.bind(this);
}
componentDidMount() {
UserService.Instance.unreadApplicationCountSub.subscribe(res => {
this.setState({ unreadApplicationCount: res });
});
+
+ document.addEventListener("click", this.handleOutsideMenuClick);
}
}
this.unreadInboxCountSub.unsubscribe();
this.unreadReportCountSub.unsubscribe();
this.unreadApplicationCountSub.unsubscribe();
+ document.removeEventListener("click", this.handleOutsideMenuClick);
}
// TODO class active corresponding to current page
>
<Icon icon="menu" />
</button>
- <div className="collapse navbar-collapse my-2" id="navbarDropdown">
+ <div
+ className="collapse navbar-collapse my-2"
+ id="navbarDropdown"
+ ref={this.mobileMenuRef}
+ >
<ul className="mr-auto navbar-nav">
<li className="nav-item">
<NavLink
<li>
<button
className="dropdown-item btn btn-link px-2"
- onClick={handleLogOut}
+ onClick={linkEvent(this, handleLogOut)}
>
<Icon icon="log-out" classes="mr-1" />
{i18n.t("logout")}
);
}
+ handleOutsideMenuClick(event: MouseEvent) {
+ if (!this.mobileMenuRef.current?.contains(event.target as Node | null)) {
+ handleCollapseClick(this);
+ }
+ }
+
get moderatesSomething(): boolean {
const mods = UserService.Instance.myUserInfo?.moderates;
const moderatesS = (mods && mods.length > 0) || false;