Fix routing details

This commit is contained in:
Timothy Armes
2024-09-30 09:42:37 +02:00
parent 08cbcd785e
commit 03f5ea3454
20 changed files with 60 additions and 43 deletions
+16 -4
View File
@@ -1,13 +1,27 @@
"use client";
import { useTranslations } from "next-intl";
import { useLocale, useTranslations } from "next-intl";
import { useSearchParams } from "next/navigation";
import { SignInForm } from "@/components/SignInForm";
import { Locale, getPathname, routing } from "@/utils/routing";
export default function SignIn() {
const t = useTranslations("SignIn");
const params = useSearchParams();
const locale = useLocale();
const allowedLocales = routing.locales as unknown as Array<string>;
const effectiveLocal = allowedLocales.includes(locale)
? (locale as Locale)
: routing.defaultLocale;
const fallbackPath = getPathname({
locale: effectiveLocal,
href: { pathname: "/tournaments" },
});
const fallbackUrl = `/${effectiveLocal}${fallbackPath}`;
return (
<section className="grid place-items-center bg-white pb-20 dark:bg-gray-800">
@@ -22,9 +36,7 @@ export default function SignIn() {
{t("info")}
</p>
<SignInForm
callbackPath={params.get("callbackUrl") ?? "/tournaments"}
/>
<SignInForm callbackPath={params.get("callbackUrl") ?? fallbackUrl} />
</div>
</section>
);
@@ -7,7 +7,7 @@ import { FaGithub, FaRegEnvelope } from "react-icons/fa";
import { MdOutlinePrivacyTip } from "react-icons/md";
import { burgerMenuIsOpenAtom } from "@/atoms";
import { Link, usePathname, useRouter } from "@/utils/navigation";
import { Link, usePathname, useRouter } from "@/utils/routing";
import ThemeSwitcher from "./ThemeSwitcher";
@@ -4,7 +4,7 @@ import { twMerge } from "tailwind-merge";
import { burgerMenuIsOpenAtom } from "@/atoms";
import { useAuthMenuOptions } from "@/hooks/useAuthMenuOptions";
import { Link } from "@/utils/navigation";
import { Link } from "@/utils/routing";
const HamburgerMenu = () => {
const t = useTranslations("Nav");
@@ -1,7 +1,7 @@
import { useTranslations } from "next-intl";
import AuthButton from "@/components/AuthButton";
import { Link } from "@/utils/navigation";
import { Link } from "@/utils/routing";
import Hamburger from "./Hamburger";
@@ -7,7 +7,7 @@ import { useTranslations } from "next-intl";
import InfoMessage from "@/components/InfoMessage";
import { deleteAccount } from "@/server/deleteAccount";
import { useRouter } from "@/utils/navigation";
import { useRouter } from "@/utils/routing";
export default function Contact() {
const t = useTranslations("DeleteAccount");
+1 -1
View File
@@ -19,7 +19,7 @@ import { fetchTournamentResultsSchema } from "@/schemas";
import { fetchTournamentResults } from "@/server/fetchTournamentResults";
import { SearchedTournament } from "@/server/searchTournaments";
import { TimeControl } from "@/types";
import { Link } from "@/utils/navigation";
import { Link } from "@/utils/routing";
import { KFactor } from "./KFactor";
import { ManualEloForm } from "./ManualEloForm";
@@ -16,8 +16,8 @@ import {
} from "@/atoms";
import { Map, MapMarker } from "@/components/Map";
import { TimeControlColours } from "@/constants";
import { generatePieSVG } from "@/lib/pie";
import { TimeControl } from "@/types";
import { generatePieSVG } from "@/utils/pie";
import Legend from "./Legend";
import TimeControlFilters from "./TimeControlFilters";
@@ -7,7 +7,7 @@ import { useTranslations } from "next-intl";
import InfoMessage, { clearMessage } from "@/components/InfoMessage";
import { useZones } from "@/hooks/useZones";
import { createZone } from "@/server/createZone";
import { useRouter } from "@/utils/navigation";
import { useRouter } from "@/utils/routing";
import { ZoneForm, ZoneFormValues } from "../components/ZoneForm";
@@ -8,7 +8,7 @@ import { useParams } from "next/navigation";
import InfoMessage, { clearMessage } from "@/components/InfoMessage";
import { useZones } from "@/hooks/useZones";
import { editZone } from "@/server/editZone";
import { useRouter } from "@/utils/navigation";
import { useRouter } from "@/utils/routing";
import { ZoneForm, ZoneFormValues } from "../../components/ZoneForm";
+1 -1
View File
@@ -12,7 +12,7 @@ import { Spinner } from "@/components/Spinner";
import { useZones } from "@/hooks/useZones";
import { deleteZone } from "@/server/deleteZone";
import { TimeControl } from "@/types";
import { Link, useRouter } from "@/utils/navigation";
import { Link, useRouter } from "@/utils/routing";
const ZoneThumbnail = dynamic(() => import("./components/ZoneThumbnail"), {
ssr: false,
+1 -1
View File
@@ -6,7 +6,7 @@ import { HiUserGroup } from "react-icons/hi2";
import { twMerge } from "tailwind-merge";
import bannerImage from "@/img/banner.jpeg";
import { Link } from "@/utils/navigation";
import { Link } from "@/utils/routing";
export default function Home() {
const t = useTranslations("Home");
+16 -14
View File
@@ -1,28 +1,30 @@
import { MetadataRoute } from "next";
import { locales, pathnames } from "@/utils/navigation";
import { Pathnames, routing } from "@/utils/routing";
export default function sitemap(): MetadataRoute.Sitemap {
return locales.flatMap((locale) => {
return routing.locales.flatMap((locale) => {
const prefix = `https://echecsfrance.com${
locale === "fr" ? "" : `/${locale}`
}`;
const paths = Object.keys(pathnames) as Array<keyof typeof pathnames>;
const paths = Object.keys(routing.pathnames) as Array<Pathnames>;
return paths
.filter((pathname) => !pathname.includes("["))
.map((pathname) => {
const route = routing.pathnames[pathname];
if (typeof route === "string") {
return {
url: `${prefix}${route}`,
lastModified: new Date(),
};
}
return paths.map((pathname) => {
const route = pathnames[pathname];
if (typeof route === "string") {
return {
url: `${prefix}${route}`,
url: `${prefix}${route[locale]}`,
lastModified: new Date(),
};
}
return {
url: `${prefix}${route[locale]}`,
lastModified: new Date(),
};
});
});
});
}