Skip to content

Commit

Permalink
SUL23-433 Adjusted order of operations for preview mode disabling
Browse files Browse the repository at this point in the history
  • Loading branch information
pookmish committed Apr 19, 2024
1 parent 918b813 commit c8b984d
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 26 deletions.
2 changes: 1 addition & 1 deletion app/api/draft/disable/route.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ export const revalidate = 0;

export async function GET() {
cookies().delete('preview');
return NextResponse.json({message: 'preview disabled'}, {status: 401})
return NextResponse.json({message: 'preview disabled'}, {status: 200})
}
8 changes: 7 additions & 1 deletion app/preview/[...slug]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
import {notFound} from "next/navigation";
import {isPreviewMode} from "@/lib/drupal/is-draft-mode";
import NodePage from "../../[...slug]/page";
import DisablePreviewMode from "../disable-preview-mode";

const PreviewNodePage = async ({params}: PageProps) => {
if (!isPreviewMode()) notFound();
return <NodePage params={params} previewMode={true}/>
return (
<>
<NodePage params={params} previewMode={true}/>
<DisablePreviewMode/>
</>
)
}

type PageProps = {
Expand Down
8 changes: 5 additions & 3 deletions app/preview/disable-preview-mode.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
"use client";

import {useEffect} from "react";
import {useLayoutEffect} from "react";

const DisablePreviewMode = () => {
useEffect(() => {
fetch('/api/draft/disable', {cache: 'no-cache'})
useLayoutEffect(() => {
setTimeout(() => {
fetch('/api/draft/disable', {cache: 'no-cache'})
}, 1000)
}, [])
return null;
}
Expand Down
3 changes: 0 additions & 3 deletions app/preview/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import {ReactNode} from "react";
import {isPreviewMode} from "@/lib/drupal/is-draft-mode";
import Editori11y from "@/components/editori11y";
import {ExclamationCircleIcon} from "@heroicons/react/20/solid";
import DisablePreviewMode from "./disable-preview-mode";

const RootLayout = ({children}: { children: ReactNode }) => {
const previewMode = isPreviewMode()
Expand All @@ -13,9 +12,7 @@ const RootLayout = ({children}: { children: ReactNode }) => {
<div className="bg-illuminating py-10 text-3xl font-bold">
<div className="centered-container flex gap-10"><ExclamationCircleIcon width={20}/>Previewing Content</div>
</div>

<Editori11y/>
<DisablePreviewMode/>
</>
}
{children}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"react-stately": "^3.30.1",
"react-tiny-oembed": "^1.1.0",
"sharp": "^0.33.3",
"tailwind-merge": "^2.2.2",
"tailwind-merge": "^2.3.0",
"tailwindcss": "^3.4.3",
"typescript": "^5.4.5",
"usehooks-ts": "^3.1.0"
Expand Down
2 changes: 1 addition & 1 deletion src/lib/drupal/get-access-token.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ export const getAccessToken = async (previewMode: boolean = false): Promise<Acce
`${process.env.NEXT_PUBLIC_DRUPAL_BASE_URL}/oauth/token`,
{
method: "POST",
next: {revalidate: 299},
headers: {Authorization: `Basic ${basic}`, "Content-Type": "application/x-www-form-urlencoded"},
body: `grant_type=client_credentials`,
cache: "no-cache"
}
)

Expand Down
23 changes: 7 additions & 16 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -658,16 +658,7 @@ __metadata:
languageName: node
linkType: hard

"@babel/runtime@npm:^7.24.0":
version: 7.24.0
resolution: "@babel/runtime@npm:7.24.0"
dependencies:
regenerator-runtime: "npm:^0.14.0"
checksum: 10c0/3495eed727bf4a4f84c35bb51ab53317ae38f4bbc3b1d0a8303751f9dfa0ce6f5fb2afced72b76c3dd0d8bb2ccb84787559a4dee9886291a36b26f02f0f759b4
languageName: node
linkType: hard

"@babel/runtime@npm:^7.24.4":
"@babel/runtime@npm:^7.24.1, @babel/runtime@npm:^7.24.4":
version: 7.24.4
resolution: "@babel/runtime@npm:7.24.4"
dependencies:
Expand Down Expand Up @@ -4472,7 +4463,7 @@ __metadata:
react-stately: "npm:^3.30.1"
react-tiny-oembed: "npm:^1.1.0"
sharp: "npm:^0.33.3"
tailwind-merge: "npm:^2.2.2"
tailwind-merge: "npm:^2.3.0"
tailwindcss: "npm:^3.4.3"
typescript: "npm:^5.4.5"
usehooks-ts: "npm:^3.1.0"
Expand Down Expand Up @@ -9565,12 +9556,12 @@ __metadata:
languageName: node
linkType: hard

"tailwind-merge@npm:^2.2.2":
version: 2.2.2
resolution: "tailwind-merge@npm:2.2.2"
"tailwind-merge@npm:^2.3.0":
version: 2.3.0
resolution: "tailwind-merge@npm:2.3.0"
dependencies:
"@babel/runtime": "npm:^7.24.0"
checksum: 10c0/68a5e199848a467aed4f8d1a8d7b6a5b583ff72f1d2801e018bf245eaa41e6564b63ead9e2b708a214cefbd843970c5e0a21754d5f2a20e2c1238e25955685ce
"@babel/runtime": "npm:^7.24.1"
checksum: 10c0/5ea308e23c3ab1cf4c3f35f0a471753f4d3ed232d63dd7c09151a74428737321902203d90e9f0cb76ea5c3978e71b0adbc503dc455e56cda967a7674ae4b94b5
languageName: node
linkType: hard

Expand Down

0 comments on commit c8b984d

Please sign in to comment.