Skip to content

Commit

Permalink
change registerComment function to async
Browse files Browse the repository at this point in the history
  • Loading branch information
Vivek Patel committed May 12, 2022
1 parent f69094e commit 3e7f270
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/components/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3698,10 +3698,10 @@ class App extends React.Component<AppProps, AppState> {
);
}

private handleCommentElementOnPointerDown = (
private handleCommentElementOnPointerDown = async (
elementType: "comment",
pointerDownState: PointerDownState,
): void => {
): Promise<void> => {
if (!this.props.user) {
return;
}
Expand All @@ -3711,11 +3711,22 @@ class App extends React.Component<AppProps, AppState> {
this.state.gridSize,
);

const { x, y } = sceneCoordsToViewportCoords(
{
sceneX: gridX,
sceneY: gridY,
},
this.state,
);

const commentID = await this.props.registerComment(x, y);

const element = newCommentElement({
type: elementType,
x: gridX,
y: gridY,
owner: this.excalOwner,
commentID,
});

this.scene.replaceAllElements([
Expand Down
1 change: 1 addition & 0 deletions src/data/restore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ const restoreElement = (
case "comment":
return restoreElementWithProperties(element, {
owner: element.owner,
commentID: element.commentID,
});

// Don't use default case so as to catch a missing an element type case.
Expand Down
2 changes: 2 additions & 0 deletions src/element/newElement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ export const newCommentElement = (opts: {
x: number;
y: number;
owner: CommentOwner;
commentID: string;
}): NonDeleted<ExcalidrawCommentElement> => {
const height = 40;
const width = 40;
Expand All @@ -145,6 +146,7 @@ export const newCommentElement = (opts: {
roughness: 0,
}),
owner: opts.owner,
commentID: opts.commentID,
};
};

Expand Down
1 change: 1 addition & 0 deletions src/element/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ export type ExcalidrawFreeDrawElement = _ExcalidrawElementBase &
export type ExcalidrawCommentElement = _ExcalidrawElementBase &
Readonly<{
type: "comment";
commentID: string;
}> & { owner: CommentOwner };

export type FileId = string & { _brand: "FileId" };
4 changes: 4 additions & 0 deletions src/excalidraw-app/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -687,6 +687,10 @@ const ExcalidrawWrapper = () => {
color: "#00ff",
// image: "https://lh3.googleusercontent.com/a-/AOh14GhnBcE5G6gu8ZYjEanRJ4-SUNI7GLshrGuJfGoo=s96-c",
}}
registerComment={async (x, y) => {
// on backend createComment with x,y coords
return "";
}}
/>
{excalidrawAPI && (
<CollabWrapper
Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ export interface ExcalidrawProps {
}>,
) => void;
user?: UserProp;
registerComment: (canvasX: number, canvasY: number) => Promise<string>;
}

export type UserProp = Readonly<{
Expand Down

0 comments on commit 3e7f270

Please sign in to comment.