fix more type things

This commit is contained in:
2024-05-13 00:08:11 +02:00
parent 780e2c7fed
commit 794818db13
3 changed files with 14 additions and 10 deletions

View File

@ -20,6 +20,7 @@ export const EventItem = ({
size?: "small" | "medium" | "large";
}) => {
const nextOccurrence = getClosestOccurrence(event);
const numOccurrences = event?.occurrences?.length ?? 0;
return (
<li
@ -42,9 +43,10 @@ export const EventItem = ({
<h1 className={styles.title}>{event.title}</h1>
{mode === "list" && nextOccurrence && (
<p className={styles.details}>
{event.occurrences.length === 1 &&
{numOccurrences === 1 &&
nextOccurrence?.start &&
formatDate(nextOccurrence.start, commonDateFormat)}
{event.occurrences.length > 1 && nextOccurrence && (
{numOccurrences > 1 && nextOccurrence?.start && (
<span>
<em>Neste:</em>{" "}
{formatDate(nextOccurrence.start, commonDateFormat)}
@ -52,7 +54,9 @@ export const EventItem = ({
)}
</p>
)}
{mode === "calendar" && event.occurrence?.start && (
{mode === "calendar" &&
"occurrence" in event &&
event.occurrence?.start && (
<p className={styles.details}>
{formatDate(event.occurrence?.start, "'kl.' HH:mm")}
</p>

View File

@ -6,7 +6,7 @@ export const FeaturedEvents = ({ events }: { events: EventFragment[] }) => {
return (
<ul className={styles.eventList}>
{events.map((event) => (
<EventItem key={event.id} event={event} />
<EventItem key={event.id} event={event} mode="list" />
))}
</ul>
);

View File

@ -95,8 +95,8 @@ function isDefined<T>(val: T | undefined | null): val is T {
interface EventsByDate {
[yearMonth: string]: {
[week: number]: {
[day: number]: SingularEvent[];
[week: string]: {
[day: string]: SingularEvent[];
};
};
}