Issue with custom preview component not showing in search results view
3 replies
Last updated: Jul 29, 2021
M
Hello you clever people. Got a bit of a conundrum here. I have created a custom preview component for my main doc type, and managed to have this preview show up as the default view, so when I select a word in the menu I see the nicely formatted preview, as in fig 1. However if I use the search bar and find a word (as illustrated in fig 2) and select it by clicking or hitting enter I get this different view showing the form, and with the links to the view options (Display, Editor) removed. How can I make the document show in the custom preview in this "searched result"-view?
Jul 29, 2021, 2:13 PM
M
My deskstructure might be relevant:
import { CgBox as ByCatIcon } from 'react-icons/cg'; import S from '@sanity/desk-tool/structure-builder'; import WordPreview from '../cpt/WordPreview'; export default () => S.list() .title('Content') .items([ S.listItem() .title('Words by category') .icon(ByCatIcon) .child( // List out the categories S.documentTypeList('category') .title('Words by category') // When a category is selected, pass its id down to the next pane .child((categoryId) => // load a new document list S.documentList() .title('Words') // Use a GROQ filter to get documents. // This filter checks for sampleProjects that has the // categoryId in its array of references .filter('_type == "word" && $categoryId == category._ref') .params({ categoryId }) ) ), S.divider(), S.listItem() .title('All words') .schemaType('word') // When you open this list item, list out the documents // of the type category" .child(S.documentTypeList('word').title('Words')), S.listItem() .title('Categories') .schemaType('category') .child(S.documentTypeList('category').title('Categories')), ]); export const getDefaultDocumentNode = ({ schemaType }) => { // Conditionally return a different configuration based on the schema type if (schemaType === 'word') { return S.document().views([ S.view.component(WordPreview).title('Display'), S.view.form(), ]); } };
Jul 29, 2021, 2:58 PM
Jul 29, 2021, 4:24 PM
M
Joining the effort, then.
Jul 29, 2021, 4:27 PM
Sanity– build remarkable experiences at scale
Sanity is a modern headless CMS that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.