actionNavigate.tsx 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import { getClientColor } from "../clients";
  2. import { Avatar } from "../components/Avatar";
  3. import { centerScrollOn } from "../scene/scroll";
  4. import { Collaborator } from "../types";
  5. import { register } from "./register";
  6. export const actionGoToCollaborator = register({
  7. name: "goToCollaborator",
  8. viewMode: true,
  9. trackEvent: { category: "collab" },
  10. perform: (_elements, appState, value) => {
  11. const point = value as Collaborator["pointer"];
  12. if (!point) {
  13. return { appState, commitToHistory: false };
  14. }
  15. return {
  16. appState: {
  17. ...appState,
  18. ...centerScrollOn({
  19. scenePoint: point,
  20. viewportDimensions: {
  21. width: appState.width,
  22. height: appState.height,
  23. },
  24. zoom: appState.zoom,
  25. }),
  26. // Close mobile menu
  27. openMenu: appState.openMenu === "canvas" ? null : appState.openMenu,
  28. },
  29. commitToHistory: false,
  30. };
  31. },
  32. PanelComponent: ({ updateData, data }) => {
  33. const [clientId, collaborator] = data as [string, Collaborator];
  34. const background = getClientColor(clientId);
  35. return (
  36. <Avatar
  37. color={background}
  38. onClick={() => updateData(collaborator.pointer)}
  39. name={collaborator.username || ""}
  40. src={collaborator.avatarUrl}
  41. />
  42. );
  43. },
  44. });