mirror of https://github.com/vector-im/riot-web
Merge pull request #1260 from matrix-org/luke/fix-rte-pills-not-updating
Use componentWillReceiveProps to update pill state when props changepull/21833/head
commit
a40a86669a
|
@ -63,16 +63,15 @@ const Pill = React.createClass({
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
componentWillMount() {
|
componentWillReceiveProps(nextProps) {
|
||||||
this._unmounted = false;
|
|
||||||
let regex = REGEX_MATRIXTO;
|
let regex = REGEX_MATRIXTO;
|
||||||
if (this.props.inMessage) {
|
if (nextProps.inMessage) {
|
||||||
regex = REGEX_LOCAL_MATRIXTO;
|
regex = REGEX_LOCAL_MATRIXTO;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Default to the empty array if no match for simplicity
|
// Default to the empty array if no match for simplicity
|
||||||
// resource and prefix will be undefined instead of throwing
|
// resource and prefix will be undefined instead of throwing
|
||||||
const matrixToMatch = regex.exec(this.props.url) || [];
|
const matrixToMatch = regex.exec(nextProps.url) || [];
|
||||||
|
|
||||||
const resourceId = matrixToMatch[1]; // The room/user ID
|
const resourceId = matrixToMatch[1]; // The room/user ID
|
||||||
const prefix = matrixToMatch[2]; // The first character of prefix
|
const prefix = matrixToMatch[2]; // The first character of prefix
|
||||||
|
@ -87,7 +86,7 @@ const Pill = React.createClass({
|
||||||
let room;
|
let room;
|
||||||
switch (pillType) {
|
switch (pillType) {
|
||||||
case Pill.TYPE_USER_MENTION: {
|
case Pill.TYPE_USER_MENTION: {
|
||||||
const localMember = this.props.room.getMember(resourceId);
|
const localMember = nextProps.room.getMember(resourceId);
|
||||||
member = localMember;
|
member = localMember;
|
||||||
if (!localMember) {
|
if (!localMember) {
|
||||||
member = new RoomMember(null, resourceId);
|
member = new RoomMember(null, resourceId);
|
||||||
|
@ -112,6 +111,11 @@ const Pill = React.createClass({
|
||||||
this.setState({resourceId, pillType, member, room});
|
this.setState({resourceId, pillType, member, room});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
componentWillMount() {
|
||||||
|
this._unmounted = false;
|
||||||
|
this.componentWillReceiveProps(this.props);
|
||||||
|
},
|
||||||
|
|
||||||
componentWillUnmount() {
|
componentWillUnmount() {
|
||||||
this._unmounted = true;
|
this._unmounted = true;
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue