You've already forked matrix-react-sdk
mirror of
https://github.com/matrix-org/matrix-react-sdk.git
synced 2025-11-19 05:22:13 +03:00
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:
@@ -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');
|
||||
|
||||
Reference in New Issue
Block a user