import clsx from "clsx"; import { CaptureUpdateAction } from "@excalidraw/element"; import { invariant } from "@excalidraw/common"; import { getClientColor } from "../clients"; import { Avatar } from "../components/Avatar"; import { eyeIcon, microphoneIcon, microphoneMutedIcon, } from "../components/icons"; import { t } from "../i18n"; import { register } from "./register"; import type { GoToCollaboratorComponentProps } from "../components/UserList"; import type { Collaborator } from "../types"; export const actionGoToCollaborator = register({ name: "goToCollaborator", label: "Go to a collaborator", viewMode: true, trackEvent: { category: "collab" }, perform: (_elements, appState, collaborator, app) => { invariant( collaborator, "actionGoToCollaborator: collaborator should be defined when actionGoToCollaborator is called", ); if ( !collaborator.socketId || app.props.userToFollow?.socketId === collaborator.socketId || collaborator.isCurrentUser ) { app.requestUnfollow(); return { appState, captureUpdate: CaptureUpdateAction.EVENTUALLY, }; } app.emitUserFollowIntent({ userToFollow: { socketId: collaborator.socketId, username: collaborator.username || "", }, action: "FOLLOW", }); return { appState: { ...appState, // Close mobile menu openMenu: appState.openMenu === "canvas" ? null : appState.openMenu, }, captureUpdate: CaptureUpdateAction.EVENTUALLY, }; }, PanelComponent: ({ updateData, data, appState }) => { const { socketId, collaborator, withName, isBeingFollowed } = data as GoToCollaboratorComponentProps; const background = getClientColor(socketId, collaborator); const statusClassNames = clsx({ "is-followed": isBeingFollowed, "is-current-user": collaborator.isCurrentUser === true, "is-speaking": collaborator.isSpeaking, "is-in-call": collaborator.isInCall, "is-muted": collaborator.isMuted, }); const statusIconJSX = collaborator.isInCall ? ( collaborator.isSpeaking ? (
) : collaborator.isMuted ? (
{microphoneMutedIcon}
) : (
{microphoneIcon}
) ) : null; return withName ? (
updateData(collaborator) } > {}} name={collaborator.username || ""} src={collaborator.avatarUrl} className={statusClassNames} />
{collaborator.username}
{isBeingFollowed && (
{eyeIcon}
)} {collaborator.isCurrentUser && ` (${t("labels.you")})`} {statusIconJSX}
) : (
{ updateData(collaborator); }} name={collaborator.username || ""} src={collaborator.avatarUrl} className={statusClassNames} /> {statusIconJSX && (
{statusIconJSX}
)}
); }, });