diff --git a/core/http/react-ui/src/hooks/useP2PMode.js b/core/http/react-ui/src/hooks/useP2PMode.js new file mode 100644 index 000000000..98676df9f --- /dev/null +++ b/core/http/react-ui/src/hooks/useP2PMode.js @@ -0,0 +1,31 @@ +import { useState, useEffect, useCallback } from 'react' +import { p2pApi } from '../utils/api' + +// useP2PMode reports whether p2p / swarm mode is available, mirroring +// useDistributedMode. Availability is "a network token exists" (the same signal +// the standalone P2P page used). One-shot probe on mount plus a manual refetch. +// +// Returns: +// enabled — true when a non-empty network token is present +// loading — true until the first probe completes +// refetch — manual trigger to re-run the probe +export function useP2PMode() { + const [enabled, setEnabled] = useState(false) + const [loading, setLoading] = useState(true) + + const probe = useCallback(async () => { + setLoading(true) + try { + const token = await p2pApi.getToken() + setEnabled(!!(token && String(token).trim())) + } catch { + setEnabled(false) + } finally { + setLoading(false) + } + }, []) + + useEffect(() => { probe() }, [probe]) + + return { enabled, loading, refetch: probe } +} diff --git a/core/http/react-ui/src/pages/Nodes.jsx b/core/http/react-ui/src/pages/Nodes.jsx index f2eb9d955..7ddcf94e8 100644 --- a/core/http/react-ui/src/pages/Nodes.jsx +++ b/core/http/react-ui/src/pages/Nodes.jsx @@ -689,7 +689,7 @@ function SchedulingForm({ onSave, onCancel }) { ) } -export default function Nodes() { +export default function Nodes({ embedded = false }) { const { addToast } = useOutletContext() const navigate = useNavigate() const { t } = useTranslation('admin') @@ -983,16 +983,18 @@ export default function Nodes() { const pending = filteredNodes.filter(n => n.status === 'pending').length return ( -
-
-

- - {t('nodes.title')} -

-

- {t('nodes.subtitle')} -

-
+
+ {!embedded && ( +
+

+ + {t('nodes.title')} +

+

+ {t('nodes.subtitle')} +

+
+ )} {/* Tabs */}
diff --git a/core/http/react-ui/src/pages/P2P.jsx b/core/http/react-ui/src/pages/P2P.jsx index 7e52d1c77..02641499b 100644 --- a/core/http/react-ui/src/pages/P2P.jsx +++ b/core/http/react-ui/src/pages/P2P.jsx @@ -102,7 +102,7 @@ function StepNumber({ n, bg, color }) { ) } -export default function P2P() { +export default function P2P({ embedded = false }) { const { addToast } = useOutletContext() const { t } = useTranslation('admin') const [workers, setWorkers] = useState([]) @@ -172,7 +172,7 @@ export default function P2P() { if (loading) { return ( -
+
) @@ -181,7 +181,7 @@ export default function P2P() { // ── P2P Disabled ── if (!enabled) { return ( -
+

@@ -294,21 +294,23 @@ export default function P2P() { const mlxTotal = stats.mlx_workers?.total ?? 0 return ( -
-
-

- - {t('p2p.title')} -

-

- {t('p2p.subtitle')} - {' '} - - - -

-
+
+ {!embedded && ( +
+

+ + {t('p2p.title')} +

+

+ {t('p2p.subtitle')} + {' '} + + + +

+
+ )} {/* Network Token */}