follow zoom POC
This commit is contained in:
parent
9152ce24f2
commit
42a90def41
@ -1502,6 +1502,11 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
|
|
||||||
// TODO follow-participant
|
// TODO follow-participant
|
||||||
// add zoom change
|
// add zoom change
|
||||||
|
|
||||||
|
if (prevState.zoom.value !== this.state.zoom.value) {
|
||||||
|
this.props?.onZoomChange?.(this.state.zoom);
|
||||||
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
prevState.scrollX !== this.state.scrollX ||
|
prevState.scrollX !== this.state.scrollX ||
|
||||||
prevState.scrollY !== this.state.scrollY
|
prevState.scrollY !== this.state.scrollY
|
||||||
|
@ -90,6 +90,7 @@ export interface CollabAPI {
|
|||||||
isCollaborating: () => boolean;
|
isCollaborating: () => boolean;
|
||||||
onPointerUpdate: CollabInstance["onPointerUpdate"];
|
onPointerUpdate: CollabInstance["onPointerUpdate"];
|
||||||
onScrollChange: CollabInstance["onScrollChange"];
|
onScrollChange: CollabInstance["onScrollChange"];
|
||||||
|
onZoomChange: CollabInstance["onZoomChange"];
|
||||||
startCollaboration: CollabInstance["startCollaboration"];
|
startCollaboration: CollabInstance["startCollaboration"];
|
||||||
stopCollaboration: CollabInstance["stopCollaboration"];
|
stopCollaboration: CollabInstance["stopCollaboration"];
|
||||||
syncElements: CollabInstance["syncElements"];
|
syncElements: CollabInstance["syncElements"];
|
||||||
@ -164,6 +165,7 @@ class Collab extends PureComponent<Props, CollabState> {
|
|||||||
isCollaborating: this.isCollaborating,
|
isCollaborating: this.isCollaborating,
|
||||||
onPointerUpdate: this.onPointerUpdate,
|
onPointerUpdate: this.onPointerUpdate,
|
||||||
onScrollChange: this.onScrollChange,
|
onScrollChange: this.onScrollChange,
|
||||||
|
onZoomChange: this.onZoomChange,
|
||||||
startCollaboration: this.startCollaboration,
|
startCollaboration: this.startCollaboration,
|
||||||
syncElements: this.syncElements,
|
syncElements: this.syncElements,
|
||||||
fetchImageFilesFromFirebase: this.fetchImageFilesFromFirebase,
|
fetchImageFilesFromFirebase: this.fetchImageFilesFromFirebase,
|
||||||
@ -542,7 +544,7 @@ class Collab extends PureComponent<Props, CollabState> {
|
|||||||
// case "ZOOM_VALUE"
|
// case "ZOOM_VALUE"
|
||||||
// if following someone, update scroll and zoom
|
// if following someone, update scroll and zoom
|
||||||
|
|
||||||
case "SCROLL_LOCATION":
|
case "SCROLL_LOCATION": {
|
||||||
const {
|
const {
|
||||||
scroll: { x, y },
|
scroll: { x, y },
|
||||||
} = decryptedData.payload;
|
} = decryptedData.payload;
|
||||||
@ -565,6 +567,26 @@ class Collab extends PureComponent<Props, CollabState> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case "ZOOM_VALUE": {
|
||||||
|
const { zoom } = decryptedData.payload;
|
||||||
|
|
||||||
|
console.log({ decryptedData });
|
||||||
|
|
||||||
|
const socketId: SocketUpdateDataSource["ZOOM_VALUE"]["payload"]["socketId"] =
|
||||||
|
decryptedData.payload.socketId;
|
||||||
|
|
||||||
|
const appState = this.excalidrawAPI.getAppState();
|
||||||
|
|
||||||
|
if (appState.userToFollow === socketId) {
|
||||||
|
this.excalidrawAPI.updateScene({
|
||||||
|
appState: { zoom },
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case "IDLE_STATUS": {
|
case "IDLE_STATUS": {
|
||||||
const { userState, socketId, username } = decryptedData.payload;
|
const { userState, socketId, username } = decryptedData.payload;
|
||||||
@ -806,6 +828,14 @@ class Collab extends PureComponent<Props, CollabState> {
|
|||||||
// - onZoomChange
|
// - onZoomChange
|
||||||
// -- broadCastZoomValue
|
// -- broadCastZoomValue
|
||||||
|
|
||||||
|
onZoomChange = throttle(
|
||||||
|
(payload: {
|
||||||
|
zoom: SocketUpdateDataSource["ZOOM_VALUE"]["payload"]["zoom"];
|
||||||
|
}) => {
|
||||||
|
this.portal.socket && this.portal.broadcastZoomValue(payload);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
onScrollChange = throttle(
|
onScrollChange = throttle(
|
||||||
(payload: {
|
(payload: {
|
||||||
scrollX: SocketUpdateDataSource["SCROLL_LOCATION"]["payload"]["scroll"]["x"];
|
scrollX: SocketUpdateDataSource["SCROLL_LOCATION"]["payload"]["scroll"]["x"];
|
||||||
|
@ -249,6 +249,28 @@ class Portal {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
broadcastZoomValue = (payload: {
|
||||||
|
zoom: SocketUpdateDataSource["ZOOM_VALUE"]["payload"]["zoom"];
|
||||||
|
}) => {
|
||||||
|
if (this.socket?.id) {
|
||||||
|
const data: SocketUpdateDataSource["ZOOM_VALUE"] = {
|
||||||
|
type: "ZOOM_VALUE",
|
||||||
|
payload: {
|
||||||
|
socketId: this.socket.id,
|
||||||
|
zoom: payload.zoom,
|
||||||
|
username: this.collab.state.username,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
console.log("broadcastZoomValue data", data);
|
||||||
|
|
||||||
|
return this._broadcastSocketData(
|
||||||
|
data as SocketUpdateData,
|
||||||
|
true, // volatile
|
||||||
|
);
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export default Portal;
|
export default Portal;
|
||||||
|
@ -121,6 +121,14 @@ export type SocketUpdateDataSource = {
|
|||||||
username: string;
|
username: string;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
ZOOM_VALUE: {
|
||||||
|
type: "ZOOM_VALUE";
|
||||||
|
payload: {
|
||||||
|
socketId: string;
|
||||||
|
zoom: AppState["zoom"];
|
||||||
|
username: string;
|
||||||
|
};
|
||||||
|
};
|
||||||
IDLE_STATUS: {
|
IDLE_STATUS: {
|
||||||
type: "IDLE_STATUS";
|
type: "IDLE_STATUS";
|
||||||
payload: {
|
payload: {
|
||||||
|
@ -651,6 +651,10 @@ const ExcalidrawWrapper = () => {
|
|||||||
<Excalidraw
|
<Excalidraw
|
||||||
// TODO follow-participant
|
// TODO follow-participant
|
||||||
// add onZoomChange
|
// add onZoomChange
|
||||||
|
onZoomChange={(zoom) => {
|
||||||
|
console.log({ zoom });
|
||||||
|
collabAPI?.onZoomChange({ zoom });
|
||||||
|
}}
|
||||||
onScrollChange={(x, y) => {
|
onScrollChange={(x, y) => {
|
||||||
// console.log({ x, y });
|
// console.log({ x, y });
|
||||||
|
|
||||||
|
@ -41,6 +41,7 @@ const ExcalidrawBase = (props: ExcalidrawProps) => {
|
|||||||
onLinkOpen,
|
onLinkOpen,
|
||||||
onPointerDown,
|
onPointerDown,
|
||||||
onScrollChange,
|
onScrollChange,
|
||||||
|
onZoomChange,
|
||||||
children,
|
children,
|
||||||
} = props;
|
} = props;
|
||||||
|
|
||||||
@ -115,6 +116,7 @@ const ExcalidrawBase = (props: ExcalidrawProps) => {
|
|||||||
onLinkOpen={onLinkOpen}
|
onLinkOpen={onLinkOpen}
|
||||||
onPointerDown={onPointerDown}
|
onPointerDown={onPointerDown}
|
||||||
onScrollChange={onScrollChange}
|
onScrollChange={onScrollChange}
|
||||||
|
onZoomChange={onZoomChange}
|
||||||
>
|
>
|
||||||
{children}
|
{children}
|
||||||
</App>
|
</App>
|
||||||
|
@ -361,6 +361,7 @@ export interface ExcalidrawProps {
|
|||||||
pointerDownState: PointerDownState,
|
pointerDownState: PointerDownState,
|
||||||
) => void;
|
) => void;
|
||||||
onScrollChange?: (scrollX: number, scrollY: number) => void;
|
onScrollChange?: (scrollX: number, scrollY: number) => void;
|
||||||
|
onZoomChange?: (zoom: Zoom) => void;
|
||||||
children?: React.ReactNode;
|
children?: React.ReactNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user