File size: 1,294 Bytes
1e92f2d | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | "use client";
import { useRouter } from "next/navigation";
import { useSyncExternalStore, useTransition } from "react";
import { disableDraftMode } from "./actions";
const emptySubscribe = () => () => {};
export default function AlertBanner() {
const router = useRouter();
const [pending, startTransition] = useTransition();
const shouldShow = useSyncExternalStore(
emptySubscribe,
() => window.top === window,
() => false,
);
if (!shouldShow) return null;
return (
<div
className={`${
pending ? "animate-pulse" : ""
} fixed top-0 left-0 z-50 w-full border-b bg-white/95 text-black backdrop-blur`}
>
<div className="py-2 text-center text-sm">
{pending ? (
"Disabling draft mode..."
) : (
<>
{"Previewing drafts. "}
<button
type="button"
onClick={() =>
startTransition(() =>
disableDraftMode().then(() => {
router.refresh();
}),
)
}
className="hover:text-cyan underline transition-colors duration-200"
>
Back to published
</button>
</>
)}
</div>
</div>
);
}
|