Skip to content

Commit

Permalink
fix: service block page
Browse files Browse the repository at this point in the history
  • Loading branch information
hamster1963 committed Dec 3, 2024
1 parent eb6612e commit 3f87876
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 9 deletions.
2 changes: 2 additions & 0 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import Footer from "./components/Footer";
import Server from "./pages/Server";
import ServerDetail from "./pages/ServerDetail";
import NotFound from "./pages/NotFound";
import ErrorPage from "./pages/ErrorPage";

const App: React.FC = () => {
return (
Expand All @@ -15,6 +16,7 @@ const App: React.FC = () => {
<Routes>
<Route path="/" element={<Server />} />
<Route path="/server/:id" element={<ServerDetail />} />
<Route path="/error" element={<ErrorPage />} />
<Route path="*" element={<NotFound />} />
</Routes>
<Footer />
Expand Down
22 changes: 14 additions & 8 deletions src/components/CycleTransferStats.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,20 @@ export const CycleTransferStatsCard: React.FC<CycleTransferStatsProps> = ({
return (
<section className="grid grid-cols-1 md:grid-cols-2 gap-2 md:gap-4">
{Object.entries(cycleStats).map(([cycleId, cycleData]) => {
const serverStats = Object.entries(cycleData.server_name).map(
([serverId, serverName]) => ({
serverId,
serverName,
transfer: cycleData.transfer[serverId] || 0,
nextUpdate: cycleData.next_update[serverId],
}),
);
const serverStats = cycleData.server_name
? Object.entries(cycleData.server_name).map(
([serverId, serverName]) => ({
serverId,
serverName,
transfer: cycleData.transfer?.[serverId] || 0,
nextUpdate: cycleData.next_update?.[serverId],
})
)
: [];

if (serverStats.length === 0) {
return null;
}

return (
<CycleTransferStatsClient
Expand Down
2 changes: 1 addition & 1 deletion src/components/ServiceTracker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export const ServiceTracker: React.FC = () => {
/>
</div>
)}
{serviceData.data.services && (
{serviceData.data.services && Object.keys(serviceData.data.services).length > 0 && (
<section className="grid grid-cols-1 md:grid-cols-2 mt-4 gap-2 md:gap-4">
{Object.entries(serviceData.data.services).map(([name, data]) => {
const { days, uptime, avgDelay } = processServiceData(data);
Expand Down
32 changes: 32 additions & 0 deletions src/pages/ErrorPage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { Button } from "@/components/ui/button";
import { useNavigate } from "react-router-dom";
import { useTranslation } from "react-i18next";

interface ErrorPageProps {
code?: string | number;
message?: string;
}

export default function ErrorPage({ code = "500", message }: ErrorPageProps) {
const navigate = useNavigate();
const { t } = useTranslation();

return (
<div className="flex flex-col items-center justify-center">
<div className="flex flex-col items-center gap-2">
<h1 className="text-4xl font-semibold">{code}</h1>
<p className="text-xl text-muted-foreground">
{message || t("error.somethingWentWrong")}
</p>
<div className="flex gap-2">
<Button onClick={() => window.location.reload()} variant="outline">
{t("error.tryAgain")}
</Button>
<Button onClick={() => navigate("/")} className="mt-2">
{t("error.backToHome")}
</Button>
</div>
</div>
</div>
);
}

0 comments on commit 3f87876

Please sign in to comment.