View Dereference.tsx
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
import {useState, useEffect, useCallback} from 'react' | |
import {useToast, Card, Button, Stack, Text, Code} from '@sanity/ui' | |
import {extractWithPath} from '@sanity/mutator' | |
import { | |
Preview, | |
DocumentActionProps, | |
SanityDocument, | |
useClient, | |
useSchema, | |
pathToString, |
View createAndScheduleArticle.js
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
/** | |
* Create a single `article` document as a draft | |
* and Schedule it to be published in 2025 | |
* | |
* Save this file to the root of your Studio and run with: | |
* sanity exec createAndScheduleArticle.js --with-user-token | |
*/ | |
import sanityClient from 'part:@sanity/base/client' | |
import {uuid} from '@sanity/uuid' |
View getUniqueFieldPaths.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
function getInnerFieldTypeNames(of = []) { | |
if (!of?.find((field) => field.fields)) { | |
return `` | |
} | |
const arrayObjectTypeNames = of.map((field) => field.name) | |
return arrayObjectTypeNames.join(`|`) | |
} |
View TemplatePopulator.tsx
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
// Add to your schema like... | |
// {name: `pageBuilderTemplatePopulator`, type: `string`, inputComponent: TemplatePopulator}, | |
import {Button, Grid} from '@sanity/ui' | |
import React, {useCallback, useState} from 'react' | |
import sanityClient from 'part:@sanity/base/client' | |
const client = sanityClient.withConfig({apiVersion: `2021-05-19`}) | |
const contentData = [ |
View CustomPreview.tsx
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
import React from 'react' | |
import {Text, Spinner, Card} from '@sanity/ui' | |
import Preview from 'part:@sanity/base/preview' | |
import schema from 'part:@sanity/base/schema' | |
import useListeningQuery from './useListeningQuery' | |
export default function CustomPreview(props) { | |
const {id} = props |
View ReferenceCustomSearch.jsx
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 is a Custom Input POC for a Reference field with defined search parameters on the target document | |
* The built-in reference field currently can filter results but only statically, not using the search query | |
* | |
* This custom input is NOT recommended as it lacks some of the amazing features of the built-in refernce field | |
* It's also a bit wonky in terms of the UI, but it's a start | |
* But it does solve this one specific use case | |
*/ | |
import React from 'react' |
View useListeningQuery.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
import React, {useEffect, useState, useRef} from 'react' | |
import documentStore from 'part:@sanity/base/datastore/document' | |
import {catchError, distinctUntilChanged} from 'rxjs/operators' | |
import isEqual from 'react-fast-compare' | |
type Params = Record<string, string | number | boolean | string[]> | |
interface ListenQueryOptions { | |
tag?: string | |
apiVersion?: string |
View CopyToMarket.jsx
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
/* eslint-disable react/prop-types */ | |
/* eslint-disable react/jsx-no-bind */ | |
import React, {useState, useCallback, useMemo} from 'react' | |
import {SearchIcon, ArrowRightIcon} from '@sanity/icons' | |
import {useToast, Text, Flex, Box, Button, Autocomplete, Label, Stack} from '@sanity/ui' | |
import sanityClient from 'part:@sanity/base/client' | |
export const MARKETS = [ | |
{ | |
name: `DE`, |
View write-nextjs-redirect.js
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
const sanityClient = require('@sanity/client') | |
const fs = require('fs') | |
const client = sanityClient({ | |
apiVersion: '2021-04-01', | |
dataset: `XXX`, | |
projectId: `XXX`, | |
useCdn: true, | |
}) |
View market-separated-desk-structure.js
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
import React from 'react' | |
import S from '@sanity/desk-tool/structure-builder' | |
import schema from 'part:@sanity/base/schema' | |
import userStore from 'part:@sanity/base/user' | |
// npm i pluralize | |
import pluralize from 'pluralize' | |
// BYO "Flag" component for an Icon | |
// import Flag from '../components/Flag/index' |
NewerOlder