diff --git a/src/app/favorites/page.tsx b/src/app/favorites/page.tsx index af65af1..ded8fe8 100644 --- a/src/app/favorites/page.tsx +++ b/src/app/favorites/page.tsx @@ -1,8 +1,5 @@ import { EventList } from "@/components/EventList"; import { ShowElapsedSwitch } from "@/components/ShowElapsedSwitch"; -import { Button } from "@/components/ui/button"; -import { Label } from "@/components/ui/label"; -import { Switch } from "@/components/ui/switch"; import { getEventsByIds } from "@/db"; import { cookies } from "next/headers"; diff --git a/src/app/now/page.tsx b/src/app/now/page.tsx new file mode 100644 index 0000000..853f79b --- /dev/null +++ b/src/app/now/page.tsx @@ -0,0 +1,30 @@ +import { groupEventsByStartTime } from "@/common/utils"; +import { EventList } from "@/components/EventList"; +import { getNowEvents } from "@/db"; + +export default async function FavoritesPage() { + const nowEvents = await getNowEvents(); + const groupedEvents = groupEventsByStartTime(nowEvents); + + return ( +
+
+

Kam jít?

+
+
+ {groupedEvents.map(({events, startTime}) => ( +
+

+ Od {new Date(startTime).toLocaleTimeString("cs-CZ", { + hour: "2-digit", + minute: "2-digit", + hour12: false, + })} +

+ +
+ ))} +
+
+ ); +} diff --git a/src/app/page.tsx b/src/app/page.tsx index 80e4f3a..a54a6ac 100644 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -29,6 +29,13 @@ export default async function Home({ searchParams }: HomePageProps) { +

Dny

diff --git a/src/common/utils.ts b/src/common/utils.ts index b2683ca..a25aaed 100644 --- a/src/common/utils.ts +++ b/src/common/utils.ts @@ -53,6 +53,21 @@ export function groupEventsByLine(events: Event[]) { })); } +export function groupEventsByStartTime(events: Event[]) { + const grouped: Record = {}; + for (const event of events) { + const startTime = new Date(event.startTime).toISOString(); + if (!grouped[startTime]) { + grouped[startTime] = []; + } + grouped[startTime].push(event); + } + return Object.entries(grouped).map(([startTime, events]) => ({ + startTime: new Date(startTime), + events, + })); +} + export async function isEventFavorite(eventId: number): Promise { const cookieStore = await cookies(); const favorites = cookieStore.get("favorites")?.value || "[]"; diff --git a/src/components/app-sidebar.tsx b/src/components/app-sidebar.tsx index aecda40..cc11fab 100644 --- a/src/components/app-sidebar.tsx +++ b/src/components/app-sidebar.tsx @@ -1,5 +1,5 @@ import * as React from "react"; -import { ChevronRight } from "lucide-react"; +import { ChevronRight, LoaderIcon } from "lucide-react"; import { SearchForm } from "@/components/search-form"; import { @@ -71,6 +71,11 @@ export async function AppSidebar({ Rozcestník + + + Kam jít? + + Oblíbené diff --git a/src/db/index.ts b/src/db/index.ts index 6c4e9b6..233cfac 100644 --- a/src/db/index.ts +++ b/src/db/index.ts @@ -156,3 +156,23 @@ export async function searchEvents(query: string) { ) .orderBy(eventsTable.startTime, eventsTable.endTime); } + +export async function getNowEvents() { + if (process.env.IS_DOCKER_BUILD === "true") { + return []; // Skip fetching now events during Docker build + } + const now = new Date(); + return db + .select() + .from(eventsTable) + .where( + and( + gte(eventsTable.startTime, now), + lte( + eventsTable.startTime, + new Date(now.getTime() + 2 * 60 * 60 * 1000), + ), + ), + ) + .orderBy(eventsTable.startTime, eventsTable.endTime); +}