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';
|
2024-07-07 14:33:28 +01:00
|
|
|
import { account } from '@cf/store/account';
|
2024-07-05 14:32:23 +01:00
|
|
|
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) {
|
2024-07-07 14:33:28 +01:00
|
|
|
if (!$app || !$app.token) return;
|
|
|
|
|
2024-07-05 14:32:23 +01:00
|
|
|
if (
|
|
|
|
reaction.name.includes('@') &&
|
|
|
|
!$server.capabilities.includes(capabilities.FOREIGN_REACTIONS)
|
|
|
|
) return;
|
|
|
|
|
|
|
|
let data;
|
|
|
|
if (reaction.me)
|
2024-07-07 14:33:28 +01:00
|
|
|
data = await api.unreactPost($server.host, $app.token, post.id, reaction.name);
|
2024-07-05 14:32:23 +01:00
|
|
|
else
|
2024-07-07 14:33:28 +01:00
|
|
|
data = await api.reactPost($server.host, $app.token, post.id, reaction.name);
|
2024-07-05 14:32:23 +01:00
|
|
|
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-07 14:33:28 +01:00
|
|
|
disabled={!$account || (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>
|