File size: 913 Bytes
dd7ec11
a1d7896
 
dd7ec11
 
e8410db
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
dd7ec11
 
a1d7896
 
 
 
 
 
 
 
 
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
<script lang="ts">
	import UserIsLogged from "$lib/components/UserIsLogged.svelte";

  export let emoji: string;
  export let count: number;
  export let gallery_id: string;
  export let onReact: (emoji: string, id: string, deleted: boolean) => void;

  const handleReaction = async (emoji: string) => {
    await fetch(`/api/community/reaction`, {
      method: "POST",
      body: JSON.stringify({ emoji, gallery_id }),
      headers: {
        "Content-Type": "application/json",
      },
    })
    .then(res => res.json())
    .then(data => {
      onReact(emoji, data.id, data.delete);
    })
  }
</script>

<UserIsLogged>
  <button
    class="rounded-full bg-white text-sm text-neutral-800 font-bold flex items-center justify-start gap-1.5 px-2.5 py-1 border border-white hover:bg-neutral-200"
    on:click={() => handleReaction(emoji)}
  >
    <span>{emoji}</span>
    {count}
  </button>
</UserIsLogged>