Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Recent News and Events Entity relationships to TopTier and ServiceEntry #573

Merged
merged 11 commits into from
Oct 16, 2024
Original file line number Diff line number Diff line change
@@ -1,21 +1,36 @@
<script lang="ts">
import type { PageServerData } from "./$types";
import DateComponent from "$lib/components/Date";
import Link from "$lib/components/Link";
import {
headingTagByLevel,
type HeadingLevel,
} from "$lib/components/ContentfulRichText/headings";

export let event: PageServerData["events"][number];
interface EventData {
__typename?: "EventEntry";
slug?: string | null;
shortTitle?: string | null;
eventDescription?: string | null;
eventDateAndTime?: Date | string | null;
eventSummary?: string | null;
sys: {
__typename?: "Sys";
id: string;
};
}

export let event: NonNullable<EventData>;
export let headingLevel: HeadingLevel = 2;
export let variation: "big" | "small" = "big";
$: date = event?.eventDateAndTime ? new Date(event?.eventDateAndTime) : undefined;

const dateString = event?.eventDateAndTime as string;

$: date = event?.eventDateAndTime ? new Date(dateString) : undefined;
</script>

<div class="event">
{#if event?.eventDateAndTime}
<DateComponent dateString={event.eventDateAndTime} {variation} />
<DateComponent {dateString} {variation} />
{/if}
<div class="event-details">
{#if event?.shortTitle}
Expand Down
1 change: 1 addition & 0 deletions src/lib/components/Event/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from "./Event.svelte";
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,28 @@
} from "$lib/components/ContentfulRichText/headings";
import { getDateStringFromUTCDate } from "$lib/util/dates";

import type { PageServerData } from "./$types";

type NewsEntry = {
__typename?: "News";
type?: string | null;
title?: string | null;
subhead?: string | null;
publicationDate?: Date | string | null;
slug?: string | null;
byline?: string | null;
sys: {
__typename?: "Sys";
id: string;
};
};
type NewsSnippetVariation = "default" | "homepage-featured" | "homepage-listed";

export let entry: NonNullable<PageServerData["newsEntries"][number]>;
export let entry: NonNullable<NewsEntry>;
export let headingLevel: HeadingLevel = 2;
export let variation: NewsSnippetVariation = "default";

$: ({ slug, title, subhead, byline, type, publicationDate } = entry);

$: dateString = getDateStringFromUTCDate(publicationDate);
$: dateString = getDateStringFromUTCDate(publicationDate as string);

$: isArticle = type === "News article";
</script>
Expand Down
1 change: 1 addition & 0 deletions src/lib/components/NewsEntry/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from "./NewsEntry.svelte";
25 changes: 25 additions & 0 deletions src/lib/fragments/entryProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
// break this up into separate fragments for those different situations.
// It will both simplify queries and make what's requested more explicit.
import gql from "graphql-tag";
import assetProps from "$lib/fragments/assetProps";

export default gql`
${assetProps}
fragment EntryProps on Entry {
__typename
sys {
Expand Down Expand Up @@ -54,5 +57,27 @@ export default gql`
}
}
}

... on EventEntry {
sys {
id
}
slug
shortTitle
eventDescription
eventDateAndTime
}

... on News {
sys {
id
}
type
title
subhead
publicationDate
slug
byline
}
}
`;
Loading
Loading