diff --git a/src/components/editor-loader.tsx b/src/components/editor-loader.tsx index 60940f74..227cb2e4 100644 --- a/src/components/editor-loader.tsx +++ b/src/components/editor-loader.tsx @@ -1,13 +1,25 @@ import { DefaultEditorLoader } from '@powerhousedao/design-system'; -import { ReactNode } from 'react'; +import { ComponentProps, ReactNode, useEffect, useState } from 'react'; -type Props = { +type Props = ComponentProps & { + loadingTimeout?: number; customEditorLoader?: ReactNode; }; export function EditorLoader(props: Props) { - const { customEditorLoader } = props; + const [showLoading, setShowLoading] = useState(false); + + // only shows the loader after some time has passed + useEffect(() => { + setTimeout(() => { + setShowLoading(true); + }, props.loadingTimeout ?? 200); + }, [props]); + + if (!showLoading) return null; + + const { customEditorLoader, ...defaultProps } = props; if (customEditorLoader) return <>{customEditorLoader}; - return ; + return ; } diff --git a/src/components/editors.tsx b/src/components/editors.tsx index d127fc69..d6ccf06e 100644 --- a/src/components/editors.tsx +++ b/src/components/editors.tsx @@ -151,7 +151,10 @@ export function DocumentEditor(props: EditorProps) { } if (isLoadingDocument || isLoadingEditor) { - return ; + const message = isLoadingDocument + ? 'Loading document' + : 'Loading editor'; + return ; } if (selectedNode?.kind !== FILE) {