Skip to content

Commit

Permalink
change whole structure of documentPreview in schemas
Browse files Browse the repository at this point in the history
  • Loading branch information
milewskibogumil committed Nov 1, 2024
1 parent 6c88ae1 commit 2bf3856
Show file tree
Hide file tree
Showing 11 changed files with 19 additions and 13 deletions.
1 change: 1 addition & 0 deletions apps/sanity/schema/singleTypes/About_Page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export default defineType({
type: 'document',
title: title,
icon,
options: { documentPreview: true },
fields: [
...defineSlugForDocument({ slug: slug }),
defineField({
Expand Down
1 change: 1 addition & 0 deletions apps/sanity/schema/singleTypes/Contact_Page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export default defineType({
type: 'document',
title: title,
icon,
options: { documentPreview: true },
fields: [
...defineSlugForDocument({ slug: slug }),
defineField({
Expand Down
1 change: 1 addition & 0 deletions apps/sanity/schema/singleTypes/Index_Page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export default defineType({
type: 'document',
title: title,
icon,
options: { documentPreview: true },
fields: [
...defineSlugForDocument({ slug: slug }),
defineField({
Expand Down
1 change: 1 addition & 0 deletions apps/sanity/schema/singleTypes/Investments_Page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export default defineType({
type: 'document',
title: title,
icon,
options: { documentPreview: true },
fields: [
...defineSlugForDocument({ slug }),
defineField({
Expand Down
1 change: 1 addition & 0 deletions apps/sanity/schema/singleTypes/NotFound_Page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export default defineType({
type: 'document',
title: title,
icon,
options: { documentPreview: true },
fields: [
...defineSlugForDocument({ slug: slug }),
defineField({
Expand Down
1 change: 1 addition & 0 deletions apps/sanity/schema/singleTypes/PrivacyPolicy_Page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export default defineType({
type: 'document',
title: title,
icon,
options: { documentPreview: true },
fields: [
...defineSlugForDocument({ slug: slug }),
defineField({
Expand Down
1 change: 1 addition & 0 deletions apps/sanity/schema/singleTypes/Projects_Page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export default defineType({
type: 'document',
title: title,
icon,
options: { documentPreview: true },
fields: [
...defineSlugForDocument({ slug }),
defineField({
Expand Down
6 changes: 2 additions & 4 deletions apps/sanity/structure/index.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@

import type { StructureResolver } from 'sanity/structure'
import { createSingleton } from './create-singleton';
import { createCollection } from './create-collection';

export const TYPES_TO_EXCLUDE_PREVIEWS = ['global', 'redirects', 'Faq_Collection'];
import { createSingleton } from '../utils/create-singleton';
import { createCollection } from '../utils/create-collection';

export const structure: StructureResolver = (S) =>
S.list()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import type { StructureBuilder } from "sanity/structure";
import { schemaTypes } from "./schema-types";
import { schemaTypes } from "../structure/schema-types";
import { Preview } from "./preview";
import { TYPES_TO_EXCLUDE_PREVIEWS } from ".";

export const createCollection = (S: StructureBuilder, name: string) => {
const { title, icon } = schemaTypes.find(item => item.name === name) as { title: string, icon: React.ReactNode };
const { title, icon, options } = schemaTypes.find(item => item.name === name) as { title: string, icon: React.ReactNode, options: { documentPreview?: boolean } };
const documentPreview = options?.documentPreview ?? false

return S.listItem()
.id(name)
.title(title)
Expand All @@ -18,7 +19,7 @@ export const createCollection = (S: StructureBuilder, name: string) => {
.schemaType(name)
.views([
S.view.form().title('Editor').icon(() => '🖋️'),
...(!TYPES_TO_EXCLUDE_PREVIEWS.includes(name) ? [
...(documentPreview ? [
S.view
.component(Preview)
.title('Preview')
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@

import type { StructureBuilder } from 'sanity/structure'
import { schemaTypes } from "./schema-types";
import { schemaTypes } from "../structure/schema-types";
import { Preview } from './preview';
import { TYPES_TO_EXCLUDE_PREVIEWS } from '.';

export const createSingleton = (S: StructureBuilder, name: string) => {
const { title, icon } = schemaTypes.find(item => item.name === name) as { title: string, icon: React.ReactNode };
const { title, icon, options } = schemaTypes.find(item => item.name === name) as { title: string, icon: React.ReactNode, options: { documentPreview?: boolean } };
const documentPreview = options?.documentPreview ?? false

return S.listItem()
.id(name)
.title(title)
Expand All @@ -17,7 +17,7 @@ export const createSingleton = (S: StructureBuilder, name: string) => {
.title(title)
.views([
S.view.form().title('Editor').icon(() => '🖋️'),
...(!TYPES_TO_EXCLUDE_PREVIEWS.includes(name) ? [
...(documentPreview ? [
S.view
.component(Preview)
.title('Preview')
Expand Down
File renamed without changes.

0 comments on commit 2bf3856

Please sign in to comment.