-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update structure schema and add createCollection helper with Preview …
…component
- Loading branch information
1 parent
a9f922c
commit 6867fa5
Showing
5 changed files
with
49 additions
and
52 deletions.
There are no files selected for viewing
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,29 @@ | ||
import type { StructureBuilder } from "sanity/structure"; | ||
import { schemaTypes } from "./schema-types"; | ||
import { TYPES_TO_EXCLUDE_PREVIEWS } from "."; | ||
import { Preview } from "./preview"; | ||
|
||
export const createCollection = (S: StructureBuilder, name: string) => { | ||
const { title, icon } = schemaTypes.find(item => item.name === name) as { title: string, icon: React.ReactNode }; | ||
return S.listItem() | ||
.title(title) | ||
.icon(icon) | ||
.child( | ||
S.documentTypeList(name) | ||
.title(title) | ||
.child(documentId => | ||
S.document() | ||
.documentId(documentId) | ||
.schemaType(name) | ||
.views([ | ||
S.view.form().title('Editor').icon(() => '🖋️'), | ||
...(!TYPES_TO_EXCLUDE_PREVIEWS.includes(name) ? [ | ||
S.view | ||
.component(Preview) | ||
.title('Preview') | ||
.icon(() => '👀') | ||
] : []), | ||
]) | ||
) | ||
); | ||
}; |
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,13 @@ | ||
import { Iframe, type IframeProps } from "sanity-plugin-iframe-pane"; | ||
import { PREVIEW_DEPLOYMENT_DOMAIN } from "../constants"; | ||
|
||
export const Preview = ({ document }: { document: IframeProps['document'] }) => { | ||
const slug = (document.displayed.slug as { current?: string })?.current; | ||
if (!slug) return <div style={{ padding: '1rem' }}>🛑 Preview not available: The slug is missing</div>; | ||
return <Iframe | ||
document={document} | ||
options={{ | ||
url: `${PREVIEW_DEPLOYMENT_DOMAIN}${slug}`, | ||
reload: { button: true } | ||
}} /> | ||
} |