diff --git a/src/components/structures/CustomRoomTagPanel.js b/src/components/structures/CustomRoomTagPanel.js index 5e6a1c14f3..9b342591ba 100644 --- a/src/components/structures/CustomRoomTagPanel.js +++ b/src/components/structures/CustomRoomTagPanel.js @@ -111,7 +111,7 @@ class CustomRoomTagTile extends React.Component { return (
= 2) { + return prefix; + } + return ""; +} /** * A class for storing application state for ordering tags in the TagPanel. */ @@ -41,9 +62,20 @@ class CustomRoomTagStore extends Store { return this._state.tags; } - getSortedTags() {this._state.tags - return Object.keys(this._state.tags).sort().map((name) => { - return {name, selected: this._state.tags[name]}; + getSortedTags() { + const tagNames = Object.keys(this._state.tags).sort(); + const prefixes = tagNames.map((name, i) => { + const isFirst = i === 0; + const isLast = i === tagNames.length - 1; + const backwardsPrefix = !isFirst ? commonPrefix(name, tagNames[i - 1]) : ""; + const forwardsPrefix = !isLast ? commonPrefix(name, tagNames[i + 1]) : ""; + const longestPrefix = backwardsPrefix.length > forwardsPrefix.length ? + backwardsPrefix : forwardsPrefix; + return longestPrefix; + }); + return tagNames.map((name, i) => { + const avatarLetter = name.substr(prefixes[i].length, 1); + return {name, selected: this._state.tags[name], avatarLetter}; }); }