Skip to content

Commit

Permalink
feat: show my bookings on music room page in green color
Browse files Browse the repository at this point in the history
  • Loading branch information
ArtemSBulgakov committed Feb 17, 2024
1 parent 884e5e7 commit fd1aa90
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 5 deletions.
8 changes: 7 additions & 1 deletion app/music-room/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,13 @@ export default function Page() {
<h2 className="my-4 text-3xl font-medium">Booking calendar</h2>
<div className="lg:-mx-8">
<Calendar
urls={[`${EVENTS_API_URL}/music-room.ics`]}
urls={[
`${EVENTS_API_URL}/music-room.ics`,
{
url: `${EVENTS_API_URL}/users/me/music-room.ics`,
color: "seagreen",
},
]}
initialView="timeGridWeek"
viewId="music-room"
/>
Expand Down
25 changes: 22 additions & 3 deletions components/common/calendar/Calendar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,20 @@ import { useEffect, useMemo, useState } from "react";
import { useLocalStorage } from "usehooks-ts";
import iCalendarPlugin from "./iCalendarPlugin";

export type URLType =
| string
| {
url: string;
color?: string;
};

function Calendar({
urls,
initialView = "listMonth",
viewId = "",
...props
}: {
urls: string[];
urls: URLType[];
initialView?: string;
viewId?: string;
}) {
Expand All @@ -39,13 +46,25 @@ function Calendar({
const calendar = useMemo(
() => (
<FullCalendar
eventSources={urls.map((url) => ({ url: url, format: "ics" }))} // Load events by url
eventSources={urls.map((url) =>
typeof url === "string"
? {
url: url,
format: "ics",
}
: {
url: url.url,
format: "ics",
color: url.color,
},
)} // Load events by url
eventsSet={(events) => {
// Remove duplicates.
// Accumulate 'extendedProps.calendarURLs' to use it later.
const unique: Record<string, EventApi> = {};
for (const event of events) {
const uniqueId = event.title + event.startStr + event.endStr;
const uniqueId =
event.id || event.title + event.startStr + event.endStr;
if (!(uniqueId in unique)) {
unique[uniqueId] = event;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ interface ICalFeedMeta {
url: string;
format: "ics"; // for EventSourceApi
internalState?: InternalState; // HACK. TODO: use classes in future
color: string; // Default color for events from this feed
}

interface InternalState {
Expand All @@ -26,6 +27,7 @@ export const eventSourceDef: EventSourceDef<ICalFeedMeta> = {
return {
url: refined.url,
format: "ics",
color: refined.color,
};
}
return null;
Expand Down Expand Up @@ -118,7 +120,7 @@ function buildNonDateProps(
id: iCalEvent.uid,
title: iCalEvent.summary,
url: extractEventUrl(iCalEvent),
color: iCalEvent.color,
color: iCalEvent.color || meta.color,
extendedProps: {
location: iCalEvent.location,
organizer: iCalEvent.organizer,
Expand Down

0 comments on commit fd1aa90

Please sign in to comment.