2024-06-30 20:53:51 +01:00
|
|
|
<script>
|
2024-07-07 12:57:04 +01:00
|
|
|
import * as api from '$lib/api';
|
|
|
|
import { server } from '$lib/client/server';
|
|
|
|
import { app } from '$lib/client/app';
|
|
|
|
import { account } from '@cf/store/account';
|
|
|
|
import { timeline } from '$lib/timeline';
|
|
|
|
import { parseReactions } from '$lib/post';
|
2024-07-08 11:56:26 +01:00
|
|
|
import { playSound } from '$lib/sound';
|
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';
|
2024-07-07 12:57:04 +01:00
|
|
|
import DeleteIcon from '../../../img/icons/bin.svg';
|
2024-06-30 20:53:51 +01:00
|
|
|
|
|
|
|
export let post;
|
|
|
|
|
|
|
|
async function toggleBoost() {
|
2024-07-07 14:33:28 +01:00
|
|
|
if (!$app || !$app.token) return;
|
|
|
|
|
2024-06-30 20:53:51 +01:00
|
|
|
let data;
|
2024-07-08 11:56:26 +01:00
|
|
|
if (post.boosted) {
|
|
|
|
playSound();
|
2024-07-07 14:33:28 +01:00
|
|
|
data = await api.unboostPost($server.host, $app.token, post.id);
|
2024-07-08 11:56:26 +01:00
|
|
|
} else {
|
|
|
|
playSound("boost");
|
2024-07-07 14:33:28 +01:00
|
|
|
data = await api.boostPost($server.host, $app.token, post.id);
|
2024-07-08 11:56:26 +01:00
|
|
|
}
|
|
|
|
|
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() {
|
2024-07-07 14:33:28 +01:00
|
|
|
if (!$app || !$app.token) return;
|
|
|
|
|
2024-06-30 20:53:51 +01:00
|
|
|
let data;
|
|
|
|
if (post.favourited)
|
2024-07-07 14:33:28 +01:00
|
|
|
data = await api.unfavouritePost($server.host, $app.token, post.id);
|
2024-06-30 20:53:51 +01:00
|
|
|
else
|
2024-07-07 14:33:28 +01:00
|
|
|
data = await api.favouritePost($server.host, $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
|
|
|
}
|
2024-07-07 12:57:04 +01:00
|
|
|
|
|
|
|
async function deletePost() {
|
|
|
|
if (!$account || post.account.id !== $account.id) return;
|
|
|
|
|
|
|
|
if (!confirm("Are you sure you want to delete this post? This action cannot be undone."))
|
|
|
|
return;
|
|
|
|
|
|
|
|
const res = await api.deletePost($server.host, $app.token, post.id);
|
|
|
|
|
|
|
|
if (!res || res.error) {
|
|
|
|
console.error(`Error while deleting post ${post.id}`);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
timeline.update(timeline => timeline.filter(p => p.id !== post.id));
|
|
|
|
}
|
2024-06-30 20:53:51 +01:00
|
|
|
</script>
|
|
|
|
|
2024-07-07 12:57:04 +01:00
|
|
|
<div class="post-actions" aria-label="Post actions" role="toolbar" tabindex="0" 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>
|
2024-07-08 11:56:26 +01:00
|
|
|
<ActionButton type="boost" label="Boost" on:click={toggleBoost} bind:active={post.boosted} bind:count={post.boost_count} disabled={!$account}>
|
2024-06-30 20:53:51 +01:00
|
|
|
<RepostIcon/>
|
|
|
|
<svelte:fragment slot="activeIcon">
|
|
|
|
<RepostIcon/>
|
|
|
|
</svelte:fragment>
|
|
|
|
</ActionButton>
|
2024-07-07 14:33:28 +01:00
|
|
|
<ActionButton type="favourite" label="Favourite" on:click={toggleFavourite} bind:active={post.favourited} bind:count={post.favourite_count} disabled={!$account}>
|
2024-06-30 20:53:51 +01:00
|
|
|
<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>
|
2024-07-07 12:57:04 +01:00
|
|
|
{#if $account && post.account.id === $account.id}
|
|
|
|
<ActionButton type="delete" label="Delete" on:click={deletePost}>
|
|
|
|
<DeleteIcon/>
|
|
|
|
</ActionButton>
|
|
|
|
{/if}
|
2024-06-30 20:53:51 +01:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<style>
|
|
|
|
.post-actions {
|
|
|
|
width: fit-content;
|
|
|
|
height: 36px;
|
|
|
|
margin-top: 8px;
|
|
|
|
display: flex;
|
|
|
|
flex-direction: row;
|
|
|
|
gap: 4px;
|
|
|
|
}
|
|
|
|
</style>
|