Wired up follow styling with business logic.
This commit is contained in:
parent
1777b4566c
commit
898564bc2e
@ -16,7 +16,7 @@ export const actionGoToCollaborator = register({
|
|||||||
return { appState, commitToHistory: false };
|
return { appState, commitToHistory: false };
|
||||||
}
|
}
|
||||||
|
|
||||||
if (appState.userToFollow === _value.clientId) {
|
if (appState.userToFollow?.clientId === _value.clientId) {
|
||||||
return {
|
return {
|
||||||
appState: {
|
appState: {
|
||||||
...appState,
|
...appState,
|
||||||
@ -29,9 +29,10 @@ export const actionGoToCollaborator = register({
|
|||||||
return {
|
return {
|
||||||
appState: {
|
appState: {
|
||||||
...appState,
|
...appState,
|
||||||
// TODO follow-participant
|
userToFollow: {
|
||||||
// maybe store more data other than just the clientId
|
clientId: _value.clientId,
|
||||||
userToFollow: _value.clientId,
|
username: _value.username || "",
|
||||||
|
},
|
||||||
...centerScrollOn({
|
...centerScrollOn({
|
||||||
scenePoint: point,
|
scenePoint: point,
|
||||||
viewportDimensions: {
|
viewportDimensions: {
|
||||||
@ -57,7 +58,7 @@ export const actionGoToCollaborator = register({
|
|||||||
onClick={() => updateData({ ...collaborator, clientId })}
|
onClick={() => updateData({ ...collaborator, clientId })}
|
||||||
name={collaborator.username || ""}
|
name={collaborator.username || ""}
|
||||||
src={collaborator.avatarUrl}
|
src={collaborator.avatarUrl}
|
||||||
isBeingFollowed={appState.userToFollow === clientId}
|
isBeingFollowed={appState.userToFollow?.clientId === clientId}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
@ -548,9 +548,19 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
} = this.state;
|
} = this.state;
|
||||||
const canvasWidth = canvasDOMWidth * canvasScale;
|
const canvasWidth = canvasDOMWidth * canvasScale;
|
||||||
const canvasHeight = canvasDOMHeight * canvasScale;
|
const canvasHeight = canvasDOMHeight * canvasScale;
|
||||||
|
|
||||||
|
const userToFollow = this.state.userToFollow;
|
||||||
|
|
||||||
if (viewModeEnabled) {
|
if (viewModeEnabled) {
|
||||||
return (
|
return (
|
||||||
<FollowMode width={canvasDOMWidth} height={canvasDOMHeight}>
|
<FollowMode
|
||||||
|
width={canvasDOMWidth}
|
||||||
|
height={canvasDOMHeight}
|
||||||
|
userToFollow={userToFollow}
|
||||||
|
onDisconnect={() => {
|
||||||
|
this.setState({ userToFollow: null });
|
||||||
|
}}
|
||||||
|
>
|
||||||
<canvas
|
<canvas
|
||||||
className="excalidraw__canvas"
|
className="excalidraw__canvas"
|
||||||
style={{
|
style={{
|
||||||
@ -576,7 +586,14 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
return (
|
return (
|
||||||
<FollowMode width={canvasDOMWidth} height={canvasDOMHeight}>
|
<FollowMode
|
||||||
|
width={canvasDOMWidth}
|
||||||
|
height={canvasDOMHeight}
|
||||||
|
userToFollow={userToFollow}
|
||||||
|
onDisconnect={() => {
|
||||||
|
this.setState({ userToFollow: null });
|
||||||
|
}}
|
||||||
|
>
|
||||||
<canvas
|
<canvas
|
||||||
className="excalidraw__canvas"
|
className="excalidraw__canvas"
|
||||||
style={{
|
style={{
|
||||||
|
@ -20,6 +20,19 @@
|
|||||||
display: flex;
|
display: flex;
|
||||||
gap: 0.5rem;
|
gap: 0.5rem;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
|
|
||||||
|
&__label {
|
||||||
|
display: flex;
|
||||||
|
white-space: pre-wrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
&__username {
|
||||||
|
display: block;
|
||||||
|
white-space: nowrap;
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
max-width: 100px;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
&__disconnect-btn {
|
&__disconnect-btn {
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
import { UserToFollow } from "../../types";
|
||||||
import { CloseIcon } from "../icons";
|
import { CloseIcon } from "../icons";
|
||||||
import "./FollowMode.scss";
|
import "./FollowMode.scss";
|
||||||
|
|
||||||
@ -5,15 +6,40 @@ interface FollowModeProps {
|
|||||||
width: number;
|
width: number;
|
||||||
height: number;
|
height: number;
|
||||||
children: React.ReactNode;
|
children: React.ReactNode;
|
||||||
|
userToFollow?: UserToFollow | null;
|
||||||
|
onDisconnect: () => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
const FollowMode = ({ children, height, width }: FollowModeProps) => {
|
const FollowMode = ({
|
||||||
|
children,
|
||||||
|
height,
|
||||||
|
width,
|
||||||
|
userToFollow,
|
||||||
|
onDisconnect,
|
||||||
|
}: FollowModeProps) => {
|
||||||
|
if (!userToFollow) {
|
||||||
|
return <>{children}</>;
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div style={{ position: "relative" }}>
|
<div style={{ position: "relative" }}>
|
||||||
<div className="follow-mode" style={{ width, height }}>
|
<div className="follow-mode" style={{ width, height }}>
|
||||||
<div className="follow-mode__badge">
|
<div className="follow-mode__badge">
|
||||||
<span>Following Handsome Swan</span>
|
<div className="follow-mode__badge__label">
|
||||||
<button className="follow-mode__disconnect-btn">{CloseIcon}</button>
|
Following{" "}
|
||||||
|
<span
|
||||||
|
className="follow-mode__badge__username"
|
||||||
|
title={userToFollow.username}
|
||||||
|
>
|
||||||
|
{userToFollow.username}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<button
|
||||||
|
onClick={onDisconnect}
|
||||||
|
className="follow-mode__disconnect-btn"
|
||||||
|
>
|
||||||
|
{CloseIcon}
|
||||||
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{children}
|
{children}
|
||||||
|
@ -543,7 +543,7 @@ class Collab extends PureComponent<Props, CollabState> {
|
|||||||
decryptedData.payload.socketId;
|
decryptedData.payload.socketId;
|
||||||
|
|
||||||
const _appState = this.excalidrawAPI.getAppState();
|
const _appState = this.excalidrawAPI.getAppState();
|
||||||
if (_appState.userToFollow === socketId) {
|
if (_appState.userToFollow?.clientId === socketId) {
|
||||||
const { appState } = zoomToFitBounds({
|
const { appState } = zoomToFitBounds({
|
||||||
appState: _appState,
|
appState: _appState,
|
||||||
bounds,
|
bounds,
|
||||||
|
@ -98,6 +98,8 @@ export type LastActiveTool =
|
|||||||
export type SidebarName = string;
|
export type SidebarName = string;
|
||||||
export type SidebarTabName = string;
|
export type SidebarTabName = string;
|
||||||
|
|
||||||
|
export type UserToFollow = { clientId: string; username: string };
|
||||||
|
|
||||||
export type AppState = {
|
export type AppState = {
|
||||||
contextMenu: {
|
contextMenu: {
|
||||||
items: ContextMenuItems;
|
items: ContextMenuItems;
|
||||||
@ -224,7 +226,7 @@ export type AppState = {
|
|||||||
showHyperlinkPopup: false | "info" | "editor";
|
showHyperlinkPopup: false | "info" | "editor";
|
||||||
selectedLinearElement: LinearElementEditor | null;
|
selectedLinearElement: LinearElementEditor | null;
|
||||||
/** the user's clientId who is being followed on the canvas */
|
/** 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 */
|
/** whether follow mode should be disconnected when the non-remote user interacts with the canvas */
|
||||||
shouldDisconnectFollowModeOnCanvasInteraction: boolean;
|
shouldDisconnectFollowModeOnCanvasInteraction: boolean;
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user