Skip to content

Commit

Permalink
fix(structure): use correct loading messages while resolving panes (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
rexxars authored and hermanwikner committed Mar 21, 2024
1 parent 798c58e commit 418e78a
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
19 changes: 19 additions & 0 deletions packages/sanity/src/structure/__workshop__/LoadingPaneStory.tsx
@@ -0,0 +1,19 @@
import {Card, Stack, Text} from '@sanity/ui'

import {PaneLayout} from '../components'
import {LoadingPane} from '../panes'

export default function LoadingPaneStory() {
return (
<Stack space={3}>
<Card padding={4} tone="positive">
<Text align="center">
Note: This is <em>intentionally</em> not resolving. We're testing the loading pane!
</Text>
</Card>
<PaneLayout height="fill">
<LoadingPane paneKey="loading" />
</PaneLayout>
</Stack>
)
}
5 changes: 5 additions & 0 deletions packages/sanity/src/structure/__workshop__/index.ts
Expand Up @@ -15,5 +15,10 @@ export default defineScope({
title: 'Document state',
component: lazy(() => import('./DocumentStateStory')),
},
{
name: 'loading-pane',
title: 'Loading pane',
component: lazy(() => import('./LoadingPaneStory')),
},
],
})
4 changes: 2 additions & 2 deletions packages/sanity/src/structure/panes/loading/LoadingPane.tsx
Expand Up @@ -61,12 +61,12 @@ export const LoadingPane = memo((props: LoadingPaneProps) => {

const [currentMessage, setCurrentMessage] = useState<string | null>(() => {
if (typeof resolvedMessage === 'string') return resolvedMessage
return DEFAULT_MESSAGE_KEY
return t(DEFAULT_MESSAGE_KEY)
})

useEffect(() => {
if (typeof resolvedMessage !== 'object') return undefined
if (typeof resolvedMessage.subscribe === 'function') return undefined
if (typeof resolvedMessage.subscribe !== 'function') return undefined

const sub = resolvedMessage.subscribe((message) => {
setCurrentMessage('messageKey' in message ? t(message.messageKey) : message.message)
Expand Down

0 comments on commit 418e78a

Please sign in to comment.