diff --git a/src/actions/TagOrderActions.js b/src/actions/TagOrderActions.js new file mode 100644 index 0000000000..d98cf28ca8 --- /dev/null +++ b/src/actions/TagOrderActions.js @@ -0,0 +1,33 @@ +/* +Copyright 2017 Vector Creations Ltd + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +import Analytics from '../Analytics'; +import { createPromiseActionCreator } from './actionCreators'; +import TagOrderStore from '../stores/TagOrderStore'; + +const TagOrderActions = {}; + +TagOrderActions.commitTagOrdering = createPromiseActionCreator( + 'TagOrderActions.commitTagOrdering', + (matrixClient) => { + Analytics.trackEvent('TagOrderActions', 'commitTagOrdering'); + return matrixClient.setAccountData('im.vector.web.tag_ordering', { + tags: TagOrderStore.getOrderedTags(), + }); + }, +); + +export default TagOrderActions; diff --git a/src/components/structures/TagPanel.js b/src/components/structures/TagPanel.js index ae86bef4c1..127a220b26 100644 --- a/src/components/structures/TagPanel.js +++ b/src/components/structures/TagPanel.js @@ -22,6 +22,7 @@ import FlairStore from '../../stores/FlairStore'; import TagOrderStore from '../../stores/TagOrderStore'; import GroupActions from '../../actions/GroupActions'; +import TagOrderActions from '../../actions/TagOrderActions'; import sdk from '../../index'; import dis from '../../dispatcher'; @@ -91,6 +92,10 @@ const TagPanel = React.createClass({ dis.dispatch({action: 'view_create_group'}); }, + onTagTileEndDrag() { + TagOrderActions.commitTagOrdering(this.context.matrixClient); + }, + render() { const AccessibleButton = sdk.getComponent('elements.AccessibleButton'); const TintableSvg = sdk.getComponent('elements.TintableSvg'); @@ -101,6 +106,7 @@ const TagPanel = React.createClass({ key={groupProfile.groupId + '_' + index} groupProfile={groupProfile} selected={this.state.selectedTags.includes(groupProfile.groupId)} + onEndDrag={this.onTagTileEndDrag} />; }); return
diff --git a/src/components/views/elements/DNDTagTile.js b/src/components/views/elements/DNDTagTile.js index 55c09a3720..4d03534980 100644 --- a/src/components/views/elements/DNDTagTile.js +++ b/src/components/views/elements/DNDTagTile.js @@ -38,9 +38,7 @@ const tagTileSource = { if (!monitor.didDrop() || !dropResult) { return; } - dis.dispatch({ - action: 'commit_tags', - }); + props.onEndDrag(); }, }; diff --git a/src/stores/TagOrderStore.js b/src/stores/TagOrderStore.js index a5eae3806e..960839fa06 100644 --- a/src/stores/TagOrderStore.js +++ b/src/stores/TagOrderStore.js @@ -15,8 +15,6 @@ limitations under the License. */ import {Store} from 'flux/utils'; import dis from '../dispatcher'; -import Analytics from '../Analytics'; -import MatrixClientPeg from "../MatrixClientPeg"; const INITIAL_STATE = { orderedTags: null, @@ -71,10 +69,6 @@ class TagOrderStore extends Store { this._setState({orderedTags}); } break; - case 'commit_tags': - MatrixClientPeg.get().setAccountData('im.vector.web.tag_ordering', {tags: this._state.orderedTags}); - Analytics.trackEvent('TagOrderStore', 'commit_tags'); - break; } }