Skip to content

Never stop coding. Free MIT AI gateway: one endpoint, 375 providers (150+ free), 1,400+ models Kimi, Claude, GPT, Gemini, GLM, DeepSeek, MiniMax. Works with Claude Code, Codex, Cursor, OpenCode, Cline & Copilot. Quota-aware auto-fallback, RTK+Caveman compression saves 15-95% tokens, MCP/A2A, Desktop/PWA. Built by 900+ contributors

934 B
Raw Blame
import type { ProviderCardHandle } from "./components/ProviderCard";

/**
 * Called before navigating to a provider detail page. Persists the provider
 * id in history.state so the list page can scroll to it on back-navigation.
 */
export function recordProviderNavigation(id: string) {
  window.history.replaceState({ providerId: id }, "");
}

/**
 * Ref callback for ProviderCard. When the rendered card's provider id
 * matches the highlighted id, scrolls it into view and triggers the
 * highlight animation. Always clears the highlighted id afterward so
 * subsequent re-renders don't re-scroll.
 */
export function resolveHighlightedCard(
  handle: ProviderCardHandle | null,
  highlightedProviderId: string | null,
  onAfterHighlight: () => void
) {
  if (handle?.getProviderId() === highlightedProviderId) {
    handle.scrollIntoView({ behavior: "auto", block: "center" });
    handle.highlight();
  }
  onAfterHighlight();
}