-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add PreviewIndicator component
- Loading branch information
1 parent
8b2858b
commit d7cc96f
Showing
7 changed files
with
123 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { cookies, draftMode, headers } from 'next/headers'; | ||
import React from 'react'; | ||
import { redirect } from 'next/navigation'; | ||
import { COOKIE_NAME } from '../handlers/previewRouteHandler'; | ||
|
||
export const PreviewIndicator: React.FC = () => { | ||
const { isEnabled } = draftMode(); | ||
|
||
if (!isEnabled) { | ||
return null; | ||
} | ||
|
||
async function disableDraftMode() { | ||
'use server'; | ||
|
||
const currentUrl = headers().get('x-headstartwp-current-url') ?? '/'; | ||
draftMode().disable(); | ||
cookies().delete(COOKIE_NAME); | ||
redirect(currentUrl); | ||
} | ||
|
||
return ( | ||
<form action={disableDraftMode}> | ||
You are previewing the current page. | ||
<button type="submit">Exit Preview</button> | ||
</form> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.