/** * Trouve-KA — cœur ♥ « Mon univers Ka » d'un résultat de recherche * Author: Simon-Pierre Boucher * Contact: contact@spboucher.ai * * Toggle du favori au hub Groupe KA (via /api/favorites/toggle). Connecté : * cœur plein/contour ; non connecté : le tap envoie au flux « Se connecter * avec KA ID » existant (retour sur la page courante). Zone tactile 44 px * via ::after (pattern du socle mobile KA). */ "use client"; import { useEffect, useState } from "react"; import { cn } from "@/lib/utils"; import { ensureLoaded, isFavorite, toggleFav, useFavorites } from "@/components/fav-store"; interface FavButtonProps { url: string; title: string; subtitle?: string; imageUrl?: string | null; className?: string; } export function FavButton({ url, title, subtitle, imageUrl, className }: FavButtonProps) { const favs = useFavorites(); const [busy, setBusy] = useState(false); useEffect(() => { void ensureLoaded(); }, []); const fav = isFavorite(favs, url); const anon = favs.status === "anon"; const onClick = async () => { if (busy) return; if (anon) { const here = window.location.pathname + window.location.search; window.location.href = `/api/auth/ka/login?next=${encodeURIComponent(here)}`; return; } setBusy(true); await toggleFav({ url, title, subtitle, image_url: imageUrl || undefined, }); setBusy(false); }; return ( ); }