From 11768862d36c83608a9e13f57fb12e9dc3417dcc Mon Sep 17 00:00:00 2001 From: coolcoala Date: Wed, 9 Jul 2025 10:25:58 +0300 Subject: [PATCH] increased the size of the proxy enable button --- src/pages/home.tsx | 162 +++++++++++++++++++++++---------------------- 1 file changed, 84 insertions(+), 78 deletions(-) diff --git a/src/pages/home.tsx b/src/pages/home.tsx index 737c62c7..d940b7a1 100644 --- a/src/pages/home.tsx +++ b/src/pages/home.tsx @@ -1,10 +1,9 @@ -import React, { useRef, useMemo, useCallback } from 'react'; +import React, { useRef, useMemo, useCallback, useState } from 'react'; import { useNavigate } from 'react-router-dom'; import { useLockFn } from 'ahooks'; import { useTranslation } from 'react-i18next'; import { toast } from 'sonner'; -// Импорты import { useProfiles } from '@/hooks/use-profiles'; import { ProfileViewer, ProfileViewerRef } from '@/components/profile/profile-viewer'; import { @@ -12,7 +11,7 @@ import { DropdownMenuSeparator, DropdownMenuTrigger, } from '@/components/ui/dropdown-menu'; import { Button } from '@/components/ui/button'; -import { ChevronsUpDown, Check, PlusCircle, Menu, Wrench, AlertTriangle } from 'lucide-react'; +import { ChevronsUpDown, Check, PlusCircle, Menu, Wrench, AlertTriangle, Loader2 } from 'lucide-react'; import { useVerge } from '@/hooks/use-verge'; import { useSystemState } from '@/hooks/use-system-state'; import { useServiceInstaller } from '@/hooks/useServiceInstaller'; @@ -25,24 +24,19 @@ import { closeAllConnections } from '@/services/api'; const MinimalHomePage: React.FC = () => { const { t } = useTranslation(); const navigate = useNavigate(); - - // --- НАЧАЛО ИЗМЕНЕНИЙ 1: Правильно используем хук --- + const [isToggling, setIsToggling] = useState(false); const { profiles, patchProfiles, activateSelected, mutateProfiles } = useProfiles(); const viewerRef = useRef(null); - // Воссоздаем логику фильтрации профилей здесь const profileItems = useMemo(() => { const items = profiles && Array.isArray(profiles.items) ? profiles.items : []; const allowedTypes = ["local", "remote"]; - // Добавляем явное указание типа, чтобы избежать ошибок return items.filter((i: any) => i && allowedTypes.includes(i.type!)); }, [profiles]); const currentProfileName = useMemo(() => { - // Находим в списке профилей тот, чей uid совпадает с активным return profileItems.find(p => p.uid === profiles?.current)?.name || profiles?.current; }, [profileItems, profiles?.current]); - // Воссоздаем логику активации профиля здесь const activateProfile = useCallback(async (uid: string, notifySuccess: boolean) => { try { await patchProfiles({ current: uid }); @@ -53,7 +47,7 @@ const MinimalHomePage: React.FC = () => { } } catch (err: any) { toast.error(err.message || err.toString()); - mutateProfiles(); // Откатываем в случае ошибки + mutateProfiles(); } }, [patchProfiles, activateSelected, mutateProfiles, t]); @@ -61,7 +55,6 @@ const MinimalHomePage: React.FC = () => { if (profiles?.current === uid) return; await activateProfile(uid, true); }); - // --- КОНЕЦ ИЗМЕНЕНИЙ 1 --- const { verge, patchVerge, mutateVerge } = useVerge(); const { isAdminMode, isServiceMode } = useSystemState(); @@ -71,6 +64,7 @@ const MinimalHomePage: React.FC = () => { const handleToggleProxy = useLockFn(async () => { const turningOn = !isProxyEnabled; + setIsToggling(true); try { if (turningOn) { await patchVerge({ enable_tun_mode: true, enable_system_proxy: false }); @@ -82,6 +76,8 @@ const MinimalHomePage: React.FC = () => { mutateVerge(); } catch (error: any) { toast.error(t('Failed to toggle proxy'), { description: error.message }); + } finally { + setIsToggling(false); } }); @@ -96,88 +92,98 @@ const MinimalHomePage: React.FC = () => { return (
-
- - - - - - {t("Profiles")} - - {profileItems.map((p) => ( - handleProfileChange(p.uid)}> - {p.name} - {profiles?.current === p.uid && } - - ))} - - viewerRef.current?.create()}> - - {t("Add New Profile")} - - - -
+
+
-
+
- - - {t("Menu")} + + {t("Profiles")} - {navMenuItems.map((item) => ( - navigate(item.path)}> - {t(item.label)} + {profileItems.map((p) => ( + handleProfileChange(p.uid)}> + {p.name} + {profiles?.current === p.uid && } ))} + + viewerRef.current?.create()}> + + {t("Add New Profile")} + -
- - -
-

- {isProxyEnabled ? t('Connected') : t('Disconnected')} -

- -
-
-
+
+ + + + + + {t("Menu")} + + {navMenuItems.map((item) => ( + navigate(item.path)}> + {t(item.label)} + + ))} + + +
+
+ +
+
+ +
+

+ {isProxyEnabled ? t('Connected') : t('Disconnected')} +

+

+ {isToggling && (isProxyEnabled ? t('Disconnecting...') : t('Connecting...'))} +

+
+ +
+ +
+ {!isTunAvailable && ( - -
- - {t("Attention Required")} -
- - {t("TUN requires Service Mode or Admin Mode")} - - {!isServiceMode && !isAdminMode && ( - - )} -
+
+ + + {t("Attention Required")} + + {t("TUN requires Service Mode or Admin Mode")} + + {!isServiceMode && !isAdminMode && ( + + )} + +
)} -
-
- +
+ +
+