Skip to content

Commit

Permalink
chore(preview): improve naming/readability
Browse files Browse the repository at this point in the history
  • Loading branch information
bjoerge committed Sep 30, 2024
1 parent aaedba7 commit 39110e8
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions packages/sanity/src/core/preview/useValuePreview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,13 @@ interface State {
const INITIAL_STATE: State = {
isLoading: true,
}
const PENDING_STATE: State = {

const IDLE_STATE: State = {
isLoading: false,
value: {
title: undefined,
description: undefined,
},
}
/**
* @internal
Expand All @@ -33,7 +38,8 @@ function useDocumentPreview(props: {
const {enabled = true, ordering, schemaType, value: previewValue} = props || {}
const {observeForPreview} = useDocumentPreviewStore()
const observable = useMemo<Observable<State>>(() => {
if (!enabled || !previewValue || !schemaType) return of(PENDING_STATE)
// this will render previews as "loaded" (i.e. not in loading state) – typically with "Untitled" text
if (!enabled || !previewValue || !schemaType) return of(IDLE_STATE)

return observeForPreview(previewValue as Previewable, schemaType, {
viewOptions: {ordering: ordering},
Expand Down

0 comments on commit 39110e8

Please sign in to comment.