Skip to content

Commit

Permalink
fix: show only after editor loads
Browse files Browse the repository at this point in the history
  • Loading branch information
Palanikannan1437 committed Sep 17, 2024
1 parent 448a615 commit cd29430
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 4 deletions.
5 changes: 3 additions & 2 deletions packages/editor/src/core/hooks/use-collaborative-editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export const useCollaborativeEditor = (props: TCollaborativeEditorProps) => {
user,
} = props;
// initialize Hocuspocus provider
console.log("afdafd");
const provider = useMemo(
() =>
new HocuspocusProvider({
Expand All @@ -44,8 +45,8 @@ export const useCollaborativeEditor = (props: TCollaborativeEditorProps) => {
if (data.event.code === 1006) serverHandler?.onServerError?.();
},
onSynced: () => {
console.log("ran", id);
provider.sendStateless("Hello from client");
console.log("ran");
serverHandler?.onSynced?.();
},
}),
[id, realtimeConfig, serverHandler, user.id]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export const useReadOnlyCollaborativeEditor = (props: TReadOnlyCollaborativeEdit
user,
} = props;
// initialize Hocuspocus provider
console.log("afdafd read only");
const provider = useMemo(
() =>
new HocuspocusProvider({
Expand All @@ -33,7 +34,8 @@ export const useReadOnlyCollaborativeEditor = (props: TReadOnlyCollaborativeEdit
if (data.event.code === 1006) serverHandler?.onServerError?.();
},
onSynced: () => {
console.log("ran", id);
console.log("ran");
serverHandler?.onSynced?.();
},
}),
[id, realtimeConfig, serverHandler, user.id]
Expand Down
1 change: 1 addition & 0 deletions packages/editor/src/core/types/collaboration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
export type TServerHandler = {
onConnect?: () => void;
onServerError?: () => void;
onSynced?: () => void;
};

type TCollaborativeEditorHookProps = {
Expand Down
13 changes: 12 additions & 1 deletion web/core/components/pages/editor/editor-body.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useCallback, useEffect, useMemo } from "react";
import { useCallback, useEffect, useMemo, useState } from "react";
import { observer } from "mobx-react";
import { useParams } from "next/navigation";
// document-editor
Expand Down Expand Up @@ -60,6 +60,9 @@ export const PageEditorBody: React.FC<Props> = observer((props) => {
sidePeekVisible,
updateMarkings,
} = props;
// states
const [isSynced, setIsSynced] = useState(false);

// router
const { workspaceSlug, projectId } = useParams();
// store hooks
Expand Down Expand Up @@ -108,10 +111,16 @@ export const PageEditorBody: React.FC<Props> = observer((props) => {
handleConnectionStatus(true);
}, []);

const handleServerSynced = useCallback(() => {
console.log("handleServerSynced called");
setIsSynced(true);
}, []);

const serverHandler: TServerHandler = useMemo(
() => ({
onConnect: handleServerConnect,
onServerError: handleServerError,
onSynced: handleServerSynced,
}),
[]
);
Expand All @@ -132,6 +141,8 @@ export const PageEditorBody: React.FC<Props> = observer((props) => {
[projectId, workspaceSlug]
);

console.log("isSynced", isSynced);

if (pageId === undefined) return <PageContentLoader />;

return (
Expand Down

0 comments on commit cd29430

Please sign in to comment.