mirror of
https://github.com/element-hq/element-web
synced 2024-11-28 20:38:55 +03:00
Use AccountData im.vector.web.tag_ordering
Also, make defaults sensible
This commit is contained in:
parent
7aa5dcef69
commit
4af7def20e
1 changed files with 22 additions and 12 deletions
|
@ -16,10 +16,11 @@ limitations under the License.
|
||||||
import {Store} from 'flux/utils';
|
import {Store} from 'flux/utils';
|
||||||
import dis from '../dispatcher';
|
import dis from '../dispatcher';
|
||||||
// import Analytics from '../Analytics';
|
// import Analytics from '../Analytics';
|
||||||
import SettingsStore from "../settings/SettingsStore";
|
import MatrixClientPeg from "../MatrixClientPeg";
|
||||||
|
|
||||||
const INITIAL_STATE = {
|
const INITIAL_STATE = {
|
||||||
orderedTags: null,
|
orderedTags: null,
|
||||||
|
allTags: null,
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -40,23 +41,28 @@ class TagOrderStore extends Store {
|
||||||
|
|
||||||
__onDispatch(payload) {
|
__onDispatch(payload) {
|
||||||
switch (payload.action) {
|
switch (payload.action) {
|
||||||
|
// Get ordering from account data, once the client has synced
|
||||||
case 'sync_state':
|
case 'sync_state':
|
||||||
// Get ordering from account data, once the client has synced
|
|
||||||
if (payload.prevState === "PREPARED" && payload.state === "SYNCING") {
|
if (payload.prevState === "PREPARED" && payload.state === "SYNCING") {
|
||||||
this._setState({
|
const accountDataEvent = MatrixClientPeg.get().getAccountData('im.vector.web.tag_ordering');
|
||||||
orderedTags: SettingsStore.getValue("TagOrderStore.orderedTags"),
|
|
||||||
});
|
const orderedTags = accountDataEvent && accountDataEvent.getContent() ?
|
||||||
|
accountDataEvent.getContent().tags : null;
|
||||||
|
|
||||||
|
this._setState({orderedTags});
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
// Initialise the state such that if account data is unset, default to the existing ordering
|
||||||
case 'all_tags':
|
case 'all_tags':
|
||||||
// Initialise the state with all known tags displayed in the TagPanel
|
this._setState({
|
||||||
this._setState({allTags: payload.tags});
|
allTags: payload.tags.sort(), // Sort lexically
|
||||||
|
});
|
||||||
break;
|
break;
|
||||||
|
// Puts payload.tag at payload.targetTag, placing the targetTag before or after the tag
|
||||||
case 'order_tag': {
|
case 'order_tag': {
|
||||||
if (!payload.tag || !payload.targetTag || payload.tag === payload.targetTag) break;
|
if (!payload.tag || !payload.targetTag || payload.tag === payload.targetTag) return;
|
||||||
|
|
||||||
// Puts payload.tag at payload.targetTag, placing the targetTag before or after the tag
|
const tags = this._state.orderedTags || this._state.allTags;
|
||||||
const tags = SettingsStore.getValue("TagOrderStore.orderedTags") || this._state.allTags;
|
|
||||||
|
|
||||||
let orderedTags = tags.filter((t) => t !== payload.tag);
|
let orderedTags = tags.filter((t) => t !== payload.tag);
|
||||||
const newIndex = orderedTags.indexOf(payload.targetTag) + (payload.after ? 1 : 0);
|
const newIndex = orderedTags.indexOf(payload.targetTag) + (payload.after ? 1 : 0);
|
||||||
|
@ -69,13 +75,17 @@ class TagOrderStore extends Store {
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'commit_tags':
|
case 'commit_tags':
|
||||||
SettingsStore.setValue("TagOrderStore.orderedTags", null, "account", this._state.orderedTags);
|
MatrixClientPeg.get().setAccountData('im.vector.web.tag_ordering', {tags: this._state.orderedTags});
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
getOrderedTags() {
|
getOrderedTags() {
|
||||||
return this._state.orderedTags || SettingsStore.getValue("TagOrderStore.orderedTags");
|
return this._state.orderedTags;
|
||||||
|
}
|
||||||
|
|
||||||
|
getAllTags() {
|
||||||
|
return this._state.allTags;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue