mirror of
https://github.com/hanzoai/next.js.git
synced 2026-10-30 14:46:38 +00:00
This PR updates the `cms-sanity` example to use: - App Router - TypeScript - Sanity Studio v3 instead of v2 - Embeds the Studio inside the next app on the `/studio` route. - ISR / Data Cache (revalidations through `revalidatePath` while in Live Visual Editing, time-based to match the Sanity API CDN in production). - Support Vercel Visual Editing out of the box. - The new `next-sanity/image` component. - Vercel Speed Insights. - The Sanity Presentation Tool for live content previews. - Sanity Portable Text setup to fully support `@tailwindcss/typography`. - [AI Assist](https://www.sanity.io/docs/ai-assist) - Auto fill in `alt` text on images. - Preset prompts for content creation
53 lines
1.3 KiB
TypeScript
53 lines
1.3 KiB
TypeScript
"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>
|
|
);
|
|
}
|