import { useMemo } from "react"; import { useIsServer } from "../../hooks"; import { useGleanClick } from "../../telemetry/glean-context"; import InternalLink from "../../ui/atoms/internal-link"; import { OBSERVATORY } from "../../telemetry/constants"; import { ReactComponent as StarsSVG } from "../../../public/assets/observatory/stars.svg"; import { ObservatoryResult, SCORING_TABLE } from "../types"; import { formatMinus, hostAsRedirectChain } from "../utils"; import { Tooltip } from "../tooltip"; import { RescanButton } from "./rescan-button"; import { HumanDuration } from "./human-duration"; export function ObservatoryRating({ result, host, rescanTrigger, }: { result: ObservatoryResult; host: string; rescanTrigger: () => void; }) { const gleanClick = useGleanClick(); const isServer = useIsServer(); const arrowState = useMemo(() => { const [oldScore, oldGrade] = result.history.length ? [result.history.at(-2)?.score, result.history.at(-2)?.grade] : [undefined, undefined]; const newScore = result.scan.score; const newGrade = result.scan.grade; if ( typeof newScore === "number" && typeof oldScore === "number" && newGrade !== oldGrade && newScore !== oldScore ) { return oldScore < newScore ? "up" : "down"; } else { return "none"; } }, [result.history, result.scan.grade, result.scan.score]); return ( <>
| Grade | Score |
|---|---|
| {formatMinus(st.grade)} |
{st.scoreText}{" "}
{result.scan.grade === st.grade && st.stars && (
|