Sigurd Heggemsnes
Developer who loves making life easier for people
Sigurd is located at Oslo, Norway
Open editor and preview pane in split view all the time
// ./sanity/components/auto-preivew-pane.component.tsx
import { useEffect } from "react"
import { usePaneRouter } from "sanity/desk"
export const AutoPreviewPane = () => {
const {
setView,
duplicateCurrent,
groupIndex,
hasGroupSiblings,
routerPanesState,
} = usePaneRouter()
useEffect(() => {
// Check if "preview" is active
const isPreviewActive = routerPanesState.some((group) =>
group.some((pane) => pane.params?.view === "preview")
)
if (!isPreviewActive) {
if (hasGroupSiblings) {
if (groupIndex === 1) {
setView("preview")
}
} else {
duplicateCurrent()
}
}
// Ignoring this because adding deps causes lots of loops
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [])
return null
}
// ./sanity/schemas/article.document.tsx
import { AutoPreviewPane } from "../components/auto-preview-pane.component"
export const article = defineType({
type: "document",
name: "article",
title: "Article",
fields: [
defineField({
type: "string",
name: "title",
}),
defineField({
type:"string",
name:"hiddenPreviewField",
components: {
field: AutoPreviewPane,
},
})
],
})
Please note!
usePaneRouter
. Please adjust it to your needs. If you have groups make sure your component is in the default group for it to load properly.Why?
On a lot of content types our editors would always want to see the preview of their website. Pressing split content button and then the preview tab has become engrained in my brain so I realised we need another solution.
Developer who loves making life easier for people
Get parents parent in reference filter
Go to Get parents parent in reference filterOrder by last name
Go to Use GROQ to order by last name in where name is stored as full name