/* 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 } from "react"; import { useParams } from "react-router-dom"; import { Alignment, Button, Breadcrumbs, Navbar, NonIdealState } from "@blueprintjs/core"; import { DateTime } from "luxon"; import { getGlobalServiceId, getIdWithHex } from "../modules/common"; import { state } from "../modules/state"; import * as ui from "../modules/ui"; import * as regexp from "../modules/regexp"; import { clearSchedule, setSchedule } from "../modules/at"; import { Error, Program } from "../../../api.d"; import { ProgramTitle } from "../components/ProgramTitle"; import { WatchButton } from "../components/WatchButton"; import { DateTimeRange } from "../components/DateTimeRange"; import { ServiceLink } from "../components/ServiceLink"; import { ProgramGenres } from "../components/ProgramGenres"; import { ProgramAVInfo } from "../components/ProgramAVInfo"; import { ProgramRelatedLinks } from "../components/ProgramRelatedLinks"; import "./ProgramView.sass"; export const ProgramView: React.FC = () => { console.debug("routes", "ProgramView"); const [reload, setReload] = useState(Date.now()); // リロード用 const [error, setError] = useState(null); const [program, setProgram] = useState(null); const { navigate } = state; const params = useParams(); const programId = parseInt(params.programId, 10); const now = Date.now(); const startTime = program?.startAt; const endTime = program ? program.startAt + program.duration : null; const isLoading = program === null && error === null; const isOnAir = program && startTime <= now && endTime >= now; const date = program && DateTime.fromMillis(program.startAt).set({ hour: 0, minute: 0, second: 0, millisecond: 0 }); const time = program && DateTime.fromMillis(program.startAt).diff(date).toMillis(); const timeForServiceLink = (time > (1000 * 60 * 60 * 24 - 1000 * 60 * 5)) ? 1 : time; useEffect(() => { const onPrograms = (programs: Program[]) => { const _program = programs.find(p => p.id === programId); if (!_program) { setError({ code: 404, reason: "番組が見つかりません", }); setProgram(null); return; } setError(null); setProgram(_program); }; state.on("programs", onPrograms); state.subscribePrograms(true); return () => { // // unsubscribe せずに差分更新を継続する // state.unsubscribePrograms(); state.off("programs", onPrograms); } }, [programId]); useEffect(() => { if (!program) { ui.setTitle("番組詳細...", true); return; } ui.setTitle(program.name); const schedules: ReturnType[] = []; if (now <= startTime) { schedules.push(setSchedule(startTime, () => setReload(Date.now()))); } if (now <= endTime) { schedules.push(setSchedule(endTime, () => setReload(Date.now()))); } console.debug("ProgramView", program); return () => { for (const id of schedules) { clearSchedule(id); } }; }, [program]); return (
{ navigate(`/epg?date=${date.toISODate()}&time=${time}`) } }, { className: isLoading ? "bp5-skeleton" : "", text: isLoading ? "Loading................................." : (error ? "エラー" : ( program ? : <> )) } ]} /> {isLoading && <>
); };