forked from blisstown/campfire
added foreign reaction capabilties (chuckya)
This commit is contained in:
parent
a9fdd913f3
commit
7f993ee538
3 changed files with 31 additions and 20 deletions
|
@ -1,8 +1,35 @@
|
|||
<script>
|
||||
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';
|
||||
|
||||
import ReactionButton from './ReactionButton.svelte';
|
||||
import ReactIcon from '../../../img/icons/react.svg';
|
||||
|
||||
export let post;
|
||||
|
||||
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);
|
||||
}
|
||||
</script>
|
||||
|
||||
<div class="post-reactions" aria-label="Reactions" on:mouseup|stopPropagation on:keydown|stopPropagation>
|
||||
|
@ -12,7 +39,7 @@
|
|||
on:click={() => toggleReaction(reaction)}
|
||||
bind:active={reaction.me}
|
||||
bind:count={reaction.count}
|
||||
disabled={reaction.name.includes('@')}
|
||||
disabled={reaction.name.includes('@') && !$server.capabilities.includes(capabilities.FOREIGN_REACTIONS)}
|
||||
title={reaction.name}
|
||||
label="">
|
||||
{#if reaction.url}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue