43 lines
1.1 KiB
TypeScript
43 lines
1.1 KiB
TypeScript
import type { HotelQueryData, NormalizedHotelQueryInput } from "./rooms";
|
|
|
|
export async function loadHotelRadioQuery(
|
|
input: NormalizedHotelQueryInput,
|
|
): Promise<HotelQueryData> {
|
|
if (input.routeId !== "hotel.radio.monitoring") {
|
|
const { loadHotelDatabaseQuery } = await import("./hotel-production");
|
|
return loadHotelDatabaseQuery(input);
|
|
}
|
|
const { fetchListeners, fetchNowPlaying } = await import(
|
|
"@/lib/services/radio"
|
|
);
|
|
const [nowPlaying, listeners] = await Promise.all([
|
|
fetchNowPlaying(),
|
|
fetchListeners(),
|
|
]);
|
|
const items: Array<HotelQueryData["items"][number]> = [];
|
|
if (nowPlaying) {
|
|
items.push({
|
|
id: "now-playing",
|
|
title: nowPlaying.title,
|
|
description: nowPlaying.artist ?? undefined,
|
|
status: "playing",
|
|
href: "/ase/hotel/radio/monitoring",
|
|
});
|
|
}
|
|
if (listeners !== null) {
|
|
items.push({
|
|
id: "listeners",
|
|
title: `${listeners} listeners`,
|
|
status: "live",
|
|
href: "/ase/hotel/radio/monitoring",
|
|
});
|
|
}
|
|
return {
|
|
kind: "radio",
|
|
items,
|
|
total: items.length,
|
|
partialDependencies:
|
|
nowPlaying === null && listeners === null ? ["radio"] : [],
|
|
};
|
|
}
|