From 137ff984c7ca3388fc86fdd89b52c5b738c5ed8f Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Tue, 5 Feb 2019 19:12:34 +0000 Subject: [PATCH] rather unsophisticated attempt at trimming common prefixes for avatar --- .../structures/CustomRoomTagPanel.js | 2 +- src/stores/CustomRoomTagStore.js | 38 +++++++++++++++++-- 2 files changed, 36 insertions(+), 4 deletions(-) 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}; }); }