your personal website on atproto - mirror blento.app
at timer-card-tiny-fix 67 lines 2.0 kB view raw
1import type { CardDefinition } from '../types'; 2import BlueskyPostCard from './BlueskyPostCard.svelte'; 3import CreateBlueskyPostCardModal from './CreateBlueskyPostCardModal.svelte'; 4import { getPosts } from '$lib/atproto/methods'; 5import type { PostView } from '@atcute/bluesky/types/app/feed/defs'; 6import { parseBlueskyPostUrl, resolveUri } from './utils'; 7 8export const BlueskyPostCardDefinition = { 9 type: 'blueskyPost', 10 contentComponent: BlueskyPostCard, 11 creationModalComponent: CreateBlueskyPostCardModal, 12 sidebarButtonText: 'Bluesky Post', 13 createNew: (card) => { 14 card.cardType = 'blueskyPost'; 15 card.w = 4; 16 card.mobileW = 8; 17 card.h = 4; 18 card.mobileH = 8; 19 }, 20 21 onUrlHandler: (url, item) => { 22 const parsed = parseBlueskyPostUrl(url); 23 if (!parsed) return null; 24 25 // Construct AT URI using handle (will be resolved to DID when loading) 26 item.cardData.uri = `at://${parsed.handle}/app.bsky.feed.post/${parsed.rkey}`; 27 item.cardData.href = url; 28 29 item.w = 4; 30 item.mobileW = 8; 31 item.h = 4; 32 item.mobileH = 8; 33 34 return item; 35 }, 36 urlHandlerPriority: 2, 37 38 loadData: async (items) => { 39 // Collect all unique URIs from blueskyPost cards 40 const originalUris = items 41 .filter((item) => item.cardData?.uri) 42 .map((item) => item.cardData.uri as string); 43 44 if (originalUris.length === 0) return {}; 45 46 // Resolve handles to DIDs 47 const resolvedUris = await Promise.all(originalUris.map(resolveUri)); 48 49 const posts = await getPosts({ uris: resolvedUris }); 50 if (!posts) return {}; 51 52 // Create a map of URI -> PostView (keyed by both original and resolved URIs) 53 const postsMap: Record<string, PostView> = {}; 54 for (let i = 0; i < posts.length; i++) { 55 const post = posts[i]; 56 postsMap[post.uri] = post; 57 // Also map by original URI for lookup 58 if (originalUris[i] && originalUris[i] !== post.uri) { 59 postsMap[originalUris[i]] = post; 60 } 61 } 62 63 return postsMap; 64 }, 65 minW: 4, 66 name: 'Bluesky Post' 67} as CardDefinition & { type: 'blueskyPost' };