Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 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 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1244x 1244x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 126x 126x 126x 126x 126x 126x 126x 126x 126x 126x 126x 126x 126x 126x 126x 126x 126x 126x 126x 126x 126x 126x 126x 126x 126x 126x 126x 126x 126x 126x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 101x 103x 27x 27x 27x 27x 27x 27x 27x 27x 27x 27x 27x 27x 27x 27x 27x 27x 27x 27x 74x 74x 76x 103x 103x 103x 103x 2x 2x 3x 3x 3x 3x 3x 3x 2x 2x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 16x 16x 16x 16x 16x 16x 16x 16x 15x 15x 15x 15x 15x 15x 15x 1x 1x 16x 7x 7x 7x 16x 16x 103x 103x 3x 3x 3x 103x 103x 103x 103x 74x 74x 74x 72x 40x 40x 40x 74x 74x 74x 74x 74x 74x 74x 74x 74x 74x 74x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 1x 13x 13x 74x 74x 3x 3x 3x 74x 74x 34x 34x 34x 34x 34x 34x 34x 34x 34x 74x 74x 74x 103x 103x 103x 103x 1x 1x 1x 1x 1x 1x 1x 1x 1x 103x 103x 103x 103x 103x 54x 54x 54x 54x 54x 5x 5x 5x 5x 2x 2x 2x 5x 3x 3x 3x 5x 5x 54x 54x 1x 107x 107x 107x 107x 107x 107x 107x 107x 107x 107x 107x 107x 107x 107x 107x 107x 107x 78x 78x 78x 78x 78x 78x 78x 110x 110x 110x 110x 30x 110x 110x 76x 76x 76x 76x 76x 76x 76x 34x 34x 34x 110x 110x 110x 110x 110x 110x 110x 110x 110x 110x 110x 110x 110x 110x 110x 110x 110x 110x 110x 110x 110x 110x 110x 110x 110x 110x 110x 110x 110x 6x 6x 6x 6x 6x 5x 6x 6x 110x 110x 110x 78x 78x 78x 78x 78x 1x 30x 30x 3x 3x 3x 3x 3x 3x 27x 27x 27x 27x 27x 27x 27x 27x 27x 27x 27x 27x 1x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 1x 26x 26x 26x 26x 26x 26x 26x 26x 26x 26x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x | import type { Fit } from "../../types/job";
import { useState } from "react";
import {
ariaFitLabel,
evidenceFor,
normalizeFit,
previewMissing,
scoreTone,
verdictLabel,
type Freshness,
type RescoreAction,
type Verdict,
} from "../../../shared/fitView";
declare const WXT_WEB_APP_URL: string;
interface FitScoreProps {
fit: Fit | null;
freshness?: Freshness;
/** What to offer for an out-of-date score; see `rescoreAction` in shared/fitView. */
action?: RescoreAction;
/** FR-004a: what the rescore will cost, from `rescoreCostLine`. */
costLine?: string | null;
onRescore?: () => void;
/** FR-005: the posting is gone, so the score can't be updated. */
unavailable?: boolean;
/** The profile could not be loaded, so the fit was not scored. */
profileUnavailable?: boolean;
/** `scoredByLabel(analysis)`, shown in the fit details. */
scoredBy?: string;
/** "I have this" (FR-018): resolves once the skill is saved, rejects with a user-facing message. */
onConfirmSkill?: (label: string) => Promise<unknown>;
}
const FRESHNESS_LABELS: Partial<Record<Freshness, string>> = {
"out-of-date": "Scored against an older profile",
"version-unknown": "May be out of date",
"profile-deleted": "Scored against a deleted profile",
};
/** The marker text for a stale score; `null` when the score is current or unknown. */
export function freshnessLabel(freshness: Freshness): string | null {
return FRESHNESS_LABELS[freshness] ?? null;
}
/** Hrefs that start with "/" belong to the web app, not the extension. */
function resolveHref(href: string): string {
return href.startsWith("/") ? `${WXT_WEB_APP_URL}${href}` : href;
}
/**
* The one place verdict tones become Tailwind classes and icons (FR-010: the
* text label is always shown, so neither colour nor icon carries meaning alone).
*/
const VERDICT_STYLES: Record<Verdict, { classes: string; icon: string }> = {
strong: {
classes: "bg-green-100 text-green-800 dark:bg-green-950/60 dark:text-green-300",
icon: "M20 6 9 17l-5-5",
},
"worth-a-shot": {
classes: "bg-lime-100 text-lime-800 dark:bg-lime-950/60 dark:text-lime-300",
icon: "M5 12h14M13 6l6 6-6 6",
},
stretch: {
classes: "bg-amber-100 text-amber-800 dark:bg-amber-950/60 dark:text-amber-300",
icon: "M4 15 12 5l8 10",
},
"long-shot": {
classes: "bg-gray-200 text-gray-700 dark:bg-gray-800 dark:text-gray-300",
icon: "M12 5v14m0 0-6-6m6 6 6-6",
},
dealbreaker: {
classes: "bg-red-100 text-red-800 dark:bg-red-950/60 dark:text-red-300",
icon: "M18 6 6 18M6 6l12 12",
},
unrated: {
classes: "bg-gray-100 text-gray-600 dark:bg-gray-800 dark:text-gray-400",
icon: "M9 9a3 3 0 1 1 4 2.8c-.7.4-1 1-1 1.7M12 17h.01",
},
};
/** Score number, verdict icon and verdict label, with the accessible name from `ariaFitLabel`. */
export function VerdictBadge({ fit, compact }: { fit: Fit; compact?: boolean }) {
const normalized = normalizeFit(fit)!;
const verdict = scoreTone(normalized);
const style = VERDICT_STYLES[verdict];
return (
<span
role="img"
aria-label={ariaFitLabel(normalized)}
className={`inline-flex items-center gap-1 rounded-full px-2.5 py-0.5 font-bold ${
compact ? "text-xs" : "text-sm"
} ${style.classes}`}
>
<svg
xmlns="http://www.w3.org/2000/svg"
width="12"
height="12"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
strokeWidth="3"
strokeLinecap="round"
strokeLinejoin="round"
aria-hidden="true"
>
<path d={style.icon} />
</svg>
<span>{normalized.score}</span>
<span className="font-semibold">{verdictLabel(verdict)}</span>
</span>
);
}
type Tone = "green" | "red" | "amber";
const CHIP_TONES: Record<Tone, string> = {
green:
"bg-green-100 text-green-800 dark:bg-green-950/60 dark:text-green-300",
red: "bg-red-100 text-red-800 dark:bg-red-950/60 dark:text-red-300",
amber:
"bg-amber-100 text-amber-800 dark:bg-amber-950/60 dark:text-amber-300",
};
const MARKER_TONES: Record<Tone, string> = {
green: "text-green-600 dark:text-green-400",
red: "text-red-600 dark:text-red-400",
amber: "text-amber-600 dark:text-amber-400",
};
export function FitScore({
fit,
freshness = "unknown",
action = { kind: "none" },
costLine,
onRescore,
unavailable,
profileUnavailable,
scoredBy,
onConfirmSkill,
}: FitScoreProps) {
const [expanded, setExpanded] = useState(false);
const confirm = useConfirmSkill(onConfirmSkill);
if (!fit && profileUnavailable) {
return (
<div className="rounded-xl border border-gray-200/70 bg-white p-3 dark:border-gray-800 dark:bg-gray-900">
<h3 className="text-xs font-semibold uppercase tracking-wide text-gray-400 dark:text-gray-500">
Fit score
</h3>
<p className="mt-1 text-sm text-gray-600 dark:text-gray-400">
Fit not scored — your profile couldn’t be loaded
</p>
</div>
);
}
if (!fit) {
return (
<div className="rounded-xl border border-gray-200/70 bg-white p-3 dark:border-gray-800 dark:bg-gray-900">
<h3 className="text-xs font-semibold uppercase tracking-wide text-gray-400 dark:text-gray-500">
Fit score
</h3>
<p className="mt-1 text-sm text-gray-600 dark:text-gray-400">
Set up your candidate profile to see how well postings match your
background.
</p>
<button
onClick={() => chrome.runtime.openOptionsPage()}
className="mt-2 rounded-md bg-blue-600 px-3 py-1.5 text-xs font-semibold text-white transition-colors hover:bg-blue-700"
>
Configure profile
</button>
</div>
);
}
const label = freshnessLabel(freshness);
const violated = fit.dealbreakersViolated ?? [];
return (
<div className="space-y-3 rounded-xl border border-gray-200/70 bg-white p-3 dark:border-gray-800 dark:bg-gray-900">
{violated.length > 0 && (
<ul aria-label="Dealbreakers" className="space-y-1">
{violated.map((line) => (
<li
key={line}
className="rounded-md bg-red-100 px-2 py-1 text-xs font-semibold text-red-800 dark:bg-red-950/60 dark:text-red-300"
>
Violates your dealbreaker: {line}
</li>
))}
</ul>
)}
<div className="flex items-center gap-2">
<h3 className="text-xs font-semibold uppercase tracking-wide text-gray-400 dark:text-gray-500">
Fit score
</h3>
<VerdictBadge fit={fit} />
<button
onClick={() => chrome.runtime.openOptionsPage()}
className="ml-auto inline-flex items-center gap-1.5 rounded-md border border-gray-300 px-2.5 py-1 text-xs font-medium text-gray-600 transition-colors hover:bg-gray-100 dark:border-gray-700 dark:text-gray-300 dark:hover:bg-gray-800"
>
<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.5" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true">
<path d="M20 21v-2a4 4 0 0 0-4-4H8a4 4 0 0 0-4 4v2" />
<circle cx="12" cy="7" r="4" />
</svg>
My profile
</button>
</div>
{label && (
<div
role="status"
className="rounded-lg bg-amber-50 px-2.5 py-2 dark:bg-amber-950/30"
>
<p className="text-xs font-semibold text-amber-800 dark:text-amber-300">
{label}
</p>
{action.kind === "rescore-here" || action.kind === "paste-again" ? (
<button
onClick={onRescore}
disabled={!onRescore}
className="mt-1.5 rounded-md bg-amber-600 px-2.5 py-1 text-xs font-semibold text-white hover:bg-amber-700 disabled:opacity-50"
>
{action.label}
</button>
) : action.kind !== "none" ? (
<a
href={resolveHref(action.href)}
target="_blank"
rel="noreferrer"
className="mt-1.5 inline-block text-xs font-semibold text-amber-800 underline dark:text-amber-300"
>
{action.label}
</a>
) : null}
{costLine && action.kind !== "none" && (
<p className="mt-1 text-[10px] text-amber-700 dark:text-amber-400">
{costLine}
</p>
)}
</div>
)}
{unavailable && (
<p className="text-xs text-gray-500 dark:text-gray-400">
Posting no longer available — score can’t be updated
</p>
)}
<p className="text-sm text-gray-600 dark:text-gray-300">{fit.rationale}</p>
{(() => {
const shown = previewMissing(fit);
const hasMore =
(fit.missing?.length ?? 0) > shown.length ||
(fit.matching?.length ?? 0) > 0 ||
(fit.desired?.length ?? 0) > 0 ||
(fit.strengths?.length ?? 0) > 0 ||
(fit.weaknesses?.length ?? 0) > 0;
return (
<>
<ChipSection
label="Missing (required)"
items={expanded ? fit.missing : shown}
tone="red"
fit={fit}
list="missing"
confirm={confirm}
/>
{expanded && (
<div id="fit-full-breakdown" className="space-y-3">
<ChipSection label="Matching skills" items={fit.matching} tone="green" fit={fit} list="matching" />
<ChipSection label="Nice to have" items={fit.desired} tone="amber" fit={fit} list="desired" confirm={confirm} />
<BulletSection
label="Strengths of this role for you"
items={fit.strengths}
tone="green"
/>
<BulletSection
label="Weaknesses of this role for you"
items={fit.weaknesses}
tone="red"
/>
{scoredBy && (
<p className="text-[10px] text-gray-400 dark:text-gray-500">{scoredBy}</p>
)}
</div>
)}
{confirm.error && (
<p role="alert" className="text-xs text-red-600 dark:text-red-400">
{confirm.error}
</p>
)}
{hasMore && (
<button
type="button"
aria-expanded={expanded}
aria-controls="fit-full-breakdown"
onClick={() => setExpanded((v) => !v)}
className="text-xs font-medium text-blue-700 hover:underline dark:text-blue-400"
>
{expanded ? "Hide full breakdown" : "Show full breakdown"}
</button>
)}
</>
);
})()}
</div>
);
}
interface ConfirmControl {
/** Absent when this surface can't confirm skills. */
confirm?: (label: string) => void;
confirmed: ReadonlySet<string>;
pending: string | null;
error: string | null;
}
function useConfirmSkill(onConfirmSkill: FitScoreProps["onConfirmSkill"]): ConfirmControl {
const [confirmed, setConfirmed] = useState<ReadonlySet<string>>(new Set());
const [pending, setPending] = useState<string | null>(null);
const [error, setError] = useState<string | null>(null);
if (!onConfirmSkill) return { confirmed, pending, error };
return {
confirmed,
pending,
error,
confirm: (label) => {
setPending(label);
setError(null);
onConfirmSkill(label).then(
() => {
setConfirmed((prev) => new Set(prev).add(label));
setPending(null);
},
(err: unknown) => {
setError(err instanceof Error ? err.message : "Couldn't save to your profile. Try again.");
setPending(null);
}
);
},
};
}
function ChipSection({
label,
items,
tone,
fit,
list,
confirm,
}: {
label: string;
items: string[] | undefined;
tone: Tone;
fit: Fit;
list: "matching" | "missing" | "desired";
confirm?: ConfirmControl;
}) {
const [openLabel, setOpenLabel] = useState<string | null>(null);
if (!items || items.length === 0) return null;
return (
<div>
<h4 className="mb-1 text-[10px] font-semibold uppercase tracking-wide text-gray-400 dark:text-gray-500">
{label}
</h4>
<ul aria-label={label} className="flex flex-wrap gap-1">
{items.map((item) => {
const evidence = evidenceFor(fit, list, item);
const hasQuote = Boolean(evidence?.postingQuote || evidence?.profileQuote);
const chip = `rounded-md px-1.5 py-0.5 text-xs ${CHIP_TONES[tone]}`;
const confirmButton = confirm?.confirm && list !== "matching" && (
<ConfirmButton item={item} confirm={confirm} />
);
if (!evidence || !hasQuote) {
return (
<li key={item} className="inline-flex items-center gap-1">
<span className={chip}>{item}</span>
{confirmButton}
</li>
);
}
const open = openLabel === item;
const regionId = `evidence-${list}-${item.replace(/\W+/g, "-")}`;
return (
<li key={item} className={open ? "w-full" : undefined}>
<div className="inline-flex items-center gap-1">
<button
type="button"
aria-expanded={open}
aria-controls={open ? regionId : undefined}
onClick={() => setOpenLabel(open ? null : item)}
className={`${chip} inline-flex items-center underline decoration-dotted underline-offset-2`}
>
{item}
<svg
xmlns="http://www.w3.org/2000/svg"
width="10"
height="10"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
strokeWidth="3"
strokeLinecap="round"
strokeLinejoin="round"
aria-hidden="true"
className={`ml-0.5 inline-block transition-transform ${open ? "rotate-180" : ""}`}
>
<path d="m6 9 6 6 6-6" />
</svg>
</button>
{confirmButton}
</div>
{open && (
<div id={regionId} className="mt-1 space-y-1">
{evidence.postingQuote && (
<EvidenceQuote source="From the posting" quote={evidence.postingQuote} />
)}
{evidence.profileQuote && (
<EvidenceQuote source="From your profile" quote={evidence.profileQuote} />
)}
</div>
)}
</li>
);
})}
</ul>
</div>
);
}
function ConfirmButton({ item, confirm }: { item: string; confirm: ConfirmControl }) {
if (confirm.confirmed.has(item)) {
return (
<span className="text-[10px] font-medium text-green-700 dark:text-green-400">
Added to your profile
</span>
);
}
return (
<button
type="button"
aria-label={`I have ${item}`}
disabled={confirm.pending !== null}
onClick={() => confirm.confirm?.(item)}
className="rounded-md border border-gray-300 px-1.5 py-0.5 text-[10px] font-medium text-gray-600 hover:bg-gray-100 disabled:opacity-50 dark:border-gray-700 dark:text-gray-300 dark:hover:bg-gray-800"
>
I have this
</button>
);
}
function EvidenceQuote({ source, quote }: { source: string; quote: string }) {
return (
<div>
<p className="text-[10px] font-semibold uppercase tracking-wide text-gray-400 dark:text-gray-500">
{source}
</p>
<blockquote className="border-l-2 border-gray-300 pl-2 text-xs italic text-gray-600 dark:border-gray-700 dark:text-gray-300">
{quote}
</blockquote>
</div>
);
}
function BulletSection({
label,
items,
tone,
}: {
label: string;
items: string[] | undefined;
tone: Tone;
}) {
if (!items || items.length === 0) return null;
return (
<div>
<h4 className="mb-1 text-[10px] font-semibold uppercase tracking-wide text-gray-400 dark:text-gray-500">
{label}
</h4>
<ul aria-label={label} className="space-y-0.5">
{items.map((item) => (
<li
key={item}
className="flex gap-1.5 text-xs text-gray-600 dark:text-gray-300"
>
<span aria-hidden="true" className={MARKER_TONES[tone]}>
•
</span>
{item}
</li>
))}
</ul>
</div>
);
}
|