Skip to content

Commit

Permalink
feat: only show editor loader for slow documents
Browse files Browse the repository at this point in the history
  • Loading branch information
acaldas committed Sep 12, 2024
1 parent 0a79acc commit 500e23b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
20 changes: 16 additions & 4 deletions src/components/editor-loader.tsx
Original file line number Diff line number Diff line change
@@ -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<typeof DefaultEditorLoader> & {
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 <DefaultEditorLoader />;
return <DefaultEditorLoader {...defaultProps} />;
}
5 changes: 4 additions & 1 deletion src/components/editors.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,10 @@ export function DocumentEditor(props: EditorProps) {
}

if (isLoadingDocument || isLoadingEditor) {
return <EditorLoader />;
const message = isLoadingDocument
? 'Loading document'
: 'Loading editor';
return <EditorLoader message={message} />;
}

if (selectedNode?.kind !== FILE) {
Expand Down

0 comments on commit 500e23b

Please sign in to comment.