Something went wrong. Try again.
A live media wall for your Bluesky follows
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226<script lang="ts"> import { getContext, type Snippet } from 'svelte'; import IconHeart from 'phosphor-svelte/lib/HeartStraightIcon'; import IconBookmark from 'phosphor-svelte/lib/BookmarkSimpleIcon'; import IconLoop from 'phosphor-svelte/lib/RepeatIcon'; import type { MediaItem } from '../feed.js'; import { DISPLAY_SETTINGS_CONTEXT, type DisplaySettings } from '../display-settings.js'; import { postCountLabels, type PostCounts } from '../post-counts.js'; import IconButton from './IconButton.svelte'; import StatusMessage from './StatusMessage.svelte'; import { POST_CONTEXT, postActionKey, postActionTarget, type PostAction, type PostControls } from '../post-controls.js';
let { item, inline = false, showInteractions = true, more, onactivate }: { item: MediaItem; inline?: boolean; showInteractions?: boolean; more?: Snippet; onactivate?: (action: PostAction) => void; } = $props(); const getControls = getContext<() => PostControls>(POST_CONTEXT); const getDisplay = getContext<() => DisplaySettings>(DISPLAY_SETTINGS_CONTEXT); const counts = $derived( inline && showInteractions && !item.provisional && !item.warnings?.length && getDisplay?.().showInteractionCounts ? item.post?.counts : undefined ); const countId = $props.id(); const exactNumber = new Intl.NumberFormat(); const compactNumber = new Intl.NumberFormat(undefined, { notation: 'compact' }); const controls = $derived( showInteractions && item.post && !item.provisional ? getControls?.() : undefined ); const liked = $derived(!!item.post?.likeUri); const reposted = $derived(!!item.post?.repostUri); const bookmarked = $derived(!!item.post?.bookmarked); let localError = $state(''); const target = $derived(controls ? postActionTarget(item) : undefined); // Invalidate in-flight feedback on navigation (including A → B → A) and teardown. let targetVersion = 0; $effect.pre(() => { void target; return () => { targetVersion++; }; }); const error = $derived( localError || controls?.errors.get(postActionKey(item.uri, 'like')) || controls?.errors.get(postActionKey(item.uri, 'bookmark')) || controls?.errors.get(postActionKey(item.uri, 'repost')) );
function act(event: MouseEvent, action: PostAction) { event.preventDefault(); event.stopPropagation(); void runAction(action); }
export async function runAction(action: PostAction) { if (!controls?.enabled || controls.pending.has(postActionKey(item.uri, action))) return; localError = ''; const key = target; const version = targetVersion; const isCurrent = () => version === targetVersion && key === target && controls?.enabled; try { const result = await controls.change(item, action); if (result === 'activated' && isCurrent()) onactivate?.(action); } catch (cause) { if (isCurrent()) localError = cause instanceof Error ? cause.message : 'Unable to update post.'; } }</script>
{#snippet countLabel(key: keyof PostCounts)} {@const count = counts?.[key]} {#if count !== undefined} {@const label = `${exactNumber.format(count)} ${postCountLabels[key][count === 1 ? 0 : 1]}`} <span class="action-count" id={`${countId}-${key}`} aria-label={label} title={label}> {count < 1000 ? exactNumber.format(count) : compactNumber.format(count)} </span> {/if}{/snippet}
{#if controls || more} <div class="post-actions" class:inline> <div class="buttons" class:with-counts={counts?.likeCount !== undefined || counts?.repostCount !== undefined || counts?.bookmarkCount !== undefined} role="group" aria-label="Post actions" data-wall-post-actions={!inline ? '' : undefined} > {#if controls} <div class="action"> <IconButton variant="surface" tone="like" active={liked} aria-pressed={liked} aria-label={liked ? 'Unlike post' : 'Like post'} aria-describedby={counts?.likeCount !== undefined ? `${countId}-likeCount` : undefined} title={liked ? 'Unlike post' : 'Like post'} disabled={!controls.enabled || controls.pending.has(postActionKey(item.uri, 'like'))} aria-busy={controls.pending.has(postActionKey(item.uri, 'like'))} onclick={(event) => act(event, 'like')} > <IconHeart size={20} weight={liked ? 'fill' : 'bold'} aria-hidden="true" /> </IconButton> {@render countLabel('likeCount')} </div> <div class="action"> <IconButton variant="surface" tone="repost" active={reposted} aria-pressed={reposted} aria-label={reposted ? 'Undo repost' : 'Repost post'} aria-describedby={counts?.repostCount !== undefined ? `${countId}-repostCount` : undefined} title={reposted ? 'Undo repost' : 'Repost post'} disabled={!controls.enabled || controls.pending.has(postActionKey(item.uri, 'repost'))} aria-busy={controls.pending.has(postActionKey(item.uri, 'repost'))} onclick={(event) => act(event, 'repost')} > <IconLoop size={20} weight="bold" aria-hidden="true" /> </IconButton> {@render countLabel('repostCount')} </div> <div class="action"> <IconButton variant="surface" tone="bookmark" active={bookmarked} aria-pressed={bookmarked} aria-label={bookmarked ? 'Remove bookmark' : 'Bookmark post'} aria-describedby={counts?.bookmarkCount !== undefined ? `${countId}-bookmarkCount` : undefined} title={bookmarked ? 'Remove bookmark' : 'Bookmark post'} disabled={!controls.enabled || controls.pending.has(postActionKey(item.uri, 'bookmark'))} aria-busy={controls.pending.has(postActionKey(item.uri, 'bookmark'))} onclick={(event) => act(event, 'bookmark')} > <IconBookmark size={20} weight={bookmarked ? 'fill' : 'bold'} aria-hidden="true" /> </IconButton> {@render countLabel('bookmarkCount')} </div> {/if} {#if more} <div class="more-actions">{@render more()}</div> {/if} </div> {#if error}<StatusMessage kind="error" compact>{error}</StatusMessage>{/if} </div>{/if}
<style> .post-actions { position: absolute; top: var(--space-075); right: var(--space-075); z-index: 2; max-width: calc(100% - var(--space-075) * 2); } .post-actions.inline { position: static; max-width: 100%; margin-top: var(--space-125); } .inline .buttons { justify-content: flex-start; } .more-actions { margin-inline-start: auto; } .buttons { pointer-events: auto; display: flex; justify-content: flex-end; gap: var(--space-050); } .action { display: contents; } .with-counts { align-items: flex-start; } .with-counts .action { display: grid; justify-items: center; gap: var(--space-025); } .action-count { color: var(--color-text-secondary); font-size: var(--font-size-sm); font-variant-numeric: tabular-nums; line-height: var(--font-line-height-body); white-space: nowrap; } .post-actions { display: grid; gap: var(--space-050); }</style>