From dbd86b34fddbb1bd9094f06c136a9b4c347d2e81 Mon Sep 17 00:00:00 2001 From: ashione Date: Sun, 8 Mar 2026 00:42:18 +0800 Subject: [PATCH] Revert channel enable/disable UI and stabilize channels view --- src/pages/Channels/index.tsx | 50 +++++++----------------------------- 1 file changed, 9 insertions(+), 41 deletions(-) diff --git a/src/pages/Channels/index.tsx b/src/pages/Channels/index.tsx index de67193..0c007eb 100644 --- a/src/pages/Channels/index.tsx +++ b/src/pages/Channels/index.tsx @@ -25,7 +25,6 @@ import { import { Button } from '@/components/ui/button'; import { Input } from '@/components/ui/input'; import { Label } from '@/components/ui/label'; -import { Switch } from '@/components/ui/switch'; import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'; import { Separator } from '@/components/ui/separator'; import { Badge } from '@/components/ui/badge'; @@ -320,7 +319,7 @@ export function Channels() { {meta.icon}

{meta.name}

- {meta.description} + {t(meta.description)}

{isConfigured && ( @@ -440,7 +439,6 @@ function AddChannelDialog({ selectedType, onSelectType, onClose, onChannelAdded const { t } = useTranslation('channels'); const [configValues, setConfigValues] = useState>({}); const [channelName, setChannelName] = useState(''); - const [enabled, setEnabled] = useState(true); const [connecting, setConnecting] = useState(false); const [showSecrets, setShowSecrets] = useState>({}); const [qrCode, setQrCode] = useState(null); @@ -462,7 +460,6 @@ function AddChannelDialog({ selectedType, onSelectType, onClose, onChannelAdded setConfigValues({}); setChannelName(''); setIsExistingConfig(false); - setEnabled(true); setChannelName(''); setIsExistingConfig(false); // Ensure we clean up any pending QR session if switching away @@ -475,45 +472,24 @@ function AddChannelDialog({ selectedType, onSelectType, onClose, onChannelAdded (async () => { try { - const [result, configResult] = await Promise.all([ - invokeIpc( - 'channel:getFormValues', - selectedType - ) as Promise<{ success: boolean; values?: Record }>, - invokeIpc( - 'channel:getConfig', - selectedType - ) as Promise<{ success: boolean; config?: Record }>, - ]); + const result = await invokeIpc( + 'channel:getFormValues', + selectedType + ) as { success: boolean; values?: Record }; if (cancelled) return; if (result.success && result.values && Object.keys(result.values).length > 0) { setConfigValues(result.values); - } else { - setConfigValues({}); - } - - const existingConfig = configResult.success ? configResult.config : undefined; - if (existingConfig && typeof existingConfig.enabled === 'boolean') { - setEnabled(existingConfig.enabled); - } else { - setEnabled(true); - } - - if ( - (result.success && result.values && Object.keys(result.values).length > 0) || - Boolean(existingConfig) - ) { setIsExistingConfig(true); } else { + setConfigValues({}); setIsExistingConfig(false); } } catch { if (!cancelled) { setConfigValues({}); setIsExistingConfig(false); - setEnabled(true); } } finally { if (!cancelled) setLoadingConfig(false); @@ -547,7 +523,7 @@ function AddChannelDialog({ selectedType, onSelectType, onClose, onChannelAdded const saveResult = await invokeIpc( 'channel:saveConfig', 'whatsapp', - { enabled } + { enabled: true } ) as { success?: boolean; error?: string }; if (!saveResult?.success) { console.error('Failed to save WhatsApp config:', saveResult?.error); @@ -581,7 +557,7 @@ function AddChannelDialog({ selectedType, onSelectType, onClose, onChannelAdded // Cancel when unmounting or switching types invokeIpc('channel:cancelWhatsAppQr').catch(() => { }); }; - }, [selectedType, channelName, enabled, onChannelAdded, t]); + }, [selectedType, channelName, onChannelAdded, t]); const handleValidate = async () => { if (!selectedType) return; @@ -690,7 +666,7 @@ function AddChannelDialog({ selectedType, onSelectType, onClose, onChannelAdded } // Step 2: Save channel configuration via IPC - const config: Record = { ...configValues, enabled }; + const config: Record = { ...configValues }; const saveResult = await invokeIpc('channel:saveConfig', selectedType, config) as { success?: boolean; error?: string; @@ -875,14 +851,6 @@ function AddChannelDialog({ selectedType, onSelectType, onClose, onChannelAdded /> -
-
-

{t('dialog.enableChannel')}

-

{t('dialog.enableChannelDesc')}

-
- -
- {/* Configuration fields */} {meta?.configFields.map((field) => (