summaryrefslogtreecommitdiff
path: root/front/src/components/Avatar.tsx
blob: 35b438654a96081e3b8432e6833c5cfd8a533ba1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import useLocalState from "@/state/state";
import type { Ship } from "@/types/urbit";
import Sigil from "./Sigil";
import ShipModal from "./modals/ShipModal";

export default function ({
  p,
  size,
  color,
  noClickOnName,
}: {
  p: Ship;
  size: number;
  color?: string;
  noClickOnName?: boolean;
}) {
  const { setModal } = useLocalState();
  // TODO revisit this when %whom updates
  const avatar = (
    <div className="avatar-w sigil cp" role="link" onClick={openModal}>
      <Sigil patp={p} size={size} color={color} />
    </div>
  );
  const tooLong = (s: string) => (s.length > 15 ? " too-long" : "");
  function openModal(e: React.MouseEvent) {
    if (noClickOnName) return;
    e.stopPropagation();
    setModal(<ShipModal ship={p} />);
  }
  const name = (
    <div className="name cp" role="link" onMouseUp={openModal}>
      <p className={"p-only" + tooLong(p)}>{p.length > 28 ? "Anon" : p}</p>
    </div>
  );
  return (
    <div className="ship-avatar">
      {avatar}
      {name}
    </div>
  );
}

export function SigilOnly({ p, size, color }: any) {
  const { setModal } = useLocalState();
  function openModal(e: React.MouseEvent) {
    e.stopPropagation();
    setModal(<ShipModal ship={p} />);
  }
  return (
    <div
      className="avatar-w sigil cp"
      role="link"
      onClick={openModal}
      onMouseUp={openModal}
    >
      <Sigil patp={p} size={size} color={color} />
    </div>
  );
}