Events
Event Records in Algolia
Section titled “Event Records in Algolia”When an Event is published or updated in Sanity, the system fetches type-specific fields in addition to the general variables. Events have unique fields for multi-day scheduling, sponsor logos, and timestamp-based sorting.
Source file: algolia/custom_actions/types/getResourcesData.js
Type-Specific Fields
Section titled “Type-Specific Fields”| Field | Source | Description |
|---|---|---|
date | props.draft?.date | Event start date |
date_timestamp | Computed from date | Unix timestamp for date-based sorting |
is_multiday | props.draft?.is_multiday | Whether the event spans multiple days |
end_date | props.draft?.end_date | End date (only if is_multiday is true) |
regions_slug | fetchEvents() | Event region slugs (uses fetchEvents, not fetchTaxRepeaterSlug) |
image | GROQ query | Event featured image from attributes |
typeName | GROQ query on event_types | Localized event type display name |
organizers | Set to false | Events don’t have author-style organizers |
logos | GROQ query on repeater | Sponsor/partner logos with titles |
How It Works
Section titled “How It Works”Logos (Instead of Organizers)
Section titled “Logos (Instead of Organizers)”Events display sponsor/partner logos instead of author organizers. The logos are fetched from the repeater field:
for (let i = 0; i < props.draft?.repeater?.length; i++) { let id = props.draft?._id?.replace(/^drafts\./, '')
var queryAuthor = `*[_type == "events" && (_id == "${id}" || _id == "${props.draft?._id}")][0]{ 'images': repeater[]{'image': asset_type.image.asset->url, 'title': title} }`
await client.fetch(queryAuthor).then((author) => { organizers = false logos = author?.images })}Date & Timestamp
Section titled “Date & Timestamp”A Unix timestamp is computed for sorting purposes:
date = props.draft?.date;date_timestamp = Math.floor(new Date(date).getTime() / 1000)Multi-Day Events
Section titled “Multi-Day Events”If the event spans multiple days, the end date is also stored:
is_multiday = props.draft?.is_multidayif (is_multiday) { end_date = props.draft?.end_date}Region Slugs
Section titled “Region Slugs”Events use a different fetch method for regions than other resource types:
regions_slug = await fetchEvents('region', 'events_regions_tax', props, client)This uses fetchEvents() instead of the standard fetchTaxRepeaterSlug() used by other types.
Featured Image
Section titled “Featured Image”var queryImage = `*[_type == "events" && (_id == "drafts.${id}" || _id == "${id}")][0]{ 'image': attributes.asset_type.image.asset->url,}`
await client.fetch(queryImage).then((imageUrl) => { image = imageUrl?.image})Event Type Name
Section titled “Event Type Name”var queryTypeName = `*[_type == 'event_types' && _id == "${props.draft?.reference._ref}"][0].title`typeName = await client.fetch(queryTypeName)