mirror of
https://github.com/vector-im/element-web.git
synced 2024-11-16 05:04:57 +08:00
show profile in topleftmenu button for now (will be current community)
This commit is contained in:
parent
eba91d3edc
commit
863d89f6fd
@ -19,6 +19,7 @@
|
|||||||
@import "./structures/_SearchBox.scss";
|
@import "./structures/_SearchBox.scss";
|
||||||
@import "./structures/_TagPanel.scss";
|
@import "./structures/_TagPanel.scss";
|
||||||
@import "./structures/_TopLeftMenu.scss";
|
@import "./structures/_TopLeftMenu.scss";
|
||||||
|
@import "./structures/_TopLeftMenuButton.scss";
|
||||||
@import "./structures/_UploadBar.scss";
|
@import "./structures/_UploadBar.scss";
|
||||||
@import "./structures/_UserSettings.scss";
|
@import "./structures/_UserSettings.scss";
|
||||||
@import "./structures/_ViewSource.scss";
|
@import "./structures/_ViewSource.scss";
|
||||||
|
@ -20,22 +20,25 @@ limitations under the License.
|
|||||||
color: $topleftmenu-color;
|
color: $topleftmenu-color;
|
||||||
background-color: $primary-bg-color;
|
background-color: $primary-bg-color;
|
||||||
display: flex;
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
min-width: 0;
|
||||||
|
padding: 0 7px;
|
||||||
|
overflow: hidden;
|
||||||
}
|
}
|
||||||
|
|
||||||
.mx_TopLeftMenuButton_avatar {
|
.mx_TopLeftMenuButton .mx_BaseAvatar {
|
||||||
position: relative; // to get avatar in the right place
|
margin: 0 7px;
|
||||||
margin-left: 15px;
|
|
||||||
margin-right: 15px;
|
|
||||||
margin-top: 14px;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.mx_TopLeftMenuButton_name {
|
.mx_TopLeftMenuButton_name {
|
||||||
margin-top: 15px;
|
margin: 0 7px;
|
||||||
margin-right: 9px;
|
|
||||||
font-size: 18px;
|
font-size: 18px;
|
||||||
|
white-space: nowrap;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
overflow: hidden;
|
||||||
font-weight: 600;
|
font-weight: 600;
|
||||||
}
|
}
|
||||||
|
|
||||||
.mx_TopLeftMenuButton_chevron {
|
.mx_TopLeftMenuButton_chevron {
|
||||||
margin-top: 24px;
|
margin: 0 7px;
|
||||||
}
|
}
|
||||||
|
@ -16,11 +16,16 @@ limitations under the License.
|
|||||||
|
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import sdk from '../../index';
|
|
||||||
import * as ContextualMenu from './ContextualMenu';
|
import * as ContextualMenu from './ContextualMenu';
|
||||||
import {TopLeftMenu} from './TopLeftMenu';
|
import {TopLeftMenu} from './TopLeftMenu';
|
||||||
|
import AccessibleButton from '../views/elements/AccessibleButton';
|
||||||
|
import BaseAvatar from '../views/avatars/BaseAvatar';
|
||||||
|
import MatrixClientPeg from '../../MatrixClientPeg';
|
||||||
|
import Avatar from '../../Avatar';
|
||||||
|
|
||||||
export class TopLeftMenuButton extends React.Component {
|
const AVATAR_SIZE = 28;
|
||||||
|
|
||||||
|
export default class TopLeftMenuButton extends React.Component {
|
||||||
|
|
||||||
static propTypes = {
|
static propTypes = {
|
||||||
collapsed: PropTypes.bool.isRequired,
|
collapsed: PropTypes.bool.isRequired,
|
||||||
@ -32,27 +37,56 @@ export class TopLeftMenuButton extends React.Component {
|
|||||||
super();
|
super();
|
||||||
this.state = {
|
this.state = {
|
||||||
menuDisplayed: false,
|
menuDisplayed: false,
|
||||||
|
profileInfo: null,
|
||||||
|
};
|
||||||
|
|
||||||
|
this.onToggleMenu = this.onToggleMenu.bind(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
async _getProfileInfo() {
|
||||||
|
const cli = MatrixClientPeg.get();
|
||||||
|
const userId = cli.getUserId();
|
||||||
|
const profileInfo = await cli.getProfileInfo(userId);
|
||||||
|
const avatarUrl = Avatar.avatarUrlForUser(
|
||||||
|
{avatarUrl: profileInfo.avatar_url},
|
||||||
|
AVATAR_SIZE, AVATAR_SIZE, "crop");
|
||||||
|
|
||||||
|
return {
|
||||||
|
userId,
|
||||||
|
name: profileInfo.displayname,
|
||||||
|
avatarUrl,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
async componentDidMount() {
|
||||||
const BaseAvatar = sdk.getComponent('avatars.BaseAvatar');
|
try {
|
||||||
const avatarHeight = 28;
|
const profileInfo = await this._getProfileInfo();
|
||||||
const name = "My stuff";
|
this.setState({profileInfo});
|
||||||
|
} catch(ex) {
|
||||||
|
console.log("could not fetch profile");
|
||||||
|
console.error(ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
render() {
|
||||||
|
const fallbackUserId = MatrixClientPeg.get().getUserId();
|
||||||
|
const profileInfo = this.state.profileInfo;
|
||||||
|
const name = profileInfo ? profileInfo.name : fallbackUserId;
|
||||||
return (
|
return (
|
||||||
<div className="mx_TopLeftMenuButton">
|
<AccessibleButton className="mx_TopLeftMenuButton" onClick={this.onToggleMenu}>
|
||||||
<BaseAvatar
|
<BaseAvatar
|
||||||
className="mx_TopLeftMenuButton_avatar"
|
idName={fallbackUserId}
|
||||||
name={name}
|
name={name}
|
||||||
width={avatarHeight}
|
url={profileInfo && profileInfo.avatarUrl}
|
||||||
height={avatarHeight}
|
width={AVATAR_SIZE}
|
||||||
|
height={AVATAR_SIZE}
|
||||||
|
resizeMethod="crop"
|
||||||
/>
|
/>
|
||||||
<div className="mx_TopLeftMenuButton_name" onClick={this.onToggleMenu}>
|
<div className="mx_TopLeftMenuButton_name">
|
||||||
{ name }
|
{ name }
|
||||||
</div>
|
</div>
|
||||||
<img className="mx_TopLeftMenuButton_chevron" src="img/topleft-chevron.svg" width="11" height="6" />
|
<img className="mx_TopLeftMenuButton_chevron" src="img/topleft-chevron.svg" width="11" height="6" />
|
||||||
</div>
|
</AccessibleButton>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -60,7 +94,7 @@ export class TopLeftMenuButton extends React.Component {
|
|||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
|
|
||||||
const elementRect = e.target.parentElement.getBoundingClientRect();
|
const elementRect = e.currentTarget.getBoundingClientRect();
|
||||||
const x = elementRect.left;
|
const x = elementRect.left;
|
||||||
const y = elementRect.top + elementRect.height;
|
const y = elementRect.top + elementRect.height;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user