Radish alpha
r
Radicle terminal user interface
Radicle
Git (anonymous pull)
Log in to clone via SSH
bin: Fix varying reaction order in comment item
Erik Kundt committed 1 year ago
commit 7c126555a95ba9dcd9c8edb4446f76264ad0ba8a
parent a5a446be37a2b41eeb9bb02bfc57f396018b8617
1 file changed +9 -5
modified bin/ui/items.rs
@@ -954,17 +954,21 @@ impl CommentItem {
        }
    }

-
    pub fn accumulated_reactions(&self) -> HashMap<char, usize> {
-
        let mut reactions: HashMap<char, usize> = HashMap::new();
+
    pub fn accumulated_reactions(&self) -> Vec<(char, usize)> {
+
        let mut accumulated: HashMap<char, usize> = HashMap::new();
+

        for reaction in &self.reactions {
-
            if let Some(count) = reactions.get_mut(reaction) {
+
            if let Some(count) = accumulated.get_mut(reaction) {
                *count = count.saturating_add(1);
            } else {
-
                reactions.insert(*reaction, 1_usize);
+
                accumulated.insert(*reaction, 1_usize);
            }
        }

-
        reactions
+
        let mut sorted = accumulated.into_iter().collect::<Vec<_>>();
+
        sorted.sort();
+

+
        sorted
    }
}