From 6ac5a59d8f50eec76cc404ab909afc17ae5685bc Mon Sep 17 00:00:00 2001 From: Ilya Oleshko Date: Wed, 5 Feb 2020 15:41:52 +0300 Subject: [PATCH] Web: Common: Layout: Fixed ProfileMenu usage --- .../Layout/sub-components/header-nav.js | 5 + .../Layout/sub-components/profile-actions.js | 93 +++++++------------ 2 files changed, 38 insertions(+), 60 deletions(-) diff --git a/web/ASC.Web.Common/src/components/Layout/sub-components/header-nav.js b/web/ASC.Web.Common/src/components/Layout/sub-components/header-nav.js index c64c0b6ff1..5dedbf506f 100644 --- a/web/ASC.Web.Common/src/components/Layout/sub-components/header-nav.js +++ b/web/ASC.Web.Common/src/components/Layout/sub-components/header-nav.js @@ -17,6 +17,11 @@ const StyledNav = styled.nav` .profile-menu { right: 12px; + + @media ${tablet} { + right: 6px; + top: 66px; + } } & > div { diff --git a/web/ASC.Web.Common/src/components/Layout/sub-components/profile-actions.js b/web/ASC.Web.Common/src/components/Layout/sub-components/profile-actions.js index ba3ccc5524..eb8d514cee 100644 --- a/web/ASC.Web.Common/src/components/Layout/sub-components/profile-actions.js +++ b/web/ASC.Web.Common/src/components/Layout/sub-components/profile-actions.js @@ -1,8 +1,7 @@ import React from "react"; import PropTypes from "prop-types"; -import { Avatar, DropDown, DropDownItem, utils, Link } from "asc-web-components"; +import { Avatar, DropDownItem, Link } from "asc-web-components"; import ProfileMenu from "./../../ProfileMenu"; -const { handleAnyClick } = utils.event; class ProfileActions extends React.PureComponent { constructor(props) { @@ -14,42 +13,20 @@ class ProfileActions extends React.PureComponent { opened: props.opened, user: props.user }; - - this.handleClick = this.handleClick.bind(this); - this.toggle = this.toggle.bind(this); - this.getUserRole = this.getUserRole.bind(this); - this.onAvatarClick = this.onAvatarClick.bind(this); - this.onDropDownItemClick = this.onDropDownItemClick.bind(this); - - if (props.opened) handleAnyClick(true, this.handleClick); } - handleClick = e => { - this.state.opened && - !this.ref.current.contains(e.target) && - this.toggle(false); - }; - - toggle = opened => { + setOpened = opened => { this.setState({ opened: opened }); }; - componentWillUnmount() { - handleAnyClick(false, this.handleClick); - } - - componentDidUpdate(prevProps, prevState) { + componentDidUpdate(prevProps) { if (this.props.user !== prevProps.user) { this.setState({ user: this.props.user }) } if (this.props.opened !== prevProps.opened) { - this.toggle(this.props.opened); - } - - if (this.state.opened !== prevState.opened) { - handleAnyClick(this.state.opened, this.handleClick); + this.setOpened(this.props.opened); } } @@ -62,56 +39,52 @@ class ProfileActions extends React.PureComponent { return "user"; }; - onAvatarClick = () => { - this.toggle(!this.state.opened); - }; + onClose = (e) => { + if (this.ref.current.contains(e.target)) return; - onDropDownItemClick = action => { - action.onClick && action.onClick(); - this.toggle(!this.state.opened); - }; + this.setOpened(!this.state.opened); + } + + onClick = (action, e) => { + action.onClick && action.onClick(e); + + this.setOpened(!this.state.opened); + } render() { //console.log("Layout sub-component ProfileActions render"); + const { user, opened } = this.state; + const userRole = this.getUserRole(user); + return (
- - {this.props.userActions.map(action => ( { - if (e) { - this.onDropDownItemClick.bind(this, action); - e.preventDefault(); - } - } - } - > - + //onClick={this.onClick.bind(this, action)} + > + ))} - +
); }