-
Notifications
You must be signed in to change notification settings - Fork 210
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
191 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
import {Memorize, shortTermCache} from "../cache.js"; | ||
import type { ContentData, ServiceInterface, ServiceMetadata } from "./abstract.js"; | ||
|
||
export const TYPE = "guild-event" as const; | ||
|
||
export class GuildEventService implements ServiceInterface<{ cover: string, startAt: string, venue?: [number, number] }> { | ||
canHandle(metadata: ServiceMetadata): Promise<boolean> { | ||
return Promise.resolve(metadata.type === TYPE); | ||
} | ||
async getInformation(metadata: ServiceMetadata): Promise<(ContentData & { cover: string, startAt: string, venue?: [number, number] }) | never> { | ||
const event = (await this.getGuildEvents('svelte-society')).events.edges.find(event => event.node.id === metadata.identifier) | ||
|
||
if (event) { | ||
return { | ||
type: TYPE, | ||
cover: event.node.uploadedSocialCard?.url ?? event.node.generatedSocialCardURL, | ||
keywords: [], | ||
url: `http://guild.host/events/${event.node.prettyUrl}`, | ||
author: event.node.owner.name, | ||
venue: event.node.hasVenue && event.node.venue?.address.location !== null ? event.node.venue?.address.location.geojson.coordinates : undefined, | ||
description: event.node.description, | ||
name: event.node.name, | ||
startAt: event.node.startAt | ||
} | ||
} | ||
|
||
return this.getOneEvent(metadata.identifier).then(response => ({ | ||
type: TYPE, | ||
cover: response.uploadedSocialCard?.url ?? response.generatedSocialCardURL, | ||
keywords: [], | ||
url: `http://guild.host/events/${response.prettyUrl}`, | ||
author: response.owner.name, | ||
venue: response.hasVenue && response.venue?.address.location !== null ? response.venue?.address.location.geojson.coordinates : undefined, | ||
description: response.description, | ||
name: response.name, | ||
startAt: response.startAt | ||
})) | ||
} | ||
|
||
@Memorize(shortTermCache) | ||
private getGuildEvents(id: string): Promise<GuildHostGuildEventsResponse> { | ||
return fetch(`https://guild.host/api/next/${id}/events`).then(response => response.json()) | ||
} | ||
|
||
@Memorize(shortTermCache) | ||
private getOneEvent(id: string): Promise<GuildHostEventResponse> { | ||
return fetch(`https://guild.host/api/next/node/${id}`).then(response => response.json()) | ||
} | ||
|
||
async getAllServiceMetadata(): Promise<Array<ServiceMetadata>> { | ||
return this.getGuildEvents('svelte-society').then(response => response.events.edges.map(event => ({ | ||
type: TYPE, | ||
identifier: event.node.id | ||
}))) | ||
} | ||
} | ||
|
||
type GuildHostGuildEventsResponse = { | ||
"__typename": "Guild", "events": { | ||
"edges": Array<{ | ||
"node": GuildHostEventResponse, | ||
"cursor": string | ||
}>, | ||
"pageInfo": { | ||
"hasPreviousPage": boolean, | ||
"hasNextPage": boolean, | ||
"startCursor": string, | ||
"endCursor": string | ||
} | ||
}, "__isNode": "Guild", "id": string | ||
}; | ||
|
||
type GuildHostEventResponse = { | ||
"__typename"?: "Event", | ||
"id": string, | ||
"slug": string, | ||
"prettyUrl": string, | ||
"name": string, | ||
"description": string, | ||
"startAt": string, | ||
"endAt": string, | ||
"timeZone": string, | ||
"visibility": "PUBLIC", | ||
"hasVenue": boolean, | ||
"hasExternalUrl": boolean, | ||
"owner": { | ||
"__typename": "Guild", | ||
"id": string, | ||
"name": string, | ||
"__isNode": "Guild" | ||
}, | ||
"uploadedSocialCard": null | { | ||
"url": string, | ||
"id": string | ||
}, | ||
"generatedSocialCardURL": string, | ||
"presentations": { "edges": [] }, | ||
"venue": null | { | ||
"address": { | ||
"location": null | { | ||
"__typename": "GeometryPoint", | ||
"geojson": { "type": "Point", "coordinates": [number, number] } | ||
}, | ||
"id": string | ||
}, | ||
"id": string | ||
}, | ||
"createdAt": string, | ||
"updatedAt": string | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<script lang="ts"> | ||
import Content from '../ContentCard.svelte'; | ||
let { | ||
id, | ||
children, | ||
cover, | ||
startAt, | ||
venue, | ||
title, | ||
...props | ||
}: { | ||
id: string; | ||
children: unknown; | ||
cover: undefined | string; | ||
startAt: string; | ||
venue: undefined | [number, number]; | ||
title: string; | ||
} = $props(); | ||
</script> | ||
|
||
<Content | ||
{...props} | ||
time={startAt} | ||
tags={[{ id: venue ? 'physical' : 'online', name: venue ? 'Physical' : 'Online' }]} | ||
{title} | ||
type="Event" | ||
> | ||
{#if cover} | ||
<figure> | ||
<img src={cover} alt={title} /> | ||
</figure> | ||
{/if} | ||
{#if Array.isArray(venue)} | ||
<section> | ||
<iframe | ||
title="Venue address" | ||
frameborder="0" | ||
src="https://www.google.com/maps/embed/v1/place?q={venue[1]},{venue[0]}&key=AIzaSyBFw0Qbyq9zTFTd-tUY6dZWTgaQzuU17R8" | ||
></iframe> | ||
</section> | ||
{/if} | ||
</Content> | ||
|
||
<style> | ||
figure { | ||
margin: 0; | ||
padding: 0; | ||
} | ||
figure img { | ||
width: 100%; | ||
border-radius: 8px; | ||
} | ||
iframe { | ||
max-width: 100%; | ||
overflow: hidden; | ||
aspect-ratio: 3/1; | ||
width: 100%; | ||
border: 0; | ||
border-radius: 8px; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters