PR feedback: remove phases

This commit is contained in:
David Baker 2017-06-27 10:28:46 +01:00
parent f0aaca0a31
commit 867b47f4a2

View file

@ -30,21 +30,20 @@ module.exports = React.createClass({
getInitialState: function() { getInitialState: function() {
return { return {
phase: "GroupView.LOADING", // LOADING / DISPLAY / ERROR / NOT_FOUND
summary: null, summary: null,
error: null, error: null,
}; };
}, },
componentWillMount: function() { componentWillMount: function() {
this._loadGroupFromServer(this.props.groupId) this._loadGroupFromServer(this.props.groupId);
}, },
componentWillReceiveProps: function(new_props) { componentWillReceiveProps: function(new_props) {
if (this.props.groupId != new_props.groupId) { if (this.props.groupId != new_props.groupId) {
this.setState({ this.setState({
phase: "GroupView.LOADING",
summary: null, summary: null,
error: null,
}) })
this._loadGroupFromServer(new_props.groupId); this._loadGroupFromServer(new_props.groupId);
} }
@ -53,12 +52,11 @@ module.exports = React.createClass({
_loadGroupFromServer: function(groupId) { _loadGroupFromServer: function(groupId) {
MatrixClientPeg.get().getGroupSummary(groupId).done((res) => { MatrixClientPeg.get().getGroupSummary(groupId).done((res) => {
this.setState({ this.setState({
phase: "GroupView.DISPLAY",
summary: res, summary: res,
error: null,
}); });
}, (err) => { }, (err) => {
this.setState({ this.setState({
phase: err.httpStatus === 404 ? "GroupView.NOT_FOUND" : "GroupView.ERROR",
summary: null, summary: null,
error: err, error: err,
}); });
@ -69,9 +67,9 @@ module.exports = React.createClass({
const BaseAvatar = sdk.getComponent("avatars.BaseAvatar"); const BaseAvatar = sdk.getComponent("avatars.BaseAvatar");
const Loader = sdk.getComponent("elements.Spinner"); const Loader = sdk.getComponent("elements.Spinner");
if (this.state.phase == "GroupView.LOADING") { if (this.state.summary === null && this.state.error === null) {
return <Loader />; return <Loader />;
} else if (this.state.phase == "GroupView.DISPLAY") { } else if (this.state.summary) {
const summary = this.state.summary; const summary = this.state.summary;
let avatarUrl = null; let avatarUrl = null;
if (summary.profile.avatarUrl) { if (summary.profile.avatarUrl) {
@ -109,23 +107,25 @@ module.exports = React.createClass({
{description} {description}
</div> </div>
); );
} else if (this.state.phase == "GroupView.NOT_FOUND") { } else if (this.state.error) {
return ( if (this.state.error.httpStatus === 404) {
<div style={{margin: "auto"}}> return (
Group {this.props.groupId} not found <div style={{margin: "auto"}}>
</div> Group {this.props.groupId} not found
); </div>
} else { );
let extraText; } else {
if (this.state.error.errcode === 'M_UNRECOGNIZED') { let extraText;
extraText = <div>{_t('This Home server does not support groups')}</div>; if (this.state.error.errcode === 'M_UNRECOGNIZED') {
extraText = <div>{_t('This Home server does not support groups')}</div>;
}
return (
<div style={{margin: "auto"}}>
Failed to load {this.props.groupId}
{extraText}
</div>
);
} }
return (
<div style={{margin: "auto"}}>
Failed to load {this.props.groupId}
{extraText}
</div>
);
} }
}, },
}); });