Implemented some TODOs.
This commit is contained in:
parent
a576b0e3b5
commit
b4867cb3dc
@ -100,6 +100,7 @@ export const getDefaultAppState = (): Omit<
|
|||||||
selectedLinearElement: null,
|
selectedLinearElement: null,
|
||||||
userToFollow: null,
|
userToFollow: null,
|
||||||
shouldDisconnectFollowModeOnCanvasInteraction: true,
|
shouldDisconnectFollowModeOnCanvasInteraction: true,
|
||||||
|
amIBeingFollowed: false,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -212,6 +213,7 @@ const APP_STATE_STORAGE_CONF = (<
|
|||||||
export: false,
|
export: false,
|
||||||
server: false,
|
server: false,
|
||||||
},
|
},
|
||||||
|
amIBeingFollowed: { browser: false, export: false, server: false },
|
||||||
});
|
});
|
||||||
|
|
||||||
const _clearAppStateForStorage = <
|
const _clearAppStateForStorage = <
|
||||||
|
@ -1543,14 +1543,14 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
if (prevState.userToFollow) {
|
if (prevState.userToFollow) {
|
||||||
this.props?.onUserFollowed?.({
|
this.props?.onUserFollowed?.({
|
||||||
userToFollow: prevState.userToFollow,
|
userToFollow: prevState.userToFollow,
|
||||||
action: "unsubscribe",
|
action: "unfollow",
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.state.userToFollow) {
|
if (this.state.userToFollow) {
|
||||||
this.props?.onUserFollowed?.({
|
this.props?.onUserFollowed?.({
|
||||||
userToFollow: this.state.userToFollow,
|
userToFollow: this.state.userToFollow,
|
||||||
action: "subscribe",
|
action: "follow",
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,10 @@
|
|||||||
import throttle from "lodash.throttle";
|
import throttle from "lodash.throttle";
|
||||||
import { PureComponent } from "react";
|
import { PureComponent } from "react";
|
||||||
import { AppState, ExcalidrawImperativeAPI, UserToFollow } from "../../types";
|
import {
|
||||||
|
AppState,
|
||||||
|
ExcalidrawImperativeAPI,
|
||||||
|
OnUserFollowedPayload,
|
||||||
|
} from "../../types";
|
||||||
import { ErrorDialog } from "../../components/ErrorDialog";
|
import { ErrorDialog } from "../../components/ErrorDialog";
|
||||||
import { APP_NAME, ENV, EVENT } from "../../constants";
|
import { APP_NAME, ENV, EVENT } from "../../constants";
|
||||||
import { ImportedDataState } from "../../data/types";
|
import { ImportedDataState } from "../../data/types";
|
||||||
@ -541,12 +545,8 @@ class Collab extends PureComponent<Props, CollabState> {
|
|||||||
case "SCROLL_AND_ZOOM": {
|
case "SCROLL_AND_ZOOM": {
|
||||||
const { bounds } = decryptedData.payload;
|
const { bounds } = decryptedData.payload;
|
||||||
|
|
||||||
const socketId: SocketUpdateDataSource["SCROLL_AND_ZOOM"]["payload"]["socketId"] =
|
|
||||||
decryptedData.payload.socketId;
|
|
||||||
|
|
||||||
const _appState = this.excalidrawAPI.getAppState();
|
const _appState = this.excalidrawAPI.getAppState();
|
||||||
// TODO follow-participant
|
|
||||||
// if (_appState.userToFollow?.clientId === socketId) {
|
|
||||||
const { appState } = zoomToFitBounds({
|
const { appState } = zoomToFitBounds({
|
||||||
appState: _appState,
|
appState: _appState,
|
||||||
bounds,
|
bounds,
|
||||||
@ -554,7 +554,6 @@ class Collab extends PureComponent<Props, CollabState> {
|
|||||||
viewportZoomFactor: 1,
|
viewportZoomFactor: 1,
|
||||||
});
|
});
|
||||||
this.excalidrawAPI.updateScene({ appState });
|
this.excalidrawAPI.updateScene({ appState });
|
||||||
// }
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -585,15 +584,16 @@ class Collab extends PureComponent<Props, CollabState> {
|
|||||||
scenePromise.resolve(sceneData);
|
scenePromise.resolve(sceneData);
|
||||||
});
|
});
|
||||||
|
|
||||||
// TODO follow-participant
|
|
||||||
// set amIBeingFollowed flag
|
|
||||||
this.portal.socket.on("broadcast-follow", () => {
|
this.portal.socket.on("broadcast-follow", () => {
|
||||||
console.log("broadcast-follow");
|
this.excalidrawAPI.updateScene({
|
||||||
|
appState: { amIBeingFollowed: true },
|
||||||
|
});
|
||||||
});
|
});
|
||||||
// TODO follow-participant
|
|
||||||
// set amIBeingFollowed flag
|
|
||||||
this.portal.socket.on("broadcast-unfollow", () => {
|
this.portal.socket.on("broadcast-unfollow", () => {
|
||||||
console.log("broadcast-unfollow");
|
this.excalidrawAPI.updateScene({
|
||||||
|
appState: { amIBeingFollowed: false },
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
this.initializeIdleDetector();
|
this.initializeIdleDetector();
|
||||||
@ -803,48 +803,44 @@ class Collab extends PureComponent<Props, CollabState> {
|
|||||||
CURSOR_SYNC_TIMEOUT,
|
CURSOR_SYNC_TIMEOUT,
|
||||||
);
|
);
|
||||||
|
|
||||||
// TODO follow-participant
|
|
||||||
// only calculate this + broadcast if some flag on appState is set
|
|
||||||
// (eg amIBeingFollowed)
|
|
||||||
onScrollAndZoomChange = throttle(
|
onScrollAndZoomChange = throttle(
|
||||||
(payload: { zoom: AppState["zoom"]; scroll: { x: number; y: number } }) => {
|
(payload: { zoom: AppState["zoom"]; scroll: { x: number; y: number } }) => {
|
||||||
const appState = this.excalidrawAPI.getAppState();
|
const appState = this.excalidrawAPI.getAppState();
|
||||||
|
|
||||||
const { x: x1, y: y1 } = viewportCoordsToSceneCoords(
|
if (appState.amIBeingFollowed) {
|
||||||
{ clientX: 0, clientY: 0 },
|
const { x: x1, y: y1 } = viewportCoordsToSceneCoords(
|
||||||
{
|
{ clientX: 0, clientY: 0 },
|
||||||
offsetLeft: appState.offsetLeft,
|
{
|
||||||
offsetTop: appState.offsetTop,
|
offsetLeft: appState.offsetLeft,
|
||||||
scrollX: payload.scroll.x,
|
offsetTop: appState.offsetTop,
|
||||||
scrollY: payload.scroll.y,
|
scrollX: payload.scroll.x,
|
||||||
zoom: payload.zoom,
|
scrollY: payload.scroll.y,
|
||||||
},
|
zoom: payload.zoom,
|
||||||
);
|
},
|
||||||
|
|
||||||
const { x: x2, y: y2 } = viewportCoordsToSceneCoords(
|
|
||||||
{ clientX: appState.width, clientY: appState.height },
|
|
||||||
{
|
|
||||||
offsetLeft: appState.offsetLeft,
|
|
||||||
offsetTop: appState.offsetTop,
|
|
||||||
scrollX: payload.scroll.x,
|
|
||||||
scrollY: payload.scroll.y,
|
|
||||||
zoom: payload.zoom,
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
this.portal.socket &&
|
|
||||||
this.portal.broadcastScrollAndZoom(
|
|
||||||
{ bounds: [x1, y1, x2, y2] },
|
|
||||||
// TODO follow-participant
|
|
||||||
`follow_${this.portal.socket.id}`,
|
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const { x: x2, y: y2 } = viewportCoordsToSceneCoords(
|
||||||
|
{ clientX: appState.width, clientY: appState.height },
|
||||||
|
{
|
||||||
|
offsetLeft: appState.offsetLeft,
|
||||||
|
offsetTop: appState.offsetTop,
|
||||||
|
scrollX: payload.scroll.x,
|
||||||
|
scrollY: payload.scroll.y,
|
||||||
|
zoom: payload.zoom,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
this.portal.socket &&
|
||||||
|
this.portal.broadcastScrollAndZoom(
|
||||||
|
{ bounds: [x1, y1, x2, y2] },
|
||||||
|
// TODO follow-participant
|
||||||
|
`follow_${this.portal.socket.id}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
onUserFollowed = (payload: {
|
onUserFollowed = (payload: OnUserFollowedPayload) => {
|
||||||
userToFollow: UserToFollow;
|
|
||||||
action: "subscribe" | "unsubscribe";
|
|
||||||
}) => {
|
|
||||||
this.portal.socket && this.portal.broadcastUserFollowed(payload);
|
this.portal.socket && this.portal.broadcastUserFollowed(payload);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -12,7 +12,7 @@ import {
|
|||||||
FILE_UPLOAD_TIMEOUT,
|
FILE_UPLOAD_TIMEOUT,
|
||||||
WS_SCENE_EVENT_TYPES,
|
WS_SCENE_EVENT_TYPES,
|
||||||
} from "../app_constants";
|
} from "../app_constants";
|
||||||
import { UserIdleState, UserToFollow } from "../../types";
|
import { OnUserFollowedPayload, UserIdleState } from "../../types";
|
||||||
import { trackEvent } from "../../analytics";
|
import { trackEvent } from "../../analytics";
|
||||||
import throttle from "lodash.throttle";
|
import throttle from "lodash.throttle";
|
||||||
import { newElementWith } from "../../element/mutateElement";
|
import { newElementWith } from "../../element/mutateElement";
|
||||||
@ -248,10 +248,7 @@ class Portal {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
broadcastUserFollowed = (payload: {
|
broadcastUserFollowed = (payload: OnUserFollowedPayload) => {
|
||||||
userToFollow: UserToFollow;
|
|
||||||
action: "subscribe" | "unsubscribe";
|
|
||||||
}) => {
|
|
||||||
if (this.socket?.id) {
|
if (this.socket?.id) {
|
||||||
this.socket?.emit("on-user-follow", payload);
|
this.socket?.emit("on-user-follow", payload);
|
||||||
}
|
}
|
||||||
|
14
src/types.ts
14
src/types.ts
@ -229,6 +229,8 @@ export type AppState = {
|
|||||||
userToFollow: UserToFollow | null;
|
userToFollow: UserToFollow | null;
|
||||||
/** whether follow mode should be disconnected when the non-remote user interacts with the canvas */
|
/** whether follow mode should be disconnected when the non-remote user interacts with the canvas */
|
||||||
shouldDisconnectFollowModeOnCanvasInteraction: boolean;
|
shouldDisconnectFollowModeOnCanvasInteraction: boolean;
|
||||||
|
/** whether the user is being followed on the canvas */
|
||||||
|
amIBeingFollowed: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type UIAppState = Omit<
|
export type UIAppState = Omit<
|
||||||
@ -313,6 +315,11 @@ export type ExcalidrawInitialDataState = Merge<
|
|||||||
}
|
}
|
||||||
>;
|
>;
|
||||||
|
|
||||||
|
export type OnUserFollowedPayload = {
|
||||||
|
userToFollow: UserToFollow;
|
||||||
|
action: "follow" | "unfollow";
|
||||||
|
};
|
||||||
|
|
||||||
export interface ExcalidrawProps {
|
export interface ExcalidrawProps {
|
||||||
onChange?: (
|
onChange?: (
|
||||||
elements: readonly ExcalidrawElement[],
|
elements: readonly ExcalidrawElement[],
|
||||||
@ -373,12 +380,7 @@ export interface ExcalidrawProps {
|
|||||||
zoom: Zoom;
|
zoom: Zoom;
|
||||||
scroll: { x: number; y: number };
|
scroll: { x: number; y: number };
|
||||||
}) => void;
|
}) => void;
|
||||||
// TODO follow-participant
|
onUserFollowed?: (payload: OnUserFollowedPayload) => void;
|
||||||
onUserFollowed?: (payload: {
|
|
||||||
userToFollow: UserToFollow;
|
|
||||||
// TODO follow-participant extract to own type
|
|
||||||
action: "subscribe" | "unsubscribe";
|
|
||||||
}) => void;
|
|
||||||
children?: React.ReactNode;
|
children?: React.ReactNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user