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 cfdfa01 commit ff6b7d8
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 25 deletions.
20 changes: 10 additions & 10 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
"xvfb-maybe": "^0.2.1"
},
"dependencies": {
"@powerhousedao/design-system": "^1.0.0-alpha.167",
"@powerhousedao/design-system": "^1.0.0-alpha.168",
"@sentry/react": "^7.109.0",
"@sentry/vite-plugin": "^2.22.2",
"@tanstack/react-virtual": "^3.8.1",
Expand Down
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} />;
}
14 changes: 6 additions & 8 deletions src/components/editors.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export function DocumentEditor(props: EditorProps) {
initialDocument,
);
const context: EditorContext = useMemo(
() => ({ theme, user: user }),
() => ({ theme, user }),
[theme, user],
);
const userPermissions = useUserPermissions();
Expand Down Expand Up @@ -151,20 +151,18 @@ 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) {
return null;
}

if (!documentModel) {
return (
<h3>
Document of type {fileNodeDocument?.documentType} is not
supported.
</h3>
);
return <h3>Document of type {documentType} is not supported.</h3>;
}

if (!editor) {
Expand Down
4 changes: 2 additions & 2 deletions src/hooks/useDocumentDriveServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -512,8 +512,8 @@ export function useDocumentDriveServer(
);

const deleteDrive = useCallback(
async (id: string, force = false) => {
if (!force && !isAllowedToCreateDocuments) {
async (id: string) => {
if (!isAllowedToCreateDocuments) {
throw new Error('User is not allowed to delete drives');
}
if (!server) {
Expand Down

0 comments on commit ff6b7d8

Please sign in to comment.