actionNavigate.tsx 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import { getClientColors } 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. trackEvent: { category: "collab" },
  9. perform: (_elements, appState, value) => {
  10. const point = value as Collaborator["pointer"];
  11. if (!point) {
  12. return { appState, commitToHistory: false };
  13. }
  14. return {
  15. appState: {
  16. ...appState,
  17. ...centerScrollOn({
  18. scenePoint: point,
  19. viewportDimensions: {
  20. width: appState.width,
  21. height: appState.height,
  22. },
  23. zoom: appState.zoom,
  24. }),
  25. // Close mobile menu
  26. openMenu: appState.openMenu === "canvas" ? null : appState.openMenu,
  27. },
  28. commitToHistory: false,
  29. };
  30. },
  31. PanelComponent: ({ appState, updateData, data }) => {
  32. const [clientId, collaborator] = data as [string, Collaborator];
  33. const { background, stroke } = getClientColors(clientId, appState);
  34. return (
  35. <Avatar
  36. color={background}
  37. border={stroke}
  38. onClick={() => updateData(collaborator.pointer)}
  39. name={collaborator.username || ""}
  40. src={collaborator.avatarUrl}
  41. />
  42. );
  43. },
  44. });