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 sanityClient from 'part:@sanity/base/client' | |
const remoteURL = 'https://example.com' | |
const localURL = 'http://localhost:8000' | |
const previewURL = | |
window.location.hostname === 'localhost' ? localURL : remoteURL | |
export default function resolveProductionUrl (document) { | |
if (!document.slug) return null |
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 userStore from 'part:@sanity/base/user' | |
import { useEffect, useState } from 'react' | |
// Retrieves the current logged-in user details | |
export function useCurrentUser() { | |
const [user, setUser] = useState() | |
useEffect(() => { | |
userStore.currentUser.subscribe(e => setUser(e.user)) | |
}, []) |
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} from 'react' | |
import {randomKey} from '@sanity/util/content' | |
import sanityClient from 'part:@sanity/base/client' | |
const apiVersion = `2021-05-19` | |
const client = sanityClient.withConfig({apiVersion}) | |
export default function AnnotateAction({draft, published}) { | |
const [isAnnotating, setIsAnnotating] = useState(false) |
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 @next/next/no-img-element */ | |
import Head from 'next/head' | |
import PropTypes from 'prop-types' | |
import React, {useMemo} from 'react' | |
import {getImageDimensions} from '@sanity/asset-utils' | |
// eslint-disable-next-line import/no-cycle | |
import {urlFor} from '../lib/sanity' | |
function getImageDetails(image, width, height) { |
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 filteredObject = (name, filters = []) => ({ | |
name, | |
type: 'object', | |
fields: [ | |
{name: 'size', type: 'string', hidden: () => filters.includes('size')}, | |
{name: 'tone', type: 'string', hidden: () => filters.includes('tone')} | |
] | |
}) | |
export default { |
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
{ | |
name: 'slug', | |
title: 'Slug', | |
type: 'slug', | |
options: { | |
source: 'title', | |
isUnique: async (slug, options) => { | |
const {document: sanityDocument} = options | |
// Filter out additional parts of the _id to get the original |
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 no-negated-condition */ | |
/* eslint-disable react/prop-types */ | |
/* eslint-disable react/display-name */ | |
/* eslint-disable max-nested-callbacks */ | |
/** | |
* inputComponent drop-in replacement for `sanity-plugin-tabs` | |
* Provided as-is with no explicit or implied future support | |
* Addresses some UI issues with that plugin, but may introduce others | |
* |
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 { data, loading } = useListeningQuery( | |
query, | |
{ | |
params: params ?? {}, | |
initialData: page, | |
enabled: preview, | |
delay: 250, | |
} | |
); |
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 */ | |
/** | |
* 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 reference field | |
* It's also a bit wonky in terms of the UI, but it's a start | |
* ...and it does solve this one specific use case | |
*/ |
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
/** | |
* Custom Input that will resolve Sanity's default UI for field editing | |
* As well as display some contextual information from the document | |
* This is example is for an `array` field of `car` type fields | |
* For which the default UI is shown below an image from the first array item | |
* | |
* The implementation is *not* bulletproof and only has basic handling | |
* of the potential pitfalls of recursive rendering of the | |
* <FormBuilderInput /> component | |
*/ |
OlderNewer