diff --git a/src/actions/actionNavigate.tsx b/src/actions/actionNavigate.tsx index 8b3b94e0d..c9388db75 100644 --- a/src/actions/actionNavigate.tsx +++ b/src/actions/actionNavigate.tsx @@ -16,7 +16,7 @@ export const actionGoToCollaborator = register({ return { appState, commitToHistory: false }; } - if (appState.userToFollow === _value.clientId) { + if (appState.userToFollow?.clientId === _value.clientId) { return { appState: { ...appState, @@ -29,9 +29,10 @@ export const actionGoToCollaborator = register({ return { appState: { ...appState, - // TODO follow-participant - // maybe store more data other than just the clientId - userToFollow: _value.clientId, + userToFollow: { + clientId: _value.clientId, + username: _value.username || "", + }, ...centerScrollOn({ scenePoint: point, viewportDimensions: { @@ -57,7 +58,7 @@ export const actionGoToCollaborator = register({ onClick={() => updateData({ ...collaborator, clientId })} name={collaborator.username || ""} src={collaborator.avatarUrl} - isBeingFollowed={appState.userToFollow === clientId} + isBeingFollowed={appState.userToFollow?.clientId === clientId} /> ); }, diff --git a/src/components/App.tsx b/src/components/App.tsx index 3cc0e61d0..97a4ba649 100644 --- a/src/components/App.tsx +++ b/src/components/App.tsx @@ -548,9 +548,19 @@ class App extends React.Component { } = this.state; const canvasWidth = canvasDOMWidth * canvasScale; const canvasHeight = canvasDOMHeight * canvasScale; + + const userToFollow = this.state.userToFollow; + if (viewModeEnabled) { return ( - + { + this.setState({ userToFollow: null }); + }} + > { ); } return ( - + { + this.setState({ userToFollow: null }); + }} + > void; } -const FollowMode = ({ children, height, width }: FollowModeProps) => { +const FollowMode = ({ + children, + height, + width, + userToFollow, + onDisconnect, +}: FollowModeProps) => { + if (!userToFollow) { + return <>{children}; + } + return (
- Following Handsome Swan - +
+ Following{" "} + + {userToFollow.username} + +
+
{children} diff --git a/src/excalidraw-app/collab/Collab.tsx b/src/excalidraw-app/collab/Collab.tsx index 99e0d4d04..18cade315 100644 --- a/src/excalidraw-app/collab/Collab.tsx +++ b/src/excalidraw-app/collab/Collab.tsx @@ -543,7 +543,7 @@ class Collab extends PureComponent { decryptedData.payload.socketId; const _appState = this.excalidrawAPI.getAppState(); - if (_appState.userToFollow === socketId) { + if (_appState.userToFollow?.clientId === socketId) { const { appState } = zoomToFitBounds({ appState: _appState, bounds, diff --git a/src/types.ts b/src/types.ts index a55e1f519..5c214b4ca 100644 --- a/src/types.ts +++ b/src/types.ts @@ -98,6 +98,8 @@ export type LastActiveTool = export type SidebarName = string; export type SidebarTabName = string; +export type UserToFollow = { clientId: string; username: string }; + export type AppState = { contextMenu: { items: ContextMenuItems; @@ -224,7 +226,7 @@ export type AppState = { showHyperlinkPopup: false | "info" | "editor"; selectedLinearElement: LinearElementEditor | null; /** the user's clientId who is being followed on the canvas */ - userToFollow: string | null; + userToFollow: UserToFollow | null; /** whether follow mode should be disconnected when the non-remote user interacts with the canvas */ shouldDisconnectFollowModeOnCanvasInteraction: boolean; };