import { AgentFace } from "@chopin/editor";
import { useEffect, useState } from "react";
import { referenceOptionId } from "./reference-picker";
import type { MentionCandidate } from "./mentions";
/** At most this many rows show before the list scrolls: 8 × 2rem plus the 0.25rem padding. */
const LIST_HEIGHT = "16.5rem";
function Avatar({ login }: { login: string }) {
let [failed, setFailed] = useState(false);
if (failed) {
return (
);
}
return (
setFailed(true)}
referrerPolicy="no-referrer"
src={`https://github.com/${encodeURIComponent(login)}.png?size=40`}
/>
);
}
export function MentionPicker(
{
active,
id,
onActive,
onSelect,
options,
}: {
active: number;
id: string;
onActive: (index: number) => void;
onSelect: (candidate: MentionCandidate) => void;
options: readonly MentionCandidate[];
},
) {
useEffect(() => {
let frame = requestAnimationFrame(() => {
document.getElementById(referenceOptionId(id, active))?.scrollIntoView({ block: "nearest" });
});
return () => cancelAnimationFrame(frame);
}, [active, id]);
return (