From 8d508d5a86934a2cf55c4fa6246f3666cc0ae05c Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 5 Mar 2026 22:04:28 +0000 Subject: [PATCH] Fix channels not active after selection and add Fetch Channels button to Channels tab Co-authored-by: xCyanGrizzly <53275238+xCyanGrizzly@users.noreply.github.com> --- .../telegram/_components/channels-tab.tsx | 46 +++++++++++++++++-- .../telegram/_components/telegram-admin.tsx | 2 +- src/app/(app)/telegram/actions.ts | 5 +- 3 files changed, 46 insertions(+), 7 deletions(-) diff --git a/src/app/(app)/telegram/_components/channels-tab.tsx b/src/app/(app)/telegram/_components/channels-tab.tsx index 042216a..7781924 100644 --- a/src/app/(app)/telegram/_components/channels-tab.tsx +++ b/src/app/(app)/telegram/_components/channels-tab.tsx @@ -2,8 +2,10 @@ import { useState, useTransition } from "react"; import { toast } from "sonner"; +import { Download } from "lucide-react"; import { getChannelColumns } from "./channel-columns"; import { DestinationCard } from "./destination-card"; +import { ChannelPickerDialog } from "./channel-picker-dialog"; import { deleteChannel, toggleChannelActive, @@ -12,18 +14,24 @@ import { } from "../actions"; import { DataTable } from "@/components/shared/data-table"; import { DeleteDialog } from "@/components/shared/delete-dialog"; -import type { ChannelRow, GlobalDestination } from "@/lib/telegram/admin-queries"; +import { Button } from "@/components/ui/button"; +import type { AccountRow, ChannelRow, GlobalDestination } from "@/lib/telegram/admin-queries"; import { useDataTable } from "@/hooks/use-data-table"; interface ChannelsTabProps { channels: ChannelRow[]; globalDestination: GlobalDestination; + accounts: AccountRow[]; } -export function ChannelsTab({ channels, globalDestination }: ChannelsTabProps) { +export function ChannelsTab({ channels, globalDestination, accounts }: ChannelsTabProps) { const [isPending, startTransition] = useTransition(); const [deleteId, setDeleteId] = useState(null); const [rescanId, setRescanId] = useState(null); + const [fetchChannelsAccountId, setFetchChannelsAccountId] = useState(null); + + // Find the first authenticated account for "Fetch Channels" + const authenticatedAccounts = accounts.filter((a) => a.authState === "AUTHENTICATED" && a.isActive); const columns = getChannelColumns({ onToggleActive: (id) => { @@ -76,19 +84,41 @@ export function ChannelsTab({ channels, globalDestination }: ChannelsTabProps) { }); }; + const handleFetchChannels = () => { + if (authenticatedAccounts.length === 1) { + setFetchChannelsAccountId(authenticatedAccounts[0].id); + } else if (authenticatedAccounts.length > 1) { + // Use the first authenticated account by default + setFetchChannelsAccountId(authenticatedAccounts[0].id); + } else { + toast.error("No authenticated accounts available. Add and authenticate an account first."); + } + }; + return (
+
+ +
+ {channels.length > 0 && (

- Source channels are added per-account via the "Fetch Channels" button on the Accounts tab. + Channels discovered via "Fetch Channels" are automatically activated as sources.

)} + + { + if (!open) setFetchChannelsAccountId(null); + }} + />
); } diff --git a/src/app/(app)/telegram/_components/telegram-admin.tsx b/src/app/(app)/telegram/_components/telegram-admin.tsx index 9632dc2..2008d58 100644 --- a/src/app/(app)/telegram/_components/telegram-admin.tsx +++ b/src/app/(app)/telegram/_components/telegram-admin.tsx @@ -53,7 +53,7 @@ export function TelegramAdmin({ - + diff --git a/src/app/(app)/telegram/actions.ts b/src/app/(app)/telegram/actions.ts index 4e25d11..27baa57 100644 --- a/src/app/(app)/telegram/actions.ts +++ b/src/app/(app)/telegram/actions.ts @@ -453,7 +453,7 @@ export async function saveChannelSelections( try { let linked = 0; for (const ch of channels) { - // Upsert the channel record (new channels default to disabled) + // Upsert the channel record and activate it (user explicitly selected it) const channel = await prisma.telegramChannel.upsert({ where: { telegramId: BigInt(ch.telegramId) }, create: { @@ -461,11 +461,12 @@ export async function saveChannelSelections( title: ch.title, type: "SOURCE", isForum: ch.isForum, - isActive: false, + isActive: true, }, update: { title: ch.title, isForum: ch.isForum, + isActive: true, }, });