fix: use search param for redirect banner instead
This commit is contained in:
parent
3c7b17dff2
commit
62ab328fa2
3 changed files with 15 additions and 25 deletions
|
|
@ -8,7 +8,6 @@ import Providers from "./provider";
|
|||
import Header from "@/components/header";
|
||||
import Footer from "@/components/footer";
|
||||
import AdminBanner from "@/components/admin/banner";
|
||||
import RedirectBanner from "@/components/redirect-banner";
|
||||
|
||||
const lexend = Lexend({
|
||||
subsets: ["latin"],
|
||||
|
|
@ -55,7 +54,6 @@ export default function RootLayout({
|
|||
<Providers>
|
||||
<Header />
|
||||
<AdminBanner />
|
||||
<RedirectBanner />
|
||||
<main className="px-4 py-8 max-w-7xl w-full flex-grow flex flex-col">{children}</main>
|
||||
<Footer />
|
||||
</Providers>
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
"use client";
|
||||
|
||||
import { useSearchParams } from "next/navigation";
|
||||
import useSWR from "swr";
|
||||
import { Icon } from "@iconify/react";
|
||||
|
||||
|
|
@ -9,14 +10,23 @@ interface ApiResponse {
|
|||
|
||||
const fetcher = (url: string) => fetch(url).then((res) => res.json());
|
||||
|
||||
export default function AdminBanner() {
|
||||
const { data } = useSWR<ApiResponse>("/api/admin/banner", fetcher);
|
||||
if (!data || !data.message) return null;
|
||||
|
||||
return (
|
||||
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="humbleicons:exclamation" className="text-2xl min-w-6" />
|
||||
<span>{data.message}</span>
|
||||
<Icon icon={icon} className="text-2xl min-w-6" />
|
||||
<span>{message}</span>
|
||||
</div>
|
||||
);
|
||||
|
||||
export default function AdminBanner() {
|
||||
const searchParams = useSearchParams();
|
||||
const from = searchParams.get("from");
|
||||
|
||||
const { data } = useSWR<ApiResponse>("/api/admin/banner", fetcher);
|
||||
|
||||
return (
|
||||
<>
|
||||
{data && data.message && <Banner icon="humbleicons:exclamation" message={data.message} />}
|
||||
{from == "old-domain" && <Banner icon="humbleicons:link" message="We have moved URLs, welcome to tomodachishare.com!" />}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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've been redirected — TomodachiShare is now at <strong>tomodachishare.com</strong>!
|
||||
</span>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Loading…
Reference in a new issue