File size: 690 Bytes
eb29a95
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<script lang="ts">
	import type { ReactionType } from "$lib/type";
  import Reaction from "$lib/components/community/reactions/Reaction.svelte";

  export let reactions: ReactionType[] = [];

  const groupReactionsByEmoji = (reactions: ReactionType[]) => {
    const grouped = new Set(reactions.map((reaction) => reaction.emoji));
    return Array.from(grouped).map((emoji) => {
      return {
        emoji,
        count: reactions.filter((reaction) => reaction.emoji === emoji).length,
      };
    });
  };

  const groupedReactions = groupReactionsByEmoji(reactions);
</script>

{#each groupedReactions as reaction}
  <Reaction emoji={reaction.emoji} count={reaction?.count} />
{/each}