diff --git a/app/routes/widgets.$region.$accountId.box.tsx b/app/routes/widgets.$region.$accountId.box.tsx index b021836..157d029 100644 --- a/app/routes/widgets.$region.$accountId.box.tsx +++ b/app/routes/widgets.$region.$accountId.box.tsx @@ -1,6 +1,7 @@ import { useEffect, useState } from "react"; import type { MetaFunction } from "@remix-run/node"; import { useParams, useSearchParams } from "@remix-run/react"; +import { snakeToPretty } from "~/lib/utils"; export const meta: MetaFunction = () => { return [{ title: "Deadlock Stats Widget" }, { name: "description", content: "Stats widget powered by Deadlock API" }]; @@ -9,9 +10,10 @@ export const meta: MetaFunction = () => { interface StatDisplay { value: string; label: string; - color?: string; } +const UPDATE_INTERVAL_MS = 2 * 60 * 1000; + export default function DeadlockWidget() { const { region, accountId } = useParams(); const [searchParams] = useSearchParams(); @@ -23,7 +25,7 @@ export default function DeadlockWidget() { const variables = searchParams.get("vars")?.split(",") ?? ["leaderboard_place", "wins_today", "losses_today"]; // Get labels from query parameters or use defaults - const labels = searchParams.get("labels")?.split(",") ?? ["Rank", "Wins", "Losses"]; + const labels = searchParams.get("labels")?.split(",") ?? variables.map(snakeToPretty); // Create mapping of variables to their display properties const getStatDisplays = (): StatDisplay[] => { @@ -31,19 +33,10 @@ export default function DeadlockWidget() { return variables.map((variable, index) => { const label = labels[index] || variable; - let color = "text-gray-900"; - - // Apply specific colors based on variable type - if (variable.includes("wins")) { - color = "text-green-600"; - } else if (variable.includes("losses") || variable.includes("deaths")) { - color = "text-red-600"; - } return { value: variable.includes("leaderboard") ? `#${stats[variable]}` : stats[variable], label, - color, }; }); }; @@ -81,51 +74,58 @@ export default function DeadlockWidget() { fetchStats(); // Set up interval for subsequent fetches (every 2 minutes) - const intervalId = setInterval(fetchStats, 2 * 60 * 1000); + const intervalId = setInterval(fetchStats, UPDATE_INTERVAL_MS); // Cleanup interval on component unmount return () => clearInterval(intervalId); - }, [stats, region, accountId, variables.join(",")]); // Add variables to dependencies + }, [region, accountId, variables.join(",")]); const statDisplays = getStatDisplays(); + useEffect(() => { + document.body.style.backgroundColor = "transparent"; + document.documentElement.style.backgroundColor = "transparent"; + return () => { + document.documentElement.style.backgroundColor = ""; // Reset when navigating away + document.body.style.backgroundColor = ""; // Reset when navigating away + }; + }, []); + return ( -
-
- {/* Header */} -
-

- Widget made by{" "} - - deadlock-api.com - -

-
- - {/* Content */} -
- {loading && !stats ? ( -
-
-
- ) : error ? ( -
{error}
- ) : stats ? ( -
3 ? "grid-cols-2" : "grid-cols-3"}`}> - {statDisplays.map((stat, index) => ( -
-

{stat.label}

-

{stat.value}

-
- ))} -
- ) : null} -
+
+ {/* Header */} +
+

+ Widget made by{" "} + + deadlock-api.com + +

+
+ + {/* Content */} +
+ {loading && !stats ? ( +
+
+
+ ) : error ? ( +
{error}
+ ) : stats ? ( +
3 ? "grid-cols-2" : "grid-cols-3"}`}> + {statDisplays.map((stat, index) => ( +
+

{stat.label}

+

{stat.value}

+
+ ))} +
+ ) : null}
);