Skip to content

Commit

Permalink
refactor(structure): send in useDocumentPane info as props vs fetchin…
Browse files Browse the repository at this point in the history
…g them again
  • Loading branch information
RitaDias committed Sep 23, 2024
1 parent 37ad4f7 commit 3b777cd
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,13 @@ export const DocumentPanel = function DocumentPanel(props: DocumentPanelProps) {
scrollElement={documentScrollElement}
containerElement={formContainerElement}
>
{activeView.type === 'form' && isLiveEdit && ready && <DraftLiveEditBanner />}
{activeView.type === 'form' && isLiveEdit && ready && (
<DraftLiveEditBanner
displayed={displayed}
documentId={documentId}
schemaType={schemaType}
/>
)}

{activeView.type === 'form' && !isPermissionsLoading && ready && (
<>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,35 @@
import {type SanityDocument} from '@sanity/client'
import {ErrorOutlineIcon} from '@sanity/icons'
import {useTelemetry} from '@sanity/telemetry/react'
import {Flex, Text} from '@sanity/ui'
import {useCallback, useEffect, useState} from 'react'
import {isDraftId, Translate, useDocumentOperation, useTranslation} from 'sanity'
import {
isDraftId,
type ObjectSchemaType,
Translate,
useDocumentOperation,
useTranslation,
} from 'sanity'

import {Button} from '../../../../../ui-components'
import {structureLocaleNamespace} from '../../../../i18n'
import {useDocumentPane} from '../../useDocumentPane'
import {
DiscardedLiveEditDraft,
PublishedLiveEditDraft,
} from './__telemetry__/DraftLiveEditBanner.telemetry'
import {Banner} from './Banner'

export function DraftLiveEditBanner(): JSX.Element | null {
const {displayed, documentId, schemaType} = useDocumentPane()
interface DraftLiveEditBannerProps {
displayed: Partial<SanityDocument> | null
documentId: string
schemaType: ObjectSchemaType
}

export function DraftLiveEditBanner({
displayed,
documentId,
schemaType,
}: DraftLiveEditBannerProps): JSX.Element | null {
const {t} = useTranslation(structureLocaleNamespace)
const [isPublishing, setPublishing] = useState(false)
const [isDiscarding, setDiscarding] = useState(false)
Expand Down

0 comments on commit 3b777cd

Please sign in to comment.