/* Copyright 2026 kanreisa Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ import * as React from "react"; import { useState, useEffect, useMemo } from "react"; import { useParams } from "react-router-dom"; import { Alignment, Button, Navbar, Tabs, Tab, HTMLSelect, Breadcrumbs } from "@blueprintjs/core"; import { DateTime } from "luxon"; import { state } from "../modules/state"; import * as ui from "../modules/ui"; import { useLocalStorageState } from "../hooks/useWebStorageState"; import { ChannelType } from "../../../api"; import { WatchButton } from "../components/WatchButton"; import { EPGTable } from "../components/EPGTable"; export const EPGView: React.FC = () => { console.debug("routes", "EPG"); const params = useParams(); const { navigate, searchParams } = state; const [channelType, setChannelType] = useLocalStorageState("EPG.channelType", "GR"); const [programId, setProgramId] = useState(null); const [time, setTime] = useState(null); const globalServiceId = parseInt(params.globalServiceId, 10) || null; const programIdQuery = searchParams.get("programId"); const typeQuery = searchParams.get("type"); const dateQuery = searchParams.get("date"); const timeQuery = searchParams.get("time"); const now = DateTime.now(); const isoDate = /^\d{4}-\d{2}-\d{2}$/.test(dateQuery) ? dateQuery : now.toISODate(); const startDate = now.startOf("day"); const endDate = startDate.plus({ days: 7 }); let date = DateTime.fromISO(isoDate); if (globalServiceId) { date = date.set({ day: now.day }); } if (typeQuery) { if (typeQuery === "ALL") { if (channelType !== null) { setChannelType(null); return; } } else if (typeQuery !== channelType) { setChannelType(typeQuery as ChannelType); return; } } else if (!globalServiceId && !programIdQuery && !timeQuery) { let to = `?type=${channelType || "ALL"}&date=${isoDate}`; setTimeout(() => navigate(to, { replace: true }), 0); return; } let hasRemovedTempParams = false; if (programIdQuery) { setProgramId(parseInt(programIdQuery, 10)); searchParams.delete("programId"); hasRemovedTempParams = true; } if (timeQuery) { setTime(parseInt(timeQuery, 10)); searchParams.delete("time"); hasRemovedTempParams = true; } if (hasRemovedTempParams) { setTimeout(() => navigate(`?${searchParams.toString()}`, { replace: true }), 0); return; } if (!globalServiceId) { ui.setTitle("EPG"); } const toolbarTabs: JSX.Element[] = []; if (date >= startDate && date <= endDate && !globalServiceId) { for (let i = 0; i <= 7; i++) { const cur = startDate.plus({ days: i }); const id = `epg-toolbar-tabs-item-${cur.toISODate()}`; const d = i === 0 ? cur.toFormat("M/d") : cur.toFormat("d"); const c = cur.toFormat("ccc"); toolbarTabs.push({d}{c}} />); } } else { const id = `epg-toolbar-tabs-item-${date.toISODate()}`; const title = date.toFormat("yyyy/MM/dd(ccc)"); toolbarTabs.push(); } const showTodayButton = (!globalServiceId && toolbarTabs.length === 1) || (globalServiceId && date.toMillis() !== startDate.toMillis()); return (
{globalServiceId ? { let to = `/epg?type=${channelType || ""}`; if (isoDate) { to += `&date=${isoDate}`; } if (time) { to += `&time=${time}`; } navigate(to) } }, { text: "週間" }, { text: "放送サービス...", className: "heading-title bp5-skeleton" } ]} /> : "EPG 番組表" } {globalServiceId && ( <> )} {!globalServiceId && ( <> {showTodayButton && (
); };