fix: support eliding after 5 authors

fix rightNode subscript
This commit is contained in:
hydrogen 2020-11-24 00:50:40 +02:00 committed by Iuri Matias
parent 9f6e582111
commit a7936e984d
1 changed files with 25 additions and 1 deletions

View File

@ -9,6 +9,30 @@ Item {
height: 20 height: 20
width: childrenRect.width width: childrenRect.width
function lastTwoItems(left, right) {
return left + " and " + right;
}
function showReactionAuthors(fromAccounts) {
if (fromAccounts.length < 3)
return fromAccounts.join(" and ");
var leftNode = [];
var rightNode = [];
if (fromAccounts.length > 3) {
leftNode = fromAccounts.slice(0, 3);
rightNode = fromAccounts.slice(3, fromAccounts.length);
return (rightNode.length == 1) ?
lastTwoItems(leftNode.join(", "), rightNode[0]) :
lastTwoItems(leftNode.join(", "), `${rightNode.length} more reacted.`);
}
leftNode = fromAccounts.slice(0, 2);
rightNode = fromAccounts.slice(2, fromAccounts.length);
return lastTwoItems(leftNode.join(", "), rightNode[0]);
}
Repeater { Repeater {
id: reactionepeater id: reactionepeater
model: { model: {
@ -54,7 +78,7 @@ Item {
ToolTip { ToolTip {
visible: mouseArea.containsMouse visible: mouseArea.containsMouse
text: modelData.fromAccounts.join(", ") text: showReactionAuthors(modelData.fromAccounts)
} }
// Rounded corner to cover one corner // Rounded corner to cover one corner