your personal website on atproto - mirror blento.app
at remove-extra-buttons 120 lines 3.2 kB view raw
1import { parseUri } from '$lib/atproto'; 2import type { CardDefinition } from '../types'; 3import CreateEventCardModal from './CreateEventCardModal.svelte'; 4import EventCard from './EventCard.svelte'; 5 6const EVENT_COLLECTION = 'community.lexicon.calendar.event'; 7 8export type EventData = { 9 mode: string; 10 name: string; 11 status: string; 12 startsAt: string; 13 endsAt?: string; 14 description?: string; 15 locations?: Array<{ 16 address?: { 17 locality?: string; 18 region?: string; 19 country?: string; 20 }; 21 }>; 22 media?: Array<{ 23 alt?: string; 24 role?: string; 25 content?: { 26 ref?: { 27 $link: string; 28 }; 29 mimeType?: string; 30 }; 31 aspect_ratio?: { 32 width: number; 33 height: number; 34 }; 35 }>; 36 countGoing?: number; 37 countInterested?: number; 38 url: string; 39}; 40 41export const EventCardDefinition = { 42 type: 'event', 43 contentComponent: EventCard, 44 creationModalComponent: CreateEventCardModal, 45 sidebarButtonText: 'Event', 46 47 createNew: (card) => { 48 card.w = 4; 49 card.h = 4; 50 card.mobileW = 8; 51 card.mobileH = 6; 52 }, 53 54 loadData: async (items) => { 55 const eventDataMap: Record<string, EventData> = {}; 56 57 for (const item of items) { 58 const uri = item.cardData?.uri; 59 if (!uri) continue; 60 61 const parsedUri = parseUri(uri); 62 if (!parsedUri || !parsedUri.rkey || !parsedUri.repo) continue; 63 64 try { 65 const response = await fetch( 66 `https://smokesignal.events/xrpc/community.lexicon.calendar.GetEvent?repository=${encodeURIComponent(parsedUri.repo)}&record_key=${encodeURIComponent(parsedUri.rkey)}` 67 ); 68 69 if (response.ok) { 70 const data = await response.json(); 71 eventDataMap[item.id] = data as EventData; 72 } 73 } catch (error) { 74 console.error('Failed to fetch event data:', error); 75 } 76 } 77 78 return eventDataMap; 79 }, 80 81 onUrlHandler: (url, item) => { 82 // Match smokesignal.events URLs: https://smokesignal.events/{did}/{rkey} 83 const smokesignalMatch = url.match(/^https?:\/\/smokesignal\.events\/(did:[^/]+)\/([^/?#]+)/); 84 if (smokesignalMatch) { 85 const [, did, rkey] = smokesignalMatch; 86 item.w = 4; 87 item.h = 4; 88 item.mobileW = 8; 89 item.mobileH = 6; 90 item.cardType = 'event'; 91 item.cardData.uri = `at://${did}/${EVENT_COLLECTION}/${rkey}`; 92 return item; 93 } 94 95 // Match AT URIs: at://{did}/community.lexicon.calendar.event/{rkey} 96 const atUriMatch = url.match(/^at:\/\/(did:[^/]+)\/([^/]+)\/([^/?#]+)/); 97 if (atUriMatch) { 98 const [, did, collection, rkey] = atUriMatch; 99 if (collection === EVENT_COLLECTION) { 100 item.w = 4; 101 item.h = 4; 102 item.mobileW = 8; 103 item.mobileH = 6; 104 item.cardType = 'event'; 105 item.cardData.uri = `at://${did}/${collection}/${rkey}`; 106 return item; 107 } 108 } 109 110 return null; 111 }, 112 113 urlHandlerPriority: 5, 114 115 name: 'Event', 116 117 groups: ['Social'], 118 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="M6.75 3v2.25M17.25 3v2.25M3 18.75V7.5a2.25 2.25 0 0 1 2.25-2.25h13.5A2.25 2.25 0 0 1 21 7.5v11.25m-18 0A2.25 2.25 0 0 0 5.25 21h13.5A2.25 2.25 0 0 0 21 18.75m-18 0v-7.5A2.25 2.25 0 0 1 5.25 9h13.5A2.25 2.25 0 0 1 21 11.25v7.5" /></svg>` 119 120} as CardDefinition & { type: 'event' };