2024-06-30 20:53:51 +01:00
|
|
|
<script>
|
2024-07-05 14:32:23 +01:00
|
|
|
import * as api from '$lib/api.js';
|
|
|
|
import { server, capabilities } from '$lib/client/server.js';
|
|
|
|
import { app } from '$lib/client/app.js';
|
|
|
|
import { get } from 'svelte/store';
|
|
|
|
import { parseReactions } from '$lib/post.js';
|
|
|
|
|
2024-06-30 20:53:51 +01:00
|
|
|
import ReactionButton from './ReactionButton.svelte';
|
|
|
|
import ReactIcon from '../../../img/icons/react.svg';
|
|
|
|
|
|
|
|
export let post;
|
2024-07-05 14:32:23 +01:00
|
|
|
|
|
|
|
async function toggleReaction(reaction) {
|
|
|
|
if (
|
|
|
|
reaction.name.includes('@') &&
|
|
|
|
!$server.capabilities.includes(capabilities.FOREIGN_REACTIONS)
|
|
|
|
) return;
|
|
|
|
|
|
|
|
let data;
|
|
|
|
if (reaction.me)
|
|
|
|
data = await api.unreactPost(get(server).host, get(app).token, post.id, reaction.name);
|
|
|
|
else
|
|
|
|
data = await api.reactPost(get(server).host, get(app).token, post.id, reaction.name);
|
|
|
|
if (!data) {
|
|
|
|
console.error(`Failed to favourite post ${post.id}`);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
post.favourited = data.favourited;
|
|
|
|
post.favourite_count = data.favourites_count;
|
|
|
|
if (data.reactions) post.reactions = parseReactions(data.reactions);
|
|
|
|
}
|
2024-06-30 20:53:51 +01:00
|
|
|
</script>
|
|
|
|
|
2024-06-30 21:08:14 +01:00
|
|
|
<div class="post-reactions" aria-label="Reactions" on:mouseup|stopPropagation on:keydown|stopPropagation>
|
2024-06-30 20:53:51 +01:00
|
|
|
{#each post.reactions as reaction}
|
|
|
|
<ReactionButton
|
|
|
|
type="reaction"
|
|
|
|
on:click={() => toggleReaction(reaction)}
|
|
|
|
bind:active={reaction.me}
|
|
|
|
bind:count={reaction.count}
|
2024-07-05 14:32:23 +01:00
|
|
|
disabled={reaction.name.includes('@') && !$server.capabilities.includes(capabilities.FOREIGN_REACTIONS)}
|
2024-06-30 20:53:51 +01:00
|
|
|
title={reaction.name}
|
|
|
|
label="">
|
|
|
|
{#if reaction.url}
|
|
|
|
<img src={reaction.url} class="emoji" height="20" title={reaction.name} alt={reaction.name}>
|
|
|
|
{:else}
|
|
|
|
{reaction.name}
|
|
|
|
{/if}
|
|
|
|
</ReactionButton>
|
|
|
|
{/each}
|
|
|
|
<ReactionButton
|
|
|
|
type="reaction"
|
|
|
|
title="react"
|
|
|
|
label="React"
|
|
|
|
disabled>
|
|
|
|
<ReactIcon/>
|
|
|
|
</ReactionButton>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<style>
|
|
|
|
.post-reactions {
|
|
|
|
width: fit-content;
|
2024-07-02 19:38:20 +01:00
|
|
|
min-height: 32px;
|
2024-06-30 20:53:51 +01:00
|
|
|
margin-top: 8px;
|
|
|
|
display: flex;
|
|
|
|
flex-direction: row;
|
2024-07-02 19:38:20 +01:00
|
|
|
flex-wrap: wrap;
|
2024-07-05 13:42:00 +01:00
|
|
|
gap: 4px;
|
2024-06-30 20:53:51 +01:00
|
|
|
}
|
|
|
|
</style>
|