Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
File size: 1,408 Bytes
eb29a95 e8410db eb29a95 e8410db eb29a95 e8410db eb29a95 e8410db eb29a95 e8410db |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
<script lang="ts">
import type { ReactionType } from "$lib/type";
import Add from "$lib/components/community/reactions/Add.svelte";
import Reaction from "$lib/components/community/reactions/Reaction.svelte";
import { get } from 'svelte/store';
import { userStore } from "$lib/stores/use-user";
let user = get(userStore);
export let reactions: ReactionType[] = [];
export let gallery_id: string;
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,
};
});
};
$: groupedReactions = groupReactionsByEmoji(reactions);
</script>
{#each groupedReactions as reaction}
<Reaction
emoji={reaction.emoji}
count={reaction?.count}
{gallery_id}
onReact={(emoji, id, deleted) => {
if (deleted) {
reactions = reactions.filter((reaction) => reaction.id !== id);
} else {
reactions = [...reactions, { emoji, hf_user_id: user?.sub, galleryId: gallery_id, id }];
}
}}
/>
{/each}
<Add
count={groupedReactions?.length}
reactions={groupedReactions}
{gallery_id}
onAdd={(emoji, id) => {
reactions = [...reactions, { emoji, hf_user_id: user?.sub, galleryId: gallery_id, id }];
}}
/>
|