import { useTranslation } from "react-i18next"; import { ExternalLink } from "lucide-react"; import Avatar from "./ui/Avatar"; import { channelYouTubeUrl } from "../lib/format"; import { Pressable } from "./ui/Pressable"; import { IconLink } from "./ui/LinkButton"; // Avatar + channel name + "open on YouTube" link, shared by the Channel manager and the // discovery list (and anywhere else that lists a channel). When `onView` is given the name // is a button that opens the in-app channel view, with middle-click opening YouTube in a new // tab; without it the name is plain text. export default function ChannelLink({ id, title, handle, thumbnailUrl, onView, }: { id: string; title: string | null; handle?: string | null; thumbnailUrl: string | null; onView?: () => void; }) { const { t } = useTranslation(); const ytUrl = channelYouTubeUrl(id, handle); const name = title ?? id; return (
{onView ? ( { // Middle-click opens the channel's YouTube page in a new tab; left-click keeps // opening the in-app channel detail. if (e.button === 1) { e.preventDefault(); window.open(ytUrl, "_blank", "noopener,noreferrer"); } }} onMouseDown={(e) => { if (e.button === 1) e.preventDefault(); // suppress middle-click autoscroll }} // title = the full name, so a truncated fluid-column name is still readable on hover. title={name} className="min-h-6 min-w-0 truncate text-sm font-medium hover:text-accent pointer-coarse:min-h-(--touch-target)" > {name} ) : ( {name} )}
); }