-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: use
perspective
features (#389)
Co-authored-by: Martin Jacobsen <174970+mmgj@users.noreply.github.com>
- Loading branch information
Showing
95 changed files
with
1,043 additions
and
984 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { draftMode } from 'next/headers' | ||
import { PreviewDraftsButton, ViewPublishedButton } from 'ui/react' | ||
|
||
export default function DraftModeButton() { | ||
return ( | ||
<form style={{ display: 'contents' }}> | ||
{draftMode().isEnabled ? ( | ||
<ViewPublishedButton formAction="/api/disable-draft" /> | ||
) : ( | ||
<PreviewDraftsButton formAction="/api/draft" /> | ||
)} | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,32 @@ | ||
'use client' | ||
|
||
import { Button } from 'ui/react' | ||
import { useListeningQueryStatus } from '@sanity/preview-kit' | ||
import { useRouter } from 'next/navigation' | ||
import { useEffect, useTransition } from 'react' | ||
import { experimental_useFormStatus as useFormStatus } from 'react-dom' | ||
import { Button, tableQuery } from 'ui/react' | ||
import { revalidate } from './actions' | ||
|
||
export default function RefreshButton() { | ||
function useRefresh() { | ||
const { pending } = useFormStatus() | ||
const router = useRouter() | ||
const [loading, startTransition] = useTransition() | ||
const status = useListeningQueryStatus(tableQuery) | ||
useEffect(() => { | ||
if (!pending) { | ||
startTransition(() => router.refresh()) | ||
} | ||
}, [pending, router]) | ||
|
||
return pending || loading || status === 'loading' | ||
} | ||
|
||
export default function RefreshButton() { | ||
const loading = useRefresh() | ||
|
||
return ( | ||
<form | ||
className="section" | ||
onSubmit={(event) => { | ||
event.preventDefault() | ||
router.refresh() | ||
}} | ||
> | ||
<Button>Refresh</Button> | ||
<form action={revalidate} className="section"> | ||
<Button isLoading={loading}>Refresh</Button> | ||
</form> | ||
) | ||
} |
11 changes: 0 additions & 11 deletions
11
apps/next-app-router-groq-store/app/ViewPublishedButtonWithLoadingStatus.tsx
This file was deleted.
Oops, something went wrong.
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,7 @@ | ||
'use server' | ||
|
||
import { revalidatePath } from 'next/cache' | ||
|
||
export async function revalidate() { | ||
await revalidatePath('/') | ||
} |
8 changes: 8 additions & 0 deletions
8
apps/next-app-router-groq-store/app/api/disable-draft/route.ts
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,8 @@ | ||
import { redirect } from 'next/navigation' | ||
|
||
import { draftMode } from 'next/headers' | ||
|
||
export async function GET(request: Request) { | ||
draftMode().disable() | ||
redirect('/') | ||
} |
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 |
---|---|---|
@@ -1,12 +1,8 @@ | ||
import { redirect } from 'next/navigation' | ||
|
||
import { draftMode } from 'next/headers' | ||
import { NextRequest, NextResponse } from 'next/server' | ||
|
||
export function GET(req: NextRequest) { | ||
if (draftMode().isEnabled) { | ||
draftMode().disable() | ||
} else { | ||
draftMode().enable() | ||
} | ||
const url = new URL(req.nextUrl) | ||
return NextResponse.redirect(new URL('/', url.origin)) | ||
export async function GET(request: Request) { | ||
draftMode().enable() | ||
redirect('/') | ||
} |
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 |
---|---|---|
@@ -1,36 +1,28 @@ | ||
import { createClient, type SanityClient } from '@sanity/preview-kit/client' | ||
import { apiVersion, dataset, projectId, useCdn } from './sanity.env' | ||
|
||
export type { SanityClient } | ||
const projectId = process.env.NEXT_PUBLIC_SANITY_PROJECT_ID || 'pv8y60vp' | ||
const dataset = process.env.NEXT_PUBLIC_SANITY_DATASET || 'production' | ||
const apiVersion = process.env.NEXT_PUBLIC_SANITY_API_VERSION || '2022-11-15' | ||
const useCdn = true | ||
|
||
export function getClient({ | ||
preview = false, | ||
token = process.env.SANITY_API_READ_TOKEN, | ||
}: { | ||
preview?: boolean | ||
token?: string | ||
}): SanityClient { | ||
export function getClient(preview?: { token: string }): SanityClient { | ||
const client = createClient({ | ||
projectId, | ||
dataset, | ||
apiVersion, | ||
useCdn, | ||
studioUrl: 'https://preview-kit-test-studio.sanity.build/', | ||
encodeSourceMapAtPath: () => true, | ||
token, | ||
perspective: 'published', | ||
ignoreBrowserTokenWarning: true, | ||
}) | ||
|
||
if (preview) { | ||
if (!token) { | ||
if (!preview.token) { | ||
throw new Error('You must provide a token to preview drafts') | ||
} | ||
return client.withConfig({ | ||
perspective: 'previewDrafts', | ||
token: preview.token, | ||
useCdn: false, | ||
ignoreBrowserTokenWarning: true, | ||
}) | ||
} | ||
|
||
return client | ||
} |
This file was deleted.
Oops, something went wrong.
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,9 @@ | ||
/** @type {import('next').NextConfig} */ | ||
const nextConfig = { | ||
experimental: { | ||
logging: 'verbose', | ||
serverActions: true, | ||
}, | ||
} | ||
|
||
export default nextConfig |
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,14 @@ | ||
import { draftMode } from 'next/headers' | ||
import { PreviewDraftsButton, ViewPublishedButton } from 'ui/react' | ||
|
||
export default function DraftModeButton() { | ||
return ( | ||
<form style={{ display: 'contents' }}> | ||
{draftMode().isEnabled ? ( | ||
<ViewPublishedButton formAction="/api/disable-draft" /> | ||
) : ( | ||
<PreviewDraftsButton formAction="/api/draft" /> | ||
)} | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
'use client' | ||
|
||
import { FooterProps, footerQuery, Footer } from 'ui/react' | ||
import { useListeningQuery } from '@sanity/preview-kit' | ||
import { useLiveQuery } from '@sanity/preview-kit' | ||
|
||
export default function PreviewFooter(props: FooterProps) { | ||
const data = useListeningQuery<FooterProps['data']>(props.data, footerQuery) | ||
const [data] = useLiveQuery<FooterProps['data']>(props.data, footerQuery) | ||
|
||
return <Footer data={data} /> | ||
} |
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 |
---|---|---|
@@ -1,10 +1,10 @@ | ||
'use client' | ||
|
||
import { TableProps, tableQuery, Table } from 'ui/react' | ||
import { useListeningQuery } from '@sanity/preview-kit' | ||
import { useLiveQuery } from '@sanity/preview-kit' | ||
|
||
export default function PreviewTable(props: TableProps) { | ||
const data = useListeningQuery<TableProps['data']>(props.data, tableQuery) | ||
const [data] = useLiveQuery<TableProps['data']>(props.data, tableQuery) | ||
|
||
return <Table data={data} /> | ||
} |
Oops, something went wrong.
4139e28
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
preview-kit-remix – ./apps/remix
preview-kit-remix.sanity.build
preview-kit-remix-git-main.sanity.build
4139e28
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
preview-kit-next-app-router-no-store – ./apps/next-app-router-no-store
preview-kit-next-app-router-no-store.sanity.build
preview-kit-next-app-router-no-store-git-main.sanity.build
4139e28
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
preview-kit-next-app-router-live-store – ./apps/next-app-router-live-store
preview-kit-remix-qhfv.sanity.build
preview-kit-next-app-router-live-store-git-main.sanity.build
preview-kit-next-app-router-live-store.sanity.build
4139e28
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
preview-kit-next-app-router – ./apps/next-app-router
preview-kit-next-app-router.sanity.build
preview-kit-next-app-router-git-main.sanity.build
4139e28
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
preview-kit-next-pages-router-groq-store – ./apps/next-pages-router-groq-store
preview-kit-next-pages-router-groq-store.sanity.build
preview-kit-next-pages-router-groq-store-git-main.sanity.build
4139e28
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
preview-kit-next-pages-router – ./apps/next-pages-router
preview-kit-next-pages-router.sanity.build
preview-kit-next-pages-router-git-main.sanity.build
4139e28
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
preview-kit-remix-groq-store – ./apps/remix-groq-store
preview-kit-remix-groq-store.sanity.build
preview-kit-remix-groq-store-git-main.sanity.build
4139e28
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
preview-kit-test-studio – ./apps/studio
preview-kit-test-studio.sanity.build
preview-kit-test-studio-git-main.sanity.build
4139e28
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
preview-kit-remix-live-store-lazy – ./apps/remix-live-store-lazy
preview-kit-remix-live-store-lazy.sanity.build
preview-kit-remix-live-store-lazy-git-main.sanity.build
4139e28
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
preview-kit-remix-live-store – ./apps/remix-live-store
preview-kit-remix-live-store.sanity.build
preview-kit-remix-live-store-git-main.sanity.build
4139e28
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
preview-kit-next-pages-router-live-store – ./apps/next-pages-router-live-store
preview-kit-next-pages-router-live-store.sanity.build
preview-kit-next-pages-router-live-store-git-main.sanity.build
4139e28
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
preview-kit-next-app-router-groq-store – ./apps/next-app-router-groq-store
preview-kit-next-app-router-groq-store.sanity.build
preview-kit-next-app-router-groq-store-git-main.sanity.build
4139e28
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
preview-kit-remix-groq-store-lazy – ./apps/remix-groq-store-lazy
preview-kit-remix-groq-store-lazy.sanity.build
preview-kit-remix-groq-store-lazy-git-main.sanity.build