You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
53 lines
1.4 KiB
TypeScript
53 lines
1.4 KiB
TypeScript
4 years ago
|
import "./UserList.scss";
|
||
5 years ago
|
|
||
|
import React from "react";
|
||
4 years ago
|
import clsx from "clsx";
|
||
3 years ago
|
import { AppState, Collaborator } from "../types";
|
||
|
import { Tooltip } from "./Tooltip";
|
||
2 years ago
|
import { useExcalidrawActionManager } from "./App";
|
||
5 years ago
|
|
||
3 years ago
|
export const UserList: React.FC<{
|
||
5 years ago
|
className?: string;
|
||
|
mobile?: boolean;
|
||
3 years ago
|
collaborators: AppState["collaborators"];
|
||
2 years ago
|
}> = ({ className, mobile, collaborators }) => {
|
||
|
const actionManager = useExcalidrawActionManager();
|
||
3 years ago
|
|
||
2 years ago
|
const uniqueCollaborators = new Map<string, Collaborator>();
|
||
3 years ago
|
collaborators.forEach((collaborator, socketId) => {
|
||
|
uniqueCollaborators.set(
|
||
|
// filter on user id, else fall back on unique socketId
|
||
|
collaborator.id || socketId,
|
||
|
collaborator,
|
||
|
);
|
||
|
});
|
||
|
|
||
|
const avatars =
|
||
|
uniqueCollaborators.size > 0 &&
|
||
|
Array.from(uniqueCollaborators)
|
||
|
.filter(([_, client]) => Object.keys(client).length !== 0)
|
||
|
.map(([clientId, collaborator]) => {
|
||
|
const avatarJSX = actionManager.renderAction("goToCollaborator", [
|
||
|
clientId,
|
||
|
collaborator,
|
||
|
]);
|
||
|
|
||
|
return mobile ? (
|
||
|
<Tooltip
|
||
|
label={collaborator.username || "Unknown user"}
|
||
|
key={clientId}
|
||
|
>
|
||
|
{avatarJSX}
|
||
|
</Tooltip>
|
||
|
) : (
|
||
|
<React.Fragment key={clientId}>{avatarJSX}</React.Fragment>
|
||
|
);
|
||
|
});
|
||
5 years ago
|
|
||
4 years ago
|
return (
|
||
|
<div className={clsx("UserList", className, { UserList_mobile: mobile })}>
|
||
3 years ago
|
{avatars}
|
||
4 years ago
|
</div>
|
||
|
);
|
||
5 years ago
|
};
|