Skip to content

Commit

Permalink
refactor(structure): add timeout to reconnecting message (#7531)
Browse files Browse the repository at this point in the history
* refactor(structure): add timeout for reconnecting pane provider

* docs(structure): add comment

* refactor(structure): add timeout clean up

* chore(structure): update type

Co-authored-by: Bjørge Næss <bjoerge@gmail.com>

---------

Co-authored-by: Bjørge Næss <bjoerge@gmail.com>
  • Loading branch information
RitaDias and bjoerge authored Sep 24, 2024
1 parent 3593bf5 commit 9ab4086
Showing 1 changed file with 11 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -748,12 +748,18 @@ export const DocumentPaneProvider = memo((props: DocumentPaneProviderProps) => {
)

useEffect(() => {
let timeout: ReturnType<typeof setTimeout>
if (connectionState === 'reconnecting') {
pushToast({
id: 'sanity/structure/reconnecting',
status: 'warning',
title: t('panes.document-pane-provider.reconnecting.title'),
})
timeout = setTimeout(() => {
pushToast({
id: 'sanity/structure/reconnecting',
status: 'warning',
title: t('panes.document-pane-provider.reconnecting.title'),
})
}, 2000) // 2 seconds, we can iterate on the value
}
return () => {
if (timeout) clearTimeout(timeout)
}
}, [connectionState, pushToast, t])

Expand Down

0 comments on commit 9ab4086

Please sign in to comment.