diff --git a/components/HomeClient.tsx b/components/HomeClient.tsx
index 632bf77..26d4ef0 100644
--- a/components/HomeClient.tsx
+++ b/components/HomeClient.tsx
@@ -7,7 +7,7 @@ import Pitch from "@/components/Pitch";
import PlayerSearch from "@/components/PlayerSearch";
import ShareResult from "@/components/ShareResult";
import StatsPanel from "@/components/StatsPanel";
-import { buildShareText, buildShareUrl } from "@/lib/share";
+import { buildGlobalStatsShareText, buildShareText, buildShareUrl } from "@/lib/share";
import {
DIFFICULTIES,
MAX_ATTEMPTS,
@@ -59,6 +59,7 @@ export default function Home() {
[dateKey, progress],
);
const shareText = useMemo(() => buildShareText(dateKey, progress, t), [dateKey, progress, t]);
+ const globalStatsShareText = useMemo(() => buildGlobalStatsShareText(stats, t), [stats, t]);
useEffect(() => {
const savedLocale = window.localStorage.getItem("hidden11-locale") as Locale | null;
@@ -190,6 +191,25 @@ export default function Home() {
);
}
+ async function shareGlobalStats() {
+ const homeUrl = typeof window === "undefined" ? "https://hidden11.app" : window.location.origin.replace(/\/$/, "");
+
+ if (navigator.share) {
+ await navigator.share({
+ title: "hidden11",
+ text: globalStatsShareText,
+ url: homeUrl,
+ });
+ return;
+ }
+
+ window.open(
+ `https://twitter.com/intent/tweet?text=${encodeURIComponent(globalStatsShareText)}&url=${encodeURIComponent(homeUrl)}`,
+ "_blank",
+ "noopener,noreferrer",
+ );
+ }
+
const actionButtons = (
-
+
) : null}
diff --git a/components/StatsPanel.tsx b/components/StatsPanel.tsx
index 5325fcc..d4e34fe 100644
--- a/components/StatsPanel.tsx
+++ b/components/StatsPanel.tsx
@@ -3,18 +3,19 @@ import { formatElapsed } from "@/lib/time";
import type { GlobalStats } from "@/lib/types";
type StatsPanelProps = {
+ showLead?: boolean;
stats: GlobalStats;
t: Dictionary;
};
-export default function StatsPanel({ stats, t }: StatsPanelProps) {
+export default function StatsPanel({ showLead = true, stats, t }: StatsPanelProps) {
const maxDistribution = Math.max(...Object.values(stats.winDistribution), 1);
return (
{t.stats}
-
{t.statsLead}
+ {showLead ?
{t.statsLead}
: null}
diff --git a/lib/share.ts b/lib/share.ts
index 41ad792..b9d6d09 100644
--- a/lib/share.ts
+++ b/lib/share.ts
@@ -1,7 +1,7 @@
import { DIFFICULTIES, getPuzzleNumber, MAX_ATTEMPTS, POSITIONS } from "./game-engine";
import type { Dictionary } from "./i18n";
import { formatElapsed } from "./time";
-import type { DailyProgress, Difficulty } from "./types";
+import type { DailyProgress, Difficulty, GlobalStats } from "./types";
const emoji = {
correct: "🟩",
@@ -57,6 +57,25 @@ export function buildShareText(dateKey: string, progress: DailyProgress, t: Dict
].join("\n");
}
+export function buildGlobalStatsShareText(stats: GlobalStats, t: Dictionary): string {
+ const homeUrl = "https://hidden11.app";
+ const bestTime = stats.bestSeconds === null ? "0:00" : formatElapsed(stats.bestSeconds);
+
+ return [
+ "┏━ hidden11.app ━┓",
+ "⚽ hidden11 global stats",
+ "",
+ `${t.played}: ${stats.gamesPlayed}`,
+ `${t.streak}: ${stats.currentStreak}`,
+ `${t.maxStreak}: ${stats.maxStreak}`,
+ `${t.perfectDays}: ${stats.perfectDays}`,
+ `${t.averageTime}: ${formatElapsed(stats.averageSeconds)}`,
+ `${t.bestTime}: ${bestTime}`,
+ "",
+ `Play: ${homeUrl}`,
+ ].join("\n");
+}
+
export function buildShareUrl(_dateKey: string, _progress: DailyProgress, origin = "https://hidden11.app"): string {
return origin.replace(/\/$/, "");
}