Add map-specific tournament creation link
Some checks failed
Deploy MineGeo to Dokploy / deploy (push) Failing after 3m31s

This commit is contained in:
2026-10-18 13:32:56 +05:00
parent a7085e4e80
commit da1a50a6ad
10 changed files with 74 additions and 9 deletions

View File

@@ -4,7 +4,7 @@ import { useI18n } from "@/components/I18nProvider";
import { useEffect, useRef, useState, type FormEvent } from "react";
import Link from "next/link";
import { useRouter } from "next/navigation";
import { ArrowRight, Timer, ZoomIn, Users } from "lucide-react";
import { ArrowRight, Timer, ZoomIn, Users, Trophy } from "lucide-react";
import {
difficulties,
customDifficultySchema,
@@ -42,6 +42,7 @@ export function StartGame({
[loading, setLoading] = useState(false),
[error, setError] = useState("");
const router = useRouter();
const tournamentPath = `/tournaments?map=${encodeURIComponent(datasetId)}`;
const starting = useRef(false);
const savingPreset = useRef(false);
useEffect(() => {
@@ -147,6 +148,22 @@ export function StartGame({
<Users size={15} /> {t("Multiplayer")}
</button>
</div>
<Link
className="button tournament-map-action full"
href={
hostName
? tournamentPath
: `/log-in?next=${encodeURIComponent(tournamentPath)}`
}
>
<Trophy size={17} />
{t(
hostName
? "Create tournament with this map"
: "Log in to create a tournament",
)}
<ArrowRight size={17} />
</Link>
<div className="difficulty-options">
{options.map((option) => (
<button

View File

@@ -37,7 +37,13 @@ function time(value: string, zone: string) {
timeZone: zone,
}).format(new Date(value));
}
export function TournamentIndex({ signedIn }: { signedIn: boolean }) {
export function TournamentIndex({
signedIn,
initialMapId = null,
}: {
signedIn: boolean;
initialMapId?: string | null;
}) {
const { t } = useI18n();
const router = useRouter();
const [events, setEvents] = useState<Events | null>(null);
@@ -45,7 +51,8 @@ export function TournamentIndex({ signedIn }: { signedIn: boolean }) {
const [presets, setPresets] = useState<DifficultyPreset[]>([]);
const [error, setError] = useState("");
const [busy, setBusy] = useState(false);
const [creating, setCreating] = useState(false);
const [creating, setCreating] = useState(!!(signedIn && initialMapId));
const [selectedMap, setSelectedMap] = useState(initialMapId ?? "");
const [clock, setClock] = useState(0);
const [timerMode, setTimerMode] = useState<"shared" | "perMini">("shared");
const [roundSeconds, setRoundSeconds] = useState(450);
@@ -83,6 +90,9 @@ export function TournamentIndex({ signedIn }: { signedIn: boolean }) {
if (active) {
setMaps(catalog.maps);
setPresets(difficulties.presets);
setSelectedMap((current) =>
catalog.maps.some((map) => map.id === current) ? current : "",
);
}
})
.catch((e) => {
@@ -183,7 +193,12 @@ export function TournamentIndex({ signedIn }: { signedIn: boolean }) {
</label>
<label>
{t("Map")}
<select name="dataset" required defaultValue="">
<select
name="dataset"
required
value={selectedMap}
onChange={(event) => setSelectedMap(event.target.value)}
>
<option value="" disabled>
{t("Choose a map")}
</option>