From 81784964572457da8a3ba763e80152bda0369173 Mon Sep 17 00:00:00 2001 From: Luke Barnard Date: Tue, 5 Dec 2017 14:38:17 +0000 Subject: [PATCH] Implement Store for ordering tags in the tag panel --- src/components/structures/TagPanel.js | 17 +++++- src/settings/Settings.js | 4 ++ src/stores/TagOrderStore.js | 80 +++++++++++++++++++++++++++ 3 files changed, 100 insertions(+), 1 deletion(-) create mode 100644 src/stores/TagOrderStore.js diff --git a/src/components/structures/TagPanel.js b/src/components/structures/TagPanel.js index 0107ad1db1..a853a59212 100644 --- a/src/components/structures/TagPanel.js +++ b/src/components/structures/TagPanel.js @@ -20,6 +20,7 @@ import { MatrixClient } from 'matrix-js-sdk'; import classNames from 'classnames'; import FilterStore from '../../stores/FilterStore'; import FlairStore from '../../stores/FlairStore'; +import TagOrderStore from '../../stores/TagOrderStore'; import sdk from '../../index'; import dis from '../../dispatcher'; import { isOnlyCtrlOrCmdKeyEvent } from '../../Keyboard'; @@ -115,6 +116,14 @@ export default React.createClass({ selectedTags: FilterStore.getSelectedTags(), }); }); + this._tagOrderStoreToken = TagOrderStore.addListener(() => { + if (this.unmounted) { + return; + } + this.setState({ + orderedTags: TagOrderStore.getOrderedTags(), + }); + }); this._fetchJoinedRooms(); }, @@ -157,7 +166,13 @@ export default React.createClass({ render() { const AccessibleButton = sdk.getComponent('elements.AccessibleButton'); const TintableSvg = sdk.getComponent('elements.TintableSvg'); - const tags = this.state.joinedGroupProfiles.map((groupProfile, index) => { + + const orderedGroupProfiles = this.state.orderedTags ? + this.state.joinedGroupProfiles.sort((a, b) => + this.state.orderedTags.indexOf(a.groupId) - + this.state.orderedTags.indexOf(b.groupId), + ) : this.state.joinedGroupProfiles; + const tags = orderedGroupProfiles.map((groupProfile, index) => { return t !== payload.tag); + const tagPrevIx = orderedTags.indexOf(payload.prevTag); + orderedTags = [ + ...orderedTags.slice(0, tagPrevIx + 1), + payload.tag, + ...orderedTags.slice(tagPrevIx + 1), + ]; + this._setState({orderedTags}); + SettingsStore.setValue("TagOrderStore.orderedTags", null, "account", orderedTags); + } + break; + } + } + + getOrderedTags() { + return this._state.orderedTags || SettingsStore.getValue("TagOrderStore.orderedTags"); + } +} + +if (global.singletonTagOrderStore === undefined) { + global.singletonTagOrderStore = new TagOrderStore(); +} +export default global.singletonTagOrderStore;