From 8b8daa7b4c481298cfcc6760aceed2eaba5b9bdc Mon Sep 17 00:00:00 2001 From: coolcoala Date: Sat, 9 Aug 2025 02:39:12 +0300 Subject: [PATCH] the Add Profile button has been moved, and the layout has been slightly changed. --- src/pages/home.tsx | 490 ++++++++++++++++++++++++++------------------- 1 file changed, 283 insertions(+), 207 deletions(-) diff --git a/src/pages/home.tsx b/src/pages/home.tsx index a335894c..991757b9 100644 --- a/src/pages/home.tsx +++ b/src/pages/home.tsx @@ -48,14 +48,14 @@ const MinimalHomePage: React.FC = () => { const [isToggling, setIsToggling] = useState(false); const [isUpdating, setIsUpdating] = useState(false); const { profiles, patchProfiles, activateSelected, mutateProfiles } = - useProfiles(); + useProfiles(); const viewerRef = useRef(null); const [uidToActivate, setUidToActivate] = useState(null); const { connections } = useAppData(); const profileItems = useMemo(() => { const items = - profiles && Array.isArray(profiles.items) ? profiles.items : []; + profiles && Array.isArray(profiles.items) ? profiles.items : []; const allowedTypes = ["local", "remote"]; return items.filter((i: any) => i && allowedTypes.includes(i.type!)); }, [profiles]); @@ -66,20 +66,20 @@ const MinimalHomePage: React.FC = () => { const currentProfileName = currentProfile?.name || profiles?.current; const activateProfile = useCallback( - async (uid: string, notifySuccess: boolean) => { - try { - await patchProfiles({ current: uid }); - await closeAllConnections(); - await activateSelected(); - if (notifySuccess) { - toast.success(t("Profile Switched")); + async (uid: string, notifySuccess: boolean) => { + try { + await patchProfiles({ current: uid }); + await closeAllConnections(); + await activateSelected(); + if (notifySuccess) { + toast.success(t("Profile Switched")); + } + } catch (err: any) { + toast.error(err.message || err.toString()); + mutateProfiles(); } - } catch (err: any) { - toast.error(err.message || err.toString()); - mutateProfiles(); - } - }, - [patchProfiles, activateSelected, mutateProfiles, t], + }, + [patchProfiles, activateSelected, mutateProfiles, t], ); useEffect(() => { @@ -90,7 +90,6 @@ const MinimalHomePage: React.FC = () => { } }, [profileItems, activateProfile]); - const handleProfileChange = useLockFn(async (uid: string) => { if (profiles?.current === uid) return; await activateProfile(uid, true); @@ -102,7 +101,7 @@ const MinimalHomePage: React.FC = () => { const isTunAvailable = isServiceMode || isAdminMode; const isProxyEnabled = verge?.enable_system_proxy || verge?.enable_tun_mode; const showTunAlert = - (verge?.primary_action ?? "tun-mode") === "tun-mode" && !isTunAvailable; + (verge?.primary_action ?? "tun-mode") === "tun-mode" && !isTunAvailable; const handleToggleProxy = useLockFn(async () => { const turningOn = !isProxyEnabled; @@ -180,111 +179,188 @@ const MinimalHomePage: React.FC = () => { }, [isToggling, isProxyEnabled, t]); return ( -
-
- World map -
- - {isProxyEnabled && ( -
+
+ World map - )} - -
-
-
-
-
- {profileItems.length > 0 && ( -
- - - - - - {t("Profiles")} - - {profileItems.map((p) => ( - handleProfileChange(p.uid)} - > - {p.name} - {profiles?.current === p.uid && ( - - )} - - ))} - - viewerRef.current?.create()}> - - {t("Add Profile")} - - - -
- )} - {currentProfile?.type === 'remote' && ( -
- - - - - -

{t("Update Profile")}

-
-
-
- )} + + {isProxyEnabled && ( +
+ )} + +
+
+
-
-
-
-
- -
-
- {currentProfile?.announce && ( -
- {currentProfile.announce_url ? ( - - {currentProfile.announce.replace(/\\n/g, '\n')} - - +
+
+ {profileItems.length > 0 ? ( + <> +
+ + + + + + +

{t("Add Profile")}

+
+
+
+
+ + + + + + {t("Profiles")} + + {profileItems.map((p) => ( + handleProfileChange(p.uid)} + > + {p.name} + {profiles?.current === p.uid && ( + + )} + + ))} + + + {currentProfile?.type === 'remote' && ( +
+ + + + + +

{t("Update Profile")}

+
+
+
+ )} + ) : ( -

- {currentProfile.announce} -

+ <> +
+ + + + + + +

{t("Add Profile")}

+
+
+
+
+ + )}
- )} +
+
+
+ + +
+
+ {currentProfile?.announce && ( +
+ {currentProfile.announce_url ? ( + + {currentProfile.announce.replace(/\\n/g, '\n')} + + + ) : ( +

+ {currentProfile.announce} +

+ )} +
+ )}

{ > {statusInfo.text}

- {isProxyEnabled && ( -
-
- - {parseTraffic(connections.downloadTotal)} -
-
- - {parseTraffic(connections.uploadTotal)} -
-
- )} -
- -
- -
- - {showTunAlert && ( -
- - - {t("Attention Required")} - - {t("TUN requires Service Mode or Admin Mode")} - - {!isServiceMode && !isAdminMode && ( - - )} - + {isProxyEnabled && ( +
+
+ + {parseTraffic(connections.downloadTotal)} +
+
+ + {parseTraffic(connections.uploadTotal)} +
+
+ )}
- )} -
- {profileItems.length > 0 ? ( - - ) : ( - - - {t("Get Started")} - - {t( - "You don't have any profiles yet. Add your first one to begin.", - )} - - - +
+ +
+ + {showTunAlert && ( +
+ + + {t("Attention Required")} + + {t("TUN requires Service Mode or Admin Mode")} + + {!isServiceMode && !isAdminMode && ( + + )} + +
)} + +
+ {profileItems.length > 0 ? ( + + ) : ( + + + {t("Get Started")} + + {t( + "You don't have any profiles yet. Add your first one to begin.", + )} + + + + )} +
-
-
-
- {currentProfile?.support_url && ( -
+
+ - mutateProfiles()} /> -
+
+ )} + + mutateProfiles()} /> +
); }; -export default MinimalHomePage; +export default MinimalHomePage; \ No newline at end of file