diff --git a/src/lib/cards/social/EventCard/CreateEventCardModal.svelte b/src/lib/cards/social/EventCard/CreateEventCardModal.svelte index e4af690..f52769f 100644 --- a/src/lib/cards/social/EventCard/CreateEventCardModal.svelte +++ b/src/lib/cards/social/EventCard/CreateEventCardModal.svelte @@ -2,6 +2,8 @@ import { Alert, Button, Input, Subheading } from '@foxui/core'; import Modal from '$lib/components/modal/Modal.svelte'; import type { CreationModalComponentProps } from '../../types'; + import { getRecord } from '$lib/atproto/methods'; + import type { Did } from '@atcute/lexicons'; const EVENT_COLLECTION = 'community.lexicon.calendar.event'; @@ -38,12 +40,14 @@ throw new Error('Invalid URL format'); } - // Validate the event exists by fetching it - const response = await fetch( - `https://smokesignal.events/xrpc/community.lexicon.calendar.GetEvent?repository=${encodeURIComponent(parsed.did)}&record_key=${encodeURIComponent(parsed.rkey)}` - ); + // Validate the event exists by fetching the record directly + const record = await getRecord({ + did: parsed.did as Did, + collection: EVENT_COLLECTION, + rkey: parsed.rkey + }); - if (!response.ok) { + if (!record?.value) { throw new Error('Event not found'); } @@ -55,7 +59,7 @@ errorMessage = err instanceof Error && err.message === 'Event not found' ? "Couldn't find that event. Please check the URL and try again." - : 'Invalid URL. Please enter a valid smokesignal.events URL or AT URI.'; + : 'Invalid URL. Please enter a valid event AT URI or smokesignal.events URL.'; return false; } finally { isValidating = false; @@ -70,10 +74,10 @@ }} class="flex flex-col gap-2" > - Enter a Smoke Signal event URL + Enter an event URL @@ -82,11 +86,7 @@ {/if}

- Paste a URL from smokesignal.events or an AT URI for a calendar event. + Paste an AT URI for a calendar event or a smokesignal.events URL.

diff --git a/src/lib/cards/social/EventCard/EventCard.svelte b/src/lib/cards/social/EventCard/EventCard.svelte index c1a36e1..481ac7c 100644 --- a/src/lib/cards/social/EventCard/EventCard.svelte +++ b/src/lib/cards/social/EventCard/EventCard.svelte @@ -91,9 +91,8 @@ } let eventUrl = $derived(() => { - if (eventData?.url) return eventData.url; if (parsedUri) { - return `https://smokesignal.events/${parsedUri.repo}/${parsedUri.rkey}`; + return `/${parsedUri.repo}/events/${parsedUri.rkey}`; } return '#'; }); @@ -144,9 +143,7 @@
{#if isMobile() ? item.mobileW > 4 : item.w > 2} - + {/if} @@ -211,51 +208,6 @@ {eventData.description}

{/if} - - {#if (eventData.countGoing !== undefined || eventData.countInterested !== undefined) && ((isMobile() && item.mobileH >= 4) || (!isMobile() && item.h >= 3))} -
- {#if eventData.countGoing !== undefined} -
- - - - {eventData.countGoing} going -
- {/if} - {#if eventData.countInterested !== undefined} -
- - - - {eventData.countInterested} interested -
- {/if} -
- {/if} {#if showImage} @@ -267,16 +219,15 @@ - View event on smokesignal.events + View event {:else if isLoaded}
diff --git a/src/lib/cards/social/EventCard/index.ts b/src/lib/cards/social/EventCard/index.ts index 8d14aa1..9a40278 100644 --- a/src/lib/cards/social/EventCard/index.ts +++ b/src/lib/cards/social/EventCard/index.ts @@ -1,7 +1,8 @@ -import { parseUri } from '$lib/atproto'; +import { parseUri, getRecord } from '$lib/atproto'; import type { CardDefinition } from '../../types'; import CreateEventCardModal from './CreateEventCardModal.svelte'; import EventCard from './EventCard.svelte'; +import type { Did } from '@atcute/lexicons'; const EVENT_COLLECTION = 'community.lexicon.calendar.event'; @@ -39,9 +40,7 @@ export type EventData = { uri: string; name?: string; }>; - countGoing?: number; - countInterested?: number; - url: string; + url?: string; }; export const EventCardDefinition = { @@ -66,13 +65,14 @@ export const EventCardDefinition = { if (!parsedUri || !parsedUri.rkey || !parsedUri.repo) continue; try { - const response = await fetch( - `https://smokesignal.events/xrpc/community.lexicon.calendar.GetEvent?repository=${encodeURIComponent(parsedUri.repo)}&record_key=${encodeURIComponent(parsedUri.rkey)}` - ); + const record = await getRecord({ + did: parsedUri.repo as Did, + collection: EVENT_COLLECTION, + rkey: parsedUri.rkey + }); - if (response.ok) { - const data = await response.json(); - eventDataMap[item.id] = data as EventData; + if (record?.value) { + eventDataMap[item.id] = record.value as EventData; } } catch (error) { console.error('Failed to fetch event data:', error); @@ -118,7 +118,7 @@ export const EventCardDefinition = { name: 'Event', - keywords: ['calendar', 'meetup', 'schedule', 'date', 'rsvp'], + keywords: ['calendar', 'meetup', 'schedule', 'date', 'rsvp', 'smokesignal'], groups: ['Social'], icon: `` } as CardDefinition & { type: 'event' }; diff --git a/src/routes/[[actor=actor]]/e/+page.server.ts b/src/routes/[[actor=actor]]/events/+page.server.ts similarity index 71% rename from src/routes/[[actor=actor]]/e/+page.server.ts rename to src/routes/[[actor=actor]]/events/+page.server.ts index 17bd279..976626e 100644 --- a/src/routes/[[actor=actor]]/e/+page.server.ts +++ b/src/routes/[[actor=actor]]/events/+page.server.ts @@ -1,6 +1,6 @@ import { error } from '@sveltejs/kit'; import type { EventData } from '$lib/cards/social/EventCard'; -import { getBlentoOrBskyProfile } from '$lib/atproto/methods.js'; +import { getBlentoOrBskyProfile, listRecords } from '$lib/atproto/methods.js'; import { createCache, type CachedProfile } from '$lib/cache'; import type { Did } from '@atcute/lexicons'; import { getActor } from '$lib/actor.js'; @@ -15,10 +15,12 @@ export async function load({ params, platform, request }) { } try { - const [eventsResponse, hostProfile] = await Promise.all([ - fetch( - `https://smokesignal.events/xrpc/community.lexicon.calendar.searchEvents?repository=${encodeURIComponent(did)}&query=upcoming` - ), + const [records, hostProfile] = await Promise.all([ + listRecords({ + did: did as Did, + collection: 'community.lexicon.calendar.event', + limit: 100 + }), cache ? cache.getProfile(did as Did).catch(() => null) : getBlentoOrBskyProfile({ did: did as Did }) @@ -35,12 +37,10 @@ export async function load({ params, platform, request }) { .catch(() => null) ]); - if (!eventsResponse.ok) { - throw error(404, 'Events not found'); - } - - const data: { results: EventData[] } = await eventsResponse.json(); - const events = data.results; + const events = records.map((r) => ({ + ...(r.value as EventData), + rkey: r.uri.split('/').pop() as string + })); return { events, diff --git a/src/routes/[[actor=actor]]/e/+page.svelte b/src/routes/[[actor=actor]]/events/+page.svelte similarity index 92% rename from src/routes/[[actor=actor]]/e/+page.svelte rename to src/routes/[[actor=actor]]/events/+page.svelte index 4c78a49..b86e504 100644 --- a/src/routes/[[actor=actor]]/e/+page.svelte +++ b/src/routes/[[actor=actor]]/events/+page.svelte @@ -6,7 +6,7 @@ let { data } = $props(); - let events: EventData[] = $derived(data.events); + let events: (EventData & { rkey: string })[] = $derived(data.events); let did: string = $derived(data.did); let hostProfile = $derived(data.hostProfile); @@ -74,10 +74,6 @@ return { url, alt: media.alt || event.name }; } - function getRkey(event: EventData): string { - return event.url.split('/').pop() || ''; - } - let actorPrefix = $derived(data.hostProfile?.handle ? `/${data.hostProfile.handle}` : `/${did}`); @@ -98,7 +94,7 @@

Upcoming events

-
+ {/each} diff --git a/src/routes/[[actor=actor]]/e/[rkey]/+page.server.ts b/src/routes/[[actor=actor]]/events/[rkey]/+page.server.ts similarity index 64% rename from src/routes/[[actor=actor]]/e/[rkey]/+page.server.ts rename to src/routes/[[actor=actor]]/events/[rkey]/+page.server.ts index a22d26f..463a15e 100644 --- a/src/routes/[[actor=actor]]/e/[rkey]/+page.server.ts +++ b/src/routes/[[actor=actor]]/events/[rkey]/+page.server.ts @@ -1,10 +1,8 @@ import { error } from '@sveltejs/kit'; import type { EventData } from '$lib/cards/social/EventCard'; -import { getBlentoOrBskyProfile, getRecord, resolveHandle } from '$lib/atproto/methods.js'; -import { isHandle } from '@atcute/lexicons/syntax'; +import { getBlentoOrBskyProfile, getRecord } from '$lib/atproto/methods.js'; import { createCache, type CachedProfile } from '$lib/cache'; -import type { ActorIdentifier, Did } from '@atcute/lexicons'; -import { env as publicEnv } from '$env/dynamic/public'; +import type { Did } from '@atcute/lexicons'; import { getActor } from '$lib/actor'; export async function load({ params, platform, request }) { @@ -19,10 +17,12 @@ export async function load({ params, platform, request }) { } try { - const [eventResponse, hostProfile, eventRecord] = await Promise.all([ - fetch( - `https://smokesignal.events/xrpc/community.lexicon.calendar.GetEvent?repository=${encodeURIComponent(did)}&record_key=${encodeURIComponent(rkey)}` - ), + const [eventRecord, hostProfile] = await Promise.all([ + getRecord({ + did: did as Did, + collection: 'community.lexicon.calendar.event', + rkey + }), cache ? cache.getProfile(did as Did).catch(() => null) : getBlentoOrBskyProfile({ did: did as Did }) @@ -36,26 +36,21 @@ export async function load({ params, platform, request }) { url: p.url }) ) - .catch(() => null), - getRecord({ - did: did as Did, - collection: 'community.lexicon.calendar.event', - rkey - }).catch(() => null) + .catch(() => null) ]); - if (!eventResponse.ok) { + if (!eventRecord?.value) { throw error(404, 'Event not found'); } - const eventData: EventData = await eventResponse.json(); + const eventData: EventData = eventRecord.value as EventData; return { eventData, did, rkey, hostProfile: hostProfile ?? null, - eventCid: (eventRecord?.cid as string) ?? null + eventCid: (eventRecord.cid as string) ?? null }; } catch (e) { if (e && typeof e === 'object' && 'status' in e) throw e; diff --git a/src/routes/[[actor=actor]]/e/[rkey]/+page.svelte b/src/routes/[[actor=actor]]/events/[rkey]/+page.svelte similarity index 94% rename from src/routes/[[actor=actor]]/e/[rkey]/+page.svelte rename to src/routes/[[actor=actor]]/events/[rkey]/+page.svelte index 846b62d..2f1ba2a 100644 --- a/src/routes/[[actor=actor]]/e/[rkey]/+page.svelte +++ b/src/routes/[[actor=actor]]/events/[rkey]/+page.svelte @@ -88,7 +88,7 @@ return { url, alt: media.alt || eventData.name }; }); - let eventUrl = $derived(eventData.url || `https://smokesignal.events/${did}/${rkey}`); + let smokesignalUrl = $derived(`https://smokesignal.events/${did}/${rkey}`); let eventUri = $derived(`at://${did}/community.lexicon.calendar.event/${rkey}`); let ogImageUrl = $derived(`${page.url.origin}${page.url.pathname}/og.png`); @@ -247,20 +247,6 @@
- {#if (eventData.countGoing && eventData.countGoing > 0) || (eventData.countInterested && eventData.countInterested > 0)} - -
- {#if eventData.countGoing && eventData.countGoing > 0} -

{eventData.countGoing} Going

- {/if} - {#if eventData.countInterested && eventData.countInterested > 0} -

{eventData.countInterested} Interested

- {/if} -
- {/if} - {#if eventData.uris && eventData.uris.length > 0}
@@ -300,7 +286,7 @@ {dateStr}
-