fix: use search param for redirect banner instead

This commit is contained in:
trafficlunar 2025-06-11 16:08:01 +01:00
parent 3c7b17dff2
commit 62ab328fa2
3 changed files with 15 additions and 25 deletions

View file

@ -8,7 +8,6 @@ import Providers from "./provider";
import Header from "@/components/header"; import Header from "@/components/header";
import Footer from "@/components/footer"; import Footer from "@/components/footer";
import AdminBanner from "@/components/admin/banner"; import AdminBanner from "@/components/admin/banner";
import RedirectBanner from "@/components/redirect-banner";
const lexend = Lexend({ const lexend = Lexend({
subsets: ["latin"], subsets: ["latin"],
@ -55,7 +54,6 @@ export default function RootLayout({
<Providers> <Providers>
<Header /> <Header />
<AdminBanner /> <AdminBanner />
<RedirectBanner />
<main className="px-4 py-8 max-w-7xl w-full flex-grow flex flex-col">{children}</main> <main className="px-4 py-8 max-w-7xl w-full flex-grow flex flex-col">{children}</main>
<Footer /> <Footer />
</Providers> </Providers>

View file

@ -1,5 +1,6 @@
"use client"; "use client";
import { useSearchParams } from "next/navigation";
import useSWR from "swr"; import useSWR from "swr";
import { Icon } from "@iconify/react"; import { Icon } from "@iconify/react";
@ -9,14 +10,23 @@ interface ApiResponse {
const fetcher = (url: string) => fetch(url).then((res) => res.json()); const fetcher = (url: string) => fetch(url).then((res) => res.json());
const Banner = ({ icon, message }: { icon: string; message: string }) => (
<div className="w-full h-10 bg-orange-300 border-y-2 border-y-orange-400 mt-1 shadow-md flex justify-center items-center gap-2 text-orange-900 text-nowrap overflow-x-auto font-semibold max-sm:justify-start">
<Icon icon={icon} className="text-2xl min-w-6" />
<span>{message}</span>
</div>
);
export default function AdminBanner() { export default function AdminBanner() {
const searchParams = useSearchParams();
const from = searchParams.get("from");
const { data } = useSWR<ApiResponse>("/api/admin/banner", fetcher); const { data } = useSWR<ApiResponse>("/api/admin/banner", fetcher);
if (!data || !data.message) return null;
return ( return (
<div className="w-full h-10 bg-orange-300 border-y-2 border-y-orange-400 mt-1 shadow-md flex justify-center items-center gap-2 text-orange-900 text-nowrap overflow-x-auto font-semibold max-sm:justify-start"> <>
<Icon icon="humbleicons:exclamation" className="text-2xl min-w-6" /> {data && data.message && <Banner icon="humbleicons:exclamation" message={data.message} />}
<span>{data.message}</span> {from == "old-domain" && <Banner icon="humbleicons:link" message="We have moved URLs, welcome to tomodachishare.com!" />}
</div> </>
); );
} }

View file

@ -1,18 +0,0 @@
import { headers } from "next/headers";
import { Icon } from "@iconify/react";
export default async function RedirectBanner() {
const headersList = await headers();
const referer = headersList.get("Referer");
if (referer !== "https://tomodachi-share.trafficlunar.net") return null;
return (
<div className="w-full h-10 bg-orange-300 border-y-2 border-y-orange-400 mt-1 shadow-md flex justify-center items-center gap-2 text-orange-900 text-nowrap overflow-x-auto font-semibold max-sm:justify-start">
<Icon icon="humbleicons:link" className="text-2xl min-w-6" />
<span>
You&apos;ve been redirected TomodachiShare is now at <strong>tomodachishare.com</strong>!
</span>
</div>
);
}