refactor(channels): share one ChannelLink + channelYouTubeUrl helper
The "avatar + name + open-on-YouTube" cell and the @handle-or-/channel/<id> URL were copy-pasted across the channel manager, the discovery tab, the subscribe notice and the player. Extract a single ChannelLink component (optional in-app onView, middle-click opens YouTube) and a channelYouTubeUrl helper, and route all four through them. Removes the NameCell / DiscoveryNameCell duplication (the latter introduced with the discovery tab).
This commit is contained in:
parent
96f303b0cf
commit
5461cada84
6 changed files with 91 additions and 72 deletions
|
|
@ -1,11 +1,11 @@
|
|||
import { useTranslation } from "react-i18next";
|
||||
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
||||
import { ExternalLink, UserPlus } from "lucide-react";
|
||||
import { UserPlus } from "lucide-react";
|
||||
import { api, HttpError, type DiscoveredChannel } from "../lib/api";
|
||||
import { formatViews } from "../lib/format";
|
||||
import { notify } from "../lib/notifications";
|
||||
import Tooltip from "./Tooltip";
|
||||
import Avatar from "./Avatar";
|
||||
import ChannelLink from "./ChannelLink";
|
||||
import DataTable, { type Column } from "./DataTable";
|
||||
|
||||
// The Channel manager's "Discovery" tab: channels that turn up in the user's playlists but
|
||||
|
|
@ -70,7 +70,9 @@ export default function ChannelDiscovery({
|
|||
sortValue: (c) => (c.title ?? c.id).toLowerCase(),
|
||||
filter: { kind: "text", get: (c) => `${c.title ?? ""} ${c.handle ?? ""}` },
|
||||
cardPrimary: true,
|
||||
render: (c) => <DiscoveryNameCell c={c} />,
|
||||
render: (c) => (
|
||||
<ChannelLink id={c.id} title={c.title} handle={c.handle} thumbnailUrl={c.thumbnail_url} />
|
||||
),
|
||||
},
|
||||
{
|
||||
key: "subs",
|
||||
|
|
@ -153,27 +155,3 @@ export default function ChannelDiscovery({
|
|||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function DiscoveryNameCell({ c }: { c: DiscoveredChannel }) {
|
||||
const { t } = useTranslation();
|
||||
const ytUrl = c.handle
|
||||
? `https://www.youtube.com/@${c.handle.replace(/^@/, "")}`
|
||||
: `https://www.youtube.com/channel/${c.id}`;
|
||||
return (
|
||||
<div className="flex items-center gap-2 min-w-0">
|
||||
<Avatar src={c.thumbnail_url} fallback={c.title ?? ""} className="w-8 h-8 rounded-full shrink-0" />
|
||||
<span className="text-sm font-medium truncate min-w-0">{c.title ?? c.id}</span>
|
||||
<Tooltip hint={t("channels.row.openOnYouTube")}>
|
||||
<a
|
||||
href={ytUrl}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
className="text-muted hover:text-accent shrink-0"
|
||||
aria-label={t("channels.row.openOnYouTube")}
|
||||
>
|
||||
<ExternalLink className="w-3.5 h-3.5" />
|
||||
</a>
|
||||
</Tooltip>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue