Something went wrong. Try again.
A live media wall for your Bluesky follows
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542<script lang="ts"> import { shortcutAria, shortcutHint, type HoverAction, type ShortcutBindings } from '../wall-shortcuts.js'; import IconArrowLeft from 'phosphor-svelte/lib/ArrowLeftIcon'; import type { Agent, AppBskyFeedDefs, ModerationOpts } from '@atproto/api'; import { getContext, onMount, setContext, untrack } from 'svelte'; import type { Attachment } from 'svelte/attachments'; import { PROFILE_CONTEXT, PROFILE_NAVIGATION_CONTEXT, type ProfileCard, type ProfileStore } from '../profiles.js'; import { extractMedia, type InteractionUpdate, type MediaItem } from '../feed.js'; import { applyPostInteractions, type PostInteractionChanges } from '../post-counts.js'; import { createAuthorMedia, mergeAuthorMedia } from '../author-media.js'; import type { ContentSettings } from '../content-settings.js'; import type { DisplaySettings } from '../display-settings.js'; import { withoutHiddenPosts, type HiddenPost } from '../hidden-posts.js'; import Avatar from './Avatar.svelte'; import IconButton from './IconButton.svelte'; import Button from './Button.svelte'; import StatusMessage from './StatusMessage.svelte'; import FollowButton from './FollowButton.svelte'; import AccountMenu from './AccountMenu.svelte'; import MasonryWall from './MasonryWall.svelte'; import MediaViewer from './MediaViewer.svelte';
let { did, agent, moderation, settings, hiddenPosts, display, paused = false, settingsOpen = false, shortcutBindings = {}, onclose, onpostshortcut, onitems, attachWall, postChanges, interactionUpdate }: { did: string; agent: Agent; moderation?: ModerationOpts; settings: ContentSettings; hiddenPosts: ReadonlyMap<string, HiddenPost>; display: DisplaySettings; paused?: boolean; settingsOpen?: boolean; shortcutBindings?: ShortcutBindings; onclose: () => void; onpostshortcut: (action: HoverAction, item: MediaItem) => Promise<string | undefined>; onitems?: (items: MediaItem[]) => void; attachWall?: Attachment<HTMLDivElement>; postChanges: ReadonlyMap<string, ReadonlyMap<string, PostInteractionChanges>>; interactionUpdate?: Extract<InteractionUpdate, { kind: 'actor' }>; } = $props();
type Post = AppBskyFeedDefs.PostView; type ActorChanges = Omit<Extract<InteractionUpdate, { kind: 'actor' }>, 'kind' | 'did'>; const getStore = getContext<(() => ProfileStore | undefined) | undefined>(PROFILE_CONTEXT); const navigateProfile = getContext<((did: string) => void) | undefined>( PROFILE_NAVIGATION_CONTEXT ); setContext(PROFILE_NAVIGATION_CONTEXT, (target: string) => { selectedId = undefined; if (target !== did) navigateProfile?.(target); }); let back = $state<HTMLButtonElement>(); let card = $state<ProfileCard>(); let media = $state.raw(createAuthorMedia()); const raw = $derived(media.posts); let revealed = $state<Set<string>>(new Set()); let selectedId = $state<string>(); let profileError = $state(''); let mediaError = $state(''); let loading = $state(false); const started = $derived(media.started); const cursor = $derived(media.cursor); const scanned = $derived(media.scanned); let revision = $state(0); let actorChanges = $state<ActorChanges>({}); let loadedPolicy = $state.raw<ModerationOpts>(); let loadedAgent = $state.raw<Agent>(); let loadedStore = $state.raw<ProfileStore>(); let loadedPolicyKey = $state<string>(); const policyKey = $derived(JSON.stringify(moderation)); let controller: AbortController | undefined; let generation = 0; const currentCard = $derived.by(() => { void policyKey; const store = getStore?.(); if (card?.did !== did || loadedAgent !== agent) return undefined; return ( store?.peek(did) ?? (loadedStore === store && loadedPolicy === moderation && loadedPolicyKey === policyKey ? card : undefined) ); }); const restricted = $derived( !!currentCard?.restricted || actorChanges.muted === true || !!actorChanges.blocking ); const items = $derived.by(() => { if (!moderation || !currentCard || restricted) return []; return withoutHiddenPosts(raw, hiddenPosts).flatMap((post) => { const changes = postChanges.get(post.uri)?.get(post.cid); return extractMedia( changes ? applyPostInteractions(post, changes) : post, moderation, settings, revealed.has(post.uri) ); }); }); const selected = $derived(items.find((item) => item.id === selectedId)); const horizontalScroll = $derived(display.layout === 'horizontal' && !!display.horizontalScroll);
$effect(() => { if (selectedId && !selected) selectedId = undefined; onitems?.(items); });
function overlay(post: Post): Post { return { ...post, author: { ...post.author, viewer: { ...post.author.viewer, ...(actorChanges.following !== undefined ? { following: actorChanges.following ?? undefined } : {}), ...(actorChanges.muted !== undefined ? { muted: actorChanges.muted } : {}), ...(actorChanges.blocking !== undefined ? { blocking: actorChanges.blocking ?? undefined } : {}) } } }; }
function cancel() { generation++; controller?.abort(); controller = undefined; loading = false; }
async function loadMore() { if (loading || !moderation || !currentCard || restricted || scanned >= 500) return; if (started && !cursor) return; const version = generation; const target = did; const client = agent; const request = new AbortController(); controller = request; loading = true; mediaError = ''; try { const { data } = await client.app.bsky.feed.getAuthorFeed( { actor: target, filter: 'posts_with_media', includePins: false, limit: 50, cursor }, { signal: request.signal } ); if (request.signal.aborted || version !== generation || target !== did || client !== agent) return; const merged = mergeAuthorMedia(media, target, data); media = { ...merged, posts: merged.posts.map(overlay) }; } catch { if (!request.signal.aborted && version === generation) mediaError = 'Could not load media. Retry, or sign in again to renew access.'; } finally { if (version === generation && controller === request) { loading = false; controller = undefined; } } }
function reveal(uri: string) { if (items.some((item) => item.uri === uri)) revealed = new Set([...revealed, uri]); }
function open(item: MediaItem) { selectedId = item.id; }
function sidewaysWheel(node: HTMLDivElement) { const wheel = (event: WheelEvent) => { const profile = event.target instanceof Element ? event.target.closest('.profile-card') : null; if ( (profile && profile.getBoundingClientRect().height > window.innerHeight) || !horizontalScroll || event.ctrlKey || event.shiftKey || Math.abs(event.deltaX) > Math.abs(event.deltaY) ) return; const delta = event.deltaY * (event.deltaMode === 1 ? 16 : event.deltaMode === 2 ? node.clientWidth : 1); if ( (delta < 0 && node.scrollLeft > 0) || (delta > 0 && node.scrollLeft < node.scrollWidth - node.clientWidth) ) { event.preventDefault(); node.scrollLeft += delta; } }; node.addEventListener('wheel', wheel, { passive: false }); return { destroy: () => node.removeEventListener('wheel', wheel) }; }
$effect(() => { void did; void agent; untrack(() => { cancel(); card = undefined; media = createAuthorMedia(); actorChanges = {}; revealed = new Set(); selectedId = undefined; mediaError = ''; }); });
$effect(() => { const target = did; const client = agent; const policy = moderation; const key = policyKey; const store = getStore?.(); void revision; let active = true; untrack(() => { cancel(); profileError = ''; }); if (!store) profileError = 'Profile access is unavailable. Try again.'; else void store .get(target) .then((value) => { if (active && client === agent && target === did && value.did === target) { card = value; loadedPolicy = policy; loadedPolicyKey = key; loadedAgent = client; loadedStore = store; } }) .catch(() => { if (active) profileError = 'Could not load this profile. Try again.'; }); return () => { active = false; cancel(); }; });
const settingsKey = $derived(JSON.stringify(settings)); $effect(() => { void policyKey; void settingsKey; revealed = new Set(); selectedId = undefined; });
$effect(() => { if (moderation && currentCard && !restricted && !started) untrack(() => { void loadMore(); }); });
$effect(() => { const update = interactionUpdate; if (!update || update.did !== did) return; untrack(() => { const { kind: _kind, did: _did, ...changes } = update; actorChanges = { ...actorChanges, ...changes }; media = { ...media, posts: raw.map(overlay) }; if (update.muted !== undefined || update.blocking !== undefined) { cancel(); media = createAuthorMedia(); revealed = new Set(); selectedId = undefined; revision++; } }); });
onMount(() => { const previous = document.activeElement instanceof HTMLElement ? document.activeElement : undefined; window.scrollTo({ top: 0, left: 0, behavior: 'instant' }); back?.focus({ preventScroll: true }); return () => { cancel(); if (previous?.isConnected) previous.focus({ preventScroll: true }); }; });</script>
<section class="profile-view" aria-label="Profile"> <header class="navigation"> <IconButton bind:element={back} aria-label="Back to wall" aria-keyshortcuts={shortcutAria('back', shortcutBindings)} title={shortcutHint('back', shortcutBindings) ? `Back to wall (${shortcutHint('back', shortcutBindings)})` : 'Back to wall'} onclick={onclose} > <IconArrowLeft size={20} aria-hidden="true" /> </IconButton> <span>Profile</span> </header> {#snippet profileCard()} {#if currentCard} <article class="profile-card" data-profile-shortcut-did={currentCard.did}> {#if !restricted && currentCard.banner} <img class="banner" src={currentCard.banner} alt="" referrerpolicy="no-referrer" /> {/if} <div class="identity"> <div class="identity-actions"> <Avatar src={restricted ? undefined : currentCard.avatar} size={80} /> <div class="actions"> {#if !restricted}<FollowButton did={currentCard.did} handle={currentCard.handle} following={actorChanges.following !== undefined ? (actorChanges.following ?? undefined) : currentCard.following} />{/if} <AccountMenu did={currentCard.did} handle={currentCard.handle} ondone={() => {}} /> </div> </div> <h1>{(!restricted && currentCard.displayName) || `@${currentCard.handle}`}</h1> <a class="handle" href={`https://bsky.app/profile/${currentCard.did}`} target="_blank" rel="noreferrer">@{currentCard.handle}</a > {#if restricted} <p role="status">This profile is hidden by your moderation settings.</p> {:else} {#if currentCard.pronouns}<p class="pronouns">{currentCard.pronouns}</p>{/if} {#if currentCard.description}<p class="bio">{currentCard.description}</p>{/if} {#if currentCard.links.length}<ul class="links"> {#each currentCard.links as link}<li> <a href={link.url} target="_blank" rel="noreferrer">{link.title}</a> </li>{/each} </ul>{/if} {/if} {#if currentCard.labels.length}<details> <summary>Account labels ({currentCard.labels.length})</summary> <ul> {#each currentCard.labels as label}<li> <strong>{label.value}</strong><span class="source">{label.source}</span> </li>{/each} </ul> </details>{/if} </div> </article> {:else if profileError} <div class="status"> <StatusMessage kind="error">{profileError}</StatusMessage> <Button type="button" onclick={() => revision++}>Retry profile</Button> </div> {:else} <div class="status"><StatusMessage>Loading profile…</StatusMessage></div> {/if} {/snippet} <div class="wall" class:sideways={horizontalScroll} use:sidewaysWheel {@attach attachWall}> <MasonryWall {items} leading={profileCard} paused={paused || settingsOpen || !!selected} playbackActive={!settingsOpen && !selected && (!paused || display.playWhilePaused)} {horizontalScroll} layoutMode={display.layout} spanningTiles={display.spanningTiles} tileSize={display.tileSize} gap={display.gap} animateArrivals={display.animateArrivals} onopen={open} onreveal={reveal} /> </div> {#if currentCard && !restricted && moderation} <div class="media-status" aria-busy={loading}> {#if loading}<StatusMessage>Loading media…</StatusMessage>{/if} {#if mediaError}<StatusMessage kind="error">{mediaError}</StatusMessage> <Button type="button" onclick={() => void loadMore()}>Retry media</Button> {:else if started && !items.length && !loading}<StatusMessage>No media to show.</StatusMessage >{/if} {#if !mediaError && started && cursor && scanned < 500}<Button type="button" disabled={loading || paused} aria-busy={loading} onclick={() => void loadMore()}>Load more</Button > {#if paused}<p role="status">Resume the wall to load more.</p>{/if} {/if} {#if scanned >= 500}<p>Showing media from the latest 500 posts.</p>{/if} </div> {/if}</section>{#if selected && !settingsOpen} <MediaViewer {shortcutBindings} {onpostshortcut} profileDid={did} {items} {selected} onclose={() => (selectedId = undefined)} onselect={open} onreveal={reveal} />{/if}
<style> .profile-view { min-width: 0; padding-bottom: calc(var(--space-125) + 5rem); color: var(--color-foreground-primary); background: var(--color-surface-panel); font: var(--font-size-md)/var(--font-line-height-body) var(--font-family-sans); overflow-wrap: anywhere; text-underline-offset: 0.2em; } .profile-view ::selection { background: var(--color-foreground-emphasis); color: var(--color-text-on-accent); } .navigation, .identity-actions, .actions { display: flex; align-items: center; gap: var(--space-075); } .navigation { padding: var(--space-075) var(--space-100); border-bottom: 1px solid var(--color-border-default); } .navigation > span { color: var(--color-text-secondary); } a:focus-visible, summary:focus-visible { outline: 2px solid var(--color-foreground-emphasis); outline-offset: 3px; } .profile-card { display: flow-root; min-width: 0; } .banner { display: block; width: 100%; aspect-ratio: 3 / 1; object-fit: cover; } .identity { padding: var(--space-125) var(--space-100); } .identity-actions { justify-content: space-between; flex-wrap: wrap; } .actions { flex-wrap: wrap; } h1 { margin: var(--space-100) 0 0; font-size: var(--font-size-xl); line-height: 1.2; text-wrap: balance; } a { color: var(--color-foreground-emphasis); } .handle, .pronouns, .source, .media-status { color: var(--color-text-secondary); } .pronouns { margin-block: var(--space-035); } .bio { white-space: pre-wrap; margin-block: var(--space-100); } .links { display: flex; flex-wrap: wrap; gap: var(--space-075); padding: 0; list-style: none; } details { margin-top: var(--space-100); } summary { cursor: pointer; } .source { display: block; font-size: var(--font-size-sm); } .wall { min-width: 0; } .sideways { overflow-x: auto; overflow-y: hidden; scrollbar-color: var(--color-border-input) var(--color-surface-recessed); } .status, .media-status { padding: var(--space-100); } .media-status { text-align: center; }</style>