mirror of
https://github.com/element-hq/element-web
synced 2024-11-28 12:28:50 +03:00
Get Group profile from TagTile instead of TagPanel
So that instead of getting all group profiles everytime the tags change order, get them when the TagTile mounts for a group tag.
This commit is contained in:
parent
9975941f3c
commit
6f896098e3
3 changed files with 33 additions and 32 deletions
|
@ -18,7 +18,6 @@ import React from 'react';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import { MatrixClient } from 'matrix-js-sdk';
|
import { MatrixClient } from 'matrix-js-sdk';
|
||||||
import FilterStore from '../../stores/FilterStore';
|
import FilterStore from '../../stores/FilterStore';
|
||||||
import FlairStore from '../../stores/FlairStore';
|
|
||||||
import TagOrderStore from '../../stores/TagOrderStore';
|
import TagOrderStore from '../../stores/TagOrderStore';
|
||||||
|
|
||||||
import GroupActions from '../../actions/GroupActions';
|
import GroupActions from '../../actions/GroupActions';
|
||||||
|
@ -36,17 +35,7 @@ const TagPanel = React.createClass({
|
||||||
|
|
||||||
getInitialState() {
|
getInitialState() {
|
||||||
return {
|
return {
|
||||||
// A list of group profiles for tags that are group IDs. The intention in future
|
orderedTags: [],
|
||||||
// is to allow arbitrary tags to be selected in the TagPanel, not just groups.
|
|
||||||
// For now, it suffices to maintain a list of ordered group profiles.
|
|
||||||
orderedGroupTagProfiles: [
|
|
||||||
// {
|
|
||||||
// groupId: '+awesome:foo.bar',{
|
|
||||||
// name: 'My Awesome Community',
|
|
||||||
// avatarUrl: 'mxc://...',
|
|
||||||
// shortDescription: 'Some description...',
|
|
||||||
// },
|
|
||||||
],
|
|
||||||
selectedTags: [],
|
selectedTags: [],
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
@ -67,15 +56,8 @@ const TagPanel = React.createClass({
|
||||||
if (this.unmounted) {
|
if (this.unmounted) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
this.setState({
|
||||||
const orderedTags = TagOrderStore.getOrderedTags() || [];
|
orderedTags: TagOrderStore.getOrderedTags() || [],
|
||||||
const orderedGroupTags = orderedTags.filter((t) => t[0] === '+');
|
|
||||||
// XXX: One profile lookup failing will bring the whole lot down
|
|
||||||
Promise.all(orderedGroupTags.map(
|
|
||||||
(groupId) => FlairStore.getGroupProfileCached(this.context.matrixClient, groupId),
|
|
||||||
)).then((orderedGroupTagProfiles) => {
|
|
||||||
if (this.unmounted) return;
|
|
||||||
this.setState({orderedGroupTagProfiles});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
// This could be done by anything with a matrix client
|
// This could be done by anything with a matrix client
|
||||||
|
@ -113,11 +95,11 @@ const TagPanel = React.createClass({
|
||||||
const TintableSvg = sdk.getComponent('elements.TintableSvg');
|
const TintableSvg = sdk.getComponent('elements.TintableSvg');
|
||||||
const DNDTagTile = sdk.getComponent('elements.DNDTagTile');
|
const DNDTagTile = sdk.getComponent('elements.DNDTagTile');
|
||||||
|
|
||||||
const tags = this.state.orderedGroupTagProfiles.map((groupProfile, index) => {
|
const tags = this.state.orderedTags.map((tag, index) => {
|
||||||
return <DNDTagTile
|
return <DNDTagTile
|
||||||
key={groupProfile.groupId + '_' + index}
|
key={tag + '_' + index}
|
||||||
groupProfile={groupProfile}
|
tag={tag}
|
||||||
selected={this.state.selectedTags.includes(groupProfile.groupId)}
|
selected={this.state.selectedTags.includes(tag)}
|
||||||
onEndDrag={this.onTagTileEndDrag}
|
onEndDrag={this.onTagTileEndDrag}
|
||||||
/>;
|
/>;
|
||||||
});
|
});
|
||||||
|
|
|
@ -29,7 +29,7 @@ const tagTileSource = {
|
||||||
beginDrag: function(props) {
|
beginDrag: function(props) {
|
||||||
// Return the data describing the dragged item
|
// Return the data describing the dragged item
|
||||||
return {
|
return {
|
||||||
tag: props.groupProfile.groupId,
|
tag: props.tag,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -55,7 +55,7 @@ const tagTileTarget = {
|
||||||
dis.dispatch({
|
dis.dispatch({
|
||||||
action: 'order_tag',
|
action: 'order_tag',
|
||||||
tag: monitor.getItem().tag,
|
tag: monitor.getItem().tag,
|
||||||
targetTag: props.groupProfile.groupId,
|
targetTag: props.tag,
|
||||||
// Note: we indicate that the tag should be after the target when
|
// Note: we indicate that the tag should be after the target when
|
||||||
// it's being dragged over the top half of the target.
|
// it's being dragged over the top half of the target.
|
||||||
after: draggedY < targetY,
|
after: draggedY < targetY,
|
||||||
|
@ -65,7 +65,7 @@ const tagTileTarget = {
|
||||||
drop(props) {
|
drop(props) {
|
||||||
// Return the data to be returned by getDropResult
|
// Return the data to be returned by getDropResult
|
||||||
return {
|
return {
|
||||||
tag: props.groupProfile.groupId,
|
tag: props.tag,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
|
@ -22,17 +22,36 @@ import sdk from '../../../index';
|
||||||
import dis from '../../../dispatcher';
|
import dis from '../../../dispatcher';
|
||||||
import { isOnlyCtrlOrCmdKeyEvent } from '../../../Keyboard';
|
import { isOnlyCtrlOrCmdKeyEvent } from '../../../Keyboard';
|
||||||
|
|
||||||
|
import FlairStore from '../../../stores/FlairStore';
|
||||||
|
|
||||||
export default React.createClass({
|
export default React.createClass({
|
||||||
displayName: 'TagTile',
|
displayName: 'TagTile',
|
||||||
|
|
||||||
propTypes: {
|
propTypes: {
|
||||||
groupProfile: PropTypes.object,
|
tag: PropTypes.string,
|
||||||
},
|
},
|
||||||
|
|
||||||
contextTypes: {
|
contextTypes: {
|
||||||
matrixClient: React.PropTypes.instanceOf(MatrixClient).isRequired,
|
matrixClient: React.PropTypes.instanceOf(MatrixClient).isRequired,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
componentWillMount() {
|
||||||
|
this.unmounted = false;
|
||||||
|
if (this.props.tag[0] === '+') {
|
||||||
|
FlairStore.getGroupProfileCached(
|
||||||
|
this.context.matrixClient,
|
||||||
|
this.props.tag,
|
||||||
|
).then((profile) => {
|
||||||
|
if (this.unmounted) return;
|
||||||
|
this.setState({profile});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
componentWillUnmount() {
|
||||||
|
this.unmounted = true;
|
||||||
|
},
|
||||||
|
|
||||||
getInitialState() {
|
getInitialState() {
|
||||||
return {
|
return {
|
||||||
hover: false,
|
hover: false,
|
||||||
|
@ -44,7 +63,7 @@ export default React.createClass({
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
dis.dispatch({
|
dis.dispatch({
|
||||||
action: 'select_tag',
|
action: 'select_tag',
|
||||||
tag: this.props.groupProfile.groupId,
|
tag: this.props.tag,
|
||||||
ctrlOrCmdKey: isOnlyCtrlOrCmdKeyEvent(e),
|
ctrlOrCmdKey: isOnlyCtrlOrCmdKeyEvent(e),
|
||||||
shiftKey: e.shiftKey,
|
shiftKey: e.shiftKey,
|
||||||
});
|
});
|
||||||
|
@ -62,8 +81,8 @@ export default React.createClass({
|
||||||
const BaseAvatar = sdk.getComponent('avatars.BaseAvatar');
|
const BaseAvatar = sdk.getComponent('avatars.BaseAvatar');
|
||||||
const AccessibleButton = sdk.getComponent('elements.AccessibleButton');
|
const AccessibleButton = sdk.getComponent('elements.AccessibleButton');
|
||||||
const RoomTooltip = sdk.getComponent('rooms.RoomTooltip');
|
const RoomTooltip = sdk.getComponent('rooms.RoomTooltip');
|
||||||
const profile = this.props.groupProfile || {};
|
const profile = this.state.profile || {};
|
||||||
const name = profile.name || profile.groupId;
|
const name = profile.name || this.props.tag;
|
||||||
const avatarHeight = 35;
|
const avatarHeight = 35;
|
||||||
|
|
||||||
const httpUrl = profile.avatarUrl ? this.context.matrixClient.mxcUrlToHttp(
|
const httpUrl = profile.avatarUrl ? this.context.matrixClient.mxcUrlToHttp(
|
||||||
|
|
Loading…
Reference in a new issue