/* * Copyright (C) 2024 Aleksander WilczyƄski (aleks@alekswilc.dev) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published * by the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * See LICENSE for more. */ import { useParams } from "react-router-dom"; import { ContentLoader, LoadError } from "../../components/mini/loaders/ContentLoader.tsx"; import { WarningAlert } from "../../components/mini/alerts/Warning.tsx"; import { useTranslation } from "react-i18next"; import { StationLog } from "../../components/pages/log/StationLog.tsx"; import { TrainLog } from "../../components/pages/log/TrainLog.tsx"; import { PageMeta } from "../../components/mini/util/PageMeta.tsx"; import { get } from "../../util/fetcher.ts"; import useSWR from "swr"; export const Log = () => { const { id } = useParams(); const { data, error, isLoading } = useSWR(`/log/${ id }`, get, { refreshInterval: 30_000, errorRetryCount: 5 }); const { t } = useTranslation(); return ( <> {/* ERROR */ } { error && } {/* LOADING */ } { isLoading && } {/* NOT FOUND */ } { data && data.code === 404 && } { data && data.code === 404 && } {/* BLACKLISTED LOG */ } { data && data.code === 403 && } { data && data.code === 403 && } {/* SUCCESS */ } { data && data.code === 200 && !("trainNumber" in data.data) && } { data && data.code === 200 && !("trainNumber" in data.data) && data.data && < StationLog data={ data.data }/> } { data && data.code === 200 && ("trainNumber" in data.data) && } { data && data.code === 200 && ("trainNumber" in data.data) && < TrainLog data={ data.data }/> } ); };