your personal website on atproto - mirror blento.app
at next 66 lines 2.4 kB view raw
1import { getPostThread } from '$lib/atproto/methods'; 2import type { CardDefinition } from '../types'; 3import GuestbookCard from './GuestbookCard.svelte'; 4import CreateGuestbookCardModal from './CreateGuestbookCardModal.svelte'; 5 6export const GuestbookCardDefinition = { 7 type: 'guestbook', 8 contentComponent: GuestbookCard, 9 creationModalComponent: CreateGuestbookCardModal, 10 createNew: (card) => { 11 card.w = 4; 12 card.h = 6; 13 card.mobileW = 8; 14 card.mobileH = 12; 15 card.cardData.label = 'Guestbook'; 16 }, 17 minW: 4, 18 minH: 4, 19 defaultColor: 'base', 20 canHaveLabel: true, 21 loadData: async (items) => { 22 const uris = items 23 .filter((item) => item.cardData?.uri) 24 .map((item) => item.cardData.uri as string); 25 26 if (uris.length === 0) return {}; 27 28 const results: Record<string, unknown[]> = {}; 29 30 await Promise.all( 31 uris.map(async (uri) => { 32 try { 33 const thread = await getPostThread({ uri, depth: 1 }); 34 if (thread && '$type' in thread && thread.$type === 'app.bsky.feed.defs#threadViewPost') { 35 const typedThread = thread as { replies?: unknown[] }; 36 results[uri] = (typedThread.replies ?? []) 37 .filter( 38 (r: unknown) => 39 r != null && 40 typeof r === 'object' && 41 '$type' in r && 42 (r as { $type: string }).$type === 'app.bsky.feed.defs#threadViewPost' 43 ) 44 .sort((a: unknown, b: unknown) => { 45 const timeA = new Date( 46 ((a as any).post?.record?.createdAt as string) ?? 0 47 ).getTime(); 48 const timeB = new Date( 49 ((b as any).post?.record?.createdAt as string) ?? 0 50 ).getTime(); 51 return timeB - timeA; 52 }); 53 } 54 } catch (e) { 55 console.error('Failed to load guestbook thread for', uri, e); 56 } 57 }) 58 ); 59 60 return results; 61 }, 62 name: 'Guestbook', 63 keywords: ['comments', 'visitors', 'message', 'sign'], 64 groups: ['Social'], 65 icon: `<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" class="size-4"><path stroke-linecap="round" stroke-linejoin="round" d="M12 6.042A8.967 8.967 0 0 0 6 3.75c-1.052 0-2.062.18-3 .512v14.25A8.987 8.987 0 0 1 6 18c2.305 0 4.408.867 6 2.292m0-14.25a8.966 8.966 0 0 1 6-2.292c1.052 0 2.062.18 3 .512v14.25A8.987 8.987 0 0 0 18 18a8.967 8.967 0 0 0-6 2.292m0-14.25v14.25" /></svg>` 66} as CardDefinition & { type: 'guestbook' };