2024-06-30 20:53:51 +01:00
|
|
|
<script>
|
2024-07-03 22:00:32 +01:00
|
|
|
import * as api from '$lib/api.js';
|
2024-06-30 20:53:51 +01:00
|
|
|
import { get } from 'svelte/store';
|
2024-07-03 22:00:32 +01:00
|
|
|
import { server } from '$lib/client/server.js';
|
|
|
|
import { app } from '$lib/client/app.js';
|
|
|
|
import { parseReactions } from '$lib/post.js';
|
2024-06-30 20:53:51 +01:00
|
|
|
|
|
|
|
import ActionButton from './ActionButton.svelte';
|
|
|
|
|
|
|
|
import ReplyIcon from '../../../img/icons/reply.svg';
|
|
|
|
import RepostIcon from '../../../img/icons/repost.svg';
|
|
|
|
import FavouriteIcon from '../../../img/icons/like.svg';
|
|
|
|
import FavouriteIconFill from '../../../img/icons/like_fill.svg';
|
|
|
|
import QuoteIcon from '../../../img/icons/quote.svg';
|
|
|
|
import MoreIcon from '../../../img/icons/more.svg';
|
|
|
|
|
|
|
|
export let post;
|
|
|
|
|
|
|
|
async function toggleBoost() {
|
|
|
|
let data;
|
|
|
|
if (post.boosted)
|
2024-07-03 22:00:32 +01:00
|
|
|
data = await api.unboostPost(get(server).host, get(app).token, post.id);
|
2024-06-30 20:53:51 +01:00
|
|
|
else
|
2024-07-03 22:00:32 +01:00
|
|
|
data = await api.boostPost(get(server).host, get(app).token, post.id);
|
2024-06-30 20:53:51 +01:00
|
|
|
if (!data) {
|
|
|
|
console.error(`Failed to boost post ${post.id}`);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
post.boosted = data.reblog ? data.reblog.reblogged : data.boosted;
|
|
|
|
post.boost_count = data.reblog ? data.reblog.reblogs_count : data.reblogs_count;
|
|
|
|
}
|
|
|
|
|
|
|
|
async function toggleFavourite() {
|
|
|
|
let data;
|
|
|
|
if (post.favourited)
|
2024-07-03 22:00:32 +01:00
|
|
|
data = await api.unfavouritePost(get(server).host, get(app).token, post.id);
|
2024-06-30 20:53:51 +01:00
|
|
|
else
|
2024-07-03 22:00:32 +01:00
|
|
|
data = await api.favouritePost(get(server).host, get(app).token, post.id);
|
2024-06-30 20:53:51 +01:00
|
|
|
if (!data) {
|
|
|
|
console.error(`Failed to favourite post ${post.id}`);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
post.favourited = data.favourited;
|
|
|
|
post.favourite_count = data.favourites_count;
|
2024-07-03 22:00:32 +01:00
|
|
|
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-actions" aria-label="Post actions" on:mouseup|stopPropagation on:keydown|stopPropagation>
|
2024-06-30 20:53:51 +01:00
|
|
|
<ActionButton type="reply" label="Reply" bind:count={post.reply_count} sound="post" disabled>
|
|
|
|
<ReplyIcon/>
|
|
|
|
</ActionButton>
|
|
|
|
<ActionButton type="boost" label="Boost" on:click={toggleBoost} bind:active={post.boosted} bind:count={post.boost_count} sound="boost">
|
|
|
|
<RepostIcon/>
|
|
|
|
<svelte:fragment slot="activeIcon">
|
|
|
|
<RepostIcon/>
|
|
|
|
</svelte:fragment>
|
|
|
|
</ActionButton>
|
|
|
|
<ActionButton type="favourite" label="Favourite" on:click={toggleFavourite} bind:active={post.favourited} bind:count={post.favourite_count}>
|
|
|
|
<FavouriteIcon/>
|
|
|
|
<svelte:fragment slot="activeIcon">
|
|
|
|
<FavouriteIconFill/>
|
|
|
|
</svelte:fragment>
|
|
|
|
</ActionButton>
|
|
|
|
<ActionButton type="quote" label="Quote" disabled>
|
|
|
|
<QuoteIcon/>
|
|
|
|
</ActionButton>
|
|
|
|
<ActionButton type="more" label="More" disabled>
|
|
|
|
<MoreIcon/>
|
|
|
|
</ActionButton>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<style>
|
|
|
|
.post-actions {
|
|
|
|
width: fit-content;
|
|
|
|
height: 36px;
|
|
|
|
margin-top: 8px;
|
|
|
|
display: flex;
|
|
|
|
flex-direction: row;
|
|
|
|
gap: 4px;
|
|
|
|
}
|
|
|
|
</style>
|