diff options
Diffstat (limited to 'packages/meshbay-hub/src/meshbay_hub/static/app.js')
| -rw-r--r-- | packages/meshbay-hub/src/meshbay_hub/static/app.js | 30 |
1 files changed, 26 insertions, 4 deletions
diff --git a/packages/meshbay-hub/src/meshbay_hub/static/app.js b/packages/meshbay-hub/src/meshbay_hub/static/app.js index c1913c0..b9466d0 100644 --- a/packages/meshbay-hub/src/meshbay_hub/static/app.js +++ b/packages/meshbay-hub/src/meshbay_hub/static/app.js @@ -429,7 +429,7 @@ function Nav({ user, theme, onThemeChange, onLogout, onMenuToggle, unreadCount, // ── Sidebar ────────────────────────────────────────────────────────────────── -function Sidebar({ groups, presence, indexProgressPct, route, menuOpen, role, hasNodeKey, +function Sidebar({ groups, presence, indexProgressPct, route, menuOpen, role, showNode, allowPublicGroups = true }) { const isStaff = role === 'moderator' || role === 'admin'; return html` @@ -449,7 +449,7 @@ function Sidebar({ groups, presence, indexProgressPct, route, menuOpen, role, ha <a class="sidebar-item ${route === '/search' ? 'active' : ''}" href="#/search"><${Icon} name="search" /> ${t('sidebar.search')}</a> </div> - ${platform.capabilities.nodeAdmin && hasNodeKey && html` + ${platform.capabilities.nodeAdmin && showNode && html` <div class="sidebar-section"> <div class="sidebar-heading">${t('sidebar.node')}</div> <a class="sidebar-item ${route === '/node' ? 'active' : ''}" @@ -781,6 +781,9 @@ function App() { const [notifDisabled, setNotifDisabled] = useState(false); const [userPrefs, setUserPrefs] = useState({}); const [hasNodeKey, setHasNodeKey] = useState(false); + // A node on this machine, linked to the account or not: the Node section is + // where it is looked after, so it cannot wait for a link to show up. + const [localNode, setLocalNode] = useState(false); // Instance policy, fetched once, unauthenticated. `null` until it answers; // treat unknown as "allowed" so a slow hub never blocks a legitimate private // group — the hub refuses a public one server-side regardless. @@ -1041,6 +1044,25 @@ function App() { fetchNotifications(); }, [user]); + // The node this application ships, set up, started and linked for whoever + // signs in (main.js `ensureNode`): installing it is all it should take. + // Keyed on the account, not the session object -- the token rotates, and a + // renewal is not a sign-in. + const signedInAs = user ? user.username : null; + useEffect(() => { + setLocalNode(false); + if (!signedInAs || !platform.capabilities.nodeAdmin || !platform.node.available) return; + let cancelled = false; + platform.node.installed() + .then((r) => { if (!cancelled) setLocalNode(Boolean(r && r.installed)); }) + .catch(() => {}); + const live = userRef.current; + platform.node.ensure({ username: live.username, token: live.token }) + .then(() => { if (!cancelled) refreshNodeKey(); }) + .catch(() => {}); + return () => { cancelled = true; }; + }, [signedInAs]); + // After an invitation is accepted: the group is ours now, and only the hub // knows its row the way `/mine` answers it. const reloadGroups = useCallback(() => { @@ -1316,7 +1338,7 @@ function App() { .catch(() => {}); refreshNodeKey(); }} />`; - } else if (route === '/node' && platform.capabilities.nodeAdmin && hasNodeKey) { + } else if (route === '/node' && platform.capabilities.nodeAdmin && (hasNodeKey || localNode)) { page = html`<${LazyNodePage} groups=${groups} token=${user.token} username=${user.username} />`; } else if (groupId) { page = html`<${GroupPage} @@ -1380,7 +1402,7 @@ function App() { menuOpen=${menuOpen} role=${user.role} allowPublicGroups=${allowPublicGroups} - hasNodeKey=${hasNodeKey} />`} + showNode=${hasNodeKey || localNode} />`} ${menuOpen && html`<div class="overlay visible" onClick=${() => setMenuOpen(false)} />`} <main class="main"> |