Introduce action creators
These can be used to dispatch actions immediately, or after some asynchronous work has been done. Also, create GroupActions.fetchJoinedGroups as an example. The concept of async action creators can be used in the following cases: - stores or views that do async work, dispatching based on the results - actions that have complicated payloads, would make more sense as functions with documentation that dispatch created actions.
This commit is contained in:
parent
65d88334a9
commit
ee6df105fe
4 changed files with 64 additions and 16 deletions
|
@ -20,6 +20,9 @@ import { MatrixClient } from 'matrix-js-sdk';
|
|||
import FilterStore from '../../stores/FilterStore';
|
||||
import FlairStore from '../../stores/FlairStore';
|
||||
import TagOrderStore from '../../stores/TagOrderStore';
|
||||
|
||||
import GroupActions from '../../actions/GroupActions';
|
||||
|
||||
import sdk from '../../index';
|
||||
import dis from '../../dispatcher';
|
||||
|
||||
|
@ -62,8 +65,8 @@ const TagPanel = React.createClass({
|
|||
this.setState({orderedGroupTagProfiles});
|
||||
});
|
||||
});
|
||||
|
||||
this._fetchJoinedRooms();
|
||||
// This could be done by anything with a matrix client
|
||||
GroupActions.fetchJoinedGroups(this.context.matrixClient);
|
||||
},
|
||||
|
||||
componentWillUnmount() {
|
||||
|
@ -76,7 +79,7 @@ const TagPanel = React.createClass({
|
|||
|
||||
_onGroupMyMembership() {
|
||||
if (this.unmounted) return;
|
||||
this._fetchJoinedRooms();
|
||||
GroupActions.fetchJoinedGroups(this.context.matrixClient);
|
||||
},
|
||||
|
||||
onClick() {
|
||||
|
@ -88,16 +91,6 @@ const TagPanel = React.createClass({
|
|||
dis.dispatch({action: 'view_create_group'});
|
||||
},
|
||||
|
||||
async _fetchJoinedRooms() {
|
||||
// This could be done by anything with a matrix client (, see TagOrderStore).
|
||||
const joinedGroupResponse = await this.context.matrixClient.getJoinedGroups();
|
||||
const joinedGroupIds = joinedGroupResponse.groups;
|
||||
dis.dispatch({
|
||||
action: 'all_tags',
|
||||
tags: joinedGroupIds,
|
||||
});
|
||||
},
|
||||
|
||||
render() {
|
||||
const AccessibleButton = sdk.getComponent('elements.AccessibleButton');
|
||||
const TintableSvg = sdk.getComponent('elements.TintableSvg');
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue