forked from acaldas/document-model-electron
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: only show editor loader for slow documents
- Loading branch information
Showing
2 changed files
with
20 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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} />; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters