Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Display whether the group summary/room list is loading #1560

Merged
merged 5 commits into from
Oct 31, 2017
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/components/structures/GroupView.js
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,10 @@ export default React.createClass({
getInitialState: function() {
return {
summary: null,
isGroupPublicised: null,
isUserPrivileged: null,
groupRooms: null,
groupRoomsLoading: null,
error: null,
editing: false,
saving: false,
Expand Down Expand Up @@ -458,8 +462,11 @@ export default React.createClass({
}
this.setState({
summary,
summaryLoading: !this._groupStore.isStateReady('GroupStore.Summary'),
isGroupPublicised: this._groupStore.getGroupPublicity(),
isUserPrivileged: this._groupStore.isUserPrivileged(),
groupRooms: this._groupStore.getGroupRooms(),
groupRoomsLoading: !this._groupStore.isStateReady('GroupStore.GroupRooms'),
isUserMember: this._groupStore.getGroupMembers().some(
(m) => m.userId === MatrixClientPeg.get().credentials.userId,
),
Expand Down Expand Up @@ -670,7 +677,7 @@ export default React.createClass({
<h3>{ _t('Rooms') }</h3>
{ addRoomRow }
</div>
<RoomDetailList rooms={this._groupStore.getGroupRooms()} />
<RoomDetailList rooms={this.state.groupRooms} loading={this.state.groupRoomsLoading} />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason for passing this into RoomDetailList and letting it deal with the loading state rather than just showing a spinner in lieu of it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not really, TBH. Happy do to the simpler thing of replacing it entirely with a spinner.

</div>;
},

Expand Down Expand Up @@ -866,7 +873,7 @@ export default React.createClass({
const Spinner = sdk.getComponent("elements.Spinner");
const TintableSvg = sdk.getComponent("elements.TintableSvg");

if (this.state.summary === null && this.state.error === null || this.state.saving) {
if (this.state.summaryLoading && this.state.error === null || this.state.saving) {
return <Spinner />;
} else if (this.state.summary) {
const summary = this.state.summary;
Expand Down
6 changes: 6 additions & 0 deletions src/components/views/rooms/RoomDetailList.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ export default React.createClass({

worldReadable: PropTypes.bool,
guestCanJoin: PropTypes.bool,

loading: PropTypes.bool,
})),
},

Expand All @@ -124,6 +126,10 @@ export default React.createClass({
},

render() {
const Spinner = sdk.getComponent('elements.Spinner');
if (this.props.loading) {
return <Spinner />;
}
const rows = this.getRows();
let rooms;
if (rows.length == 0) {
Expand Down
13 changes: 13 additions & 0 deletions src/stores/GroupStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ export default class GroupStore extends EventEmitter {
this._matrixClient = matrixClient;
this._summary = {};
this._rooms = [];
this._members = [];
this._invitedMembers = [];
this._ready = {};

this.on('error', (err) => {
console.error(`GroupStore for ${this.groupId} encountered error`, err);
Expand All @@ -40,6 +43,7 @@ export default class GroupStore extends EventEmitter {
this._members = result.chunk.map((apiMember) => {
return groupMemberFromApiObject(apiMember);
});
this._ready['GroupStore.GroupMembers'] = true;
this._notifyListeners();
}).catch((err) => {
console.error("Failed to get group member list: " + err);
Expand All @@ -50,6 +54,7 @@ export default class GroupStore extends EventEmitter {
this._invitedMembers = result.chunk.map((apiMember) => {
return groupMemberFromApiObject(apiMember);
});
this._ready['GroupStore.GroupInvitedMembers'] = true;
this._notifyListeners();
}).catch((err) => {
// Invited users not visible to non-members
Expand All @@ -64,6 +69,7 @@ export default class GroupStore extends EventEmitter {
_fetchSummary() {
this._matrixClient.getGroupSummary(this.groupId).then((resp) => {
this._summary = resp;
this._ready['GroupStore.Summary'] = true;
this._notifyListeners();
}).catch((err) => {
this.emit('error', err);
Expand All @@ -75,6 +81,7 @@ export default class GroupStore extends EventEmitter {
this._rooms = resp.chunk.map((apiRoom) => {
return groupRoomFromApiObject(apiRoom);
});
this._ready['GroupStore.GroupRooms'] = true;
this._notifyListeners();
}).catch((err) => {
this.emit('error', err);
Expand All @@ -87,6 +94,8 @@ export default class GroupStore extends EventEmitter {

registerListener(fn) {
this.on('update', fn);
// Call to set initial state (before fetching starts)
this.emit('update');
this._fetchSummary();
this._fetchRooms();
this._fetchMembers();
Expand All @@ -96,6 +105,10 @@ export default class GroupStore extends EventEmitter {
this.removeListener('update', fn);
}

isStateReady(id) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is quite nice but I feel like we now need to doc what string values are acceptable to it. How about defining some constants on the GroupStore class and and using these instead?

return this._ready[id];
}

getSummary() {
return this._summary;
}
Expand Down