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 | 41 |
1 files changed, 29 insertions, 12 deletions
diff --git a/packages/meshbay-hub/src/meshbay_hub/static/app.js b/packages/meshbay-hub/src/meshbay_hub/static/app.js index 6b20a63..875b1aa 100644 --- a/packages/meshbay-hub/src/meshbay_hub/static/app.js +++ b/packages/meshbay-hub/src/meshbay_hub/static/app.js @@ -3,7 +3,7 @@ import { clearPending, loadPending } from './invite-link.js'; import { html, render, useState, useEffect, useLayoutEffect, useCallback, useRef, - createContext, useContext, + createContext, } from './vendor/htm-preact.js'; import { t, getLocale, setLocale, initLocale, LOCALES } from './i18n.js'; import { ZipStream, entriesUnder } from './zipstream.js'; @@ -72,7 +72,6 @@ function useRoute() { // ── Context ────────────────────────────────────────────────────────────────── const AuthContext = createContext(null); -function useAuth() { return useContext(AuthContext); } // The M of the wordmark is a picture; the rest is text. Resolved from this // module's own URL so the hub's fingerprinted path and the application's @@ -304,6 +303,7 @@ function TransferRow({ it }) { </button> `} </div> + ${it.note && html`<div class="transfer-meta transfer-note">${it.note}</div>`} ${it.status === 'preparing' ? html` ${/* Not a progress bar at 0%: nothing is wrong and nothing is @@ -645,10 +645,6 @@ function LazyCreateGroupPage(props) { return html`<${_CreateGroupPage} ...${props} />`; } -// ── Settings Page ─────────────────────────────────────────────────────────── - -const THEME_OPTIONS = ['light', 'dark', 'system']; - // ── Profile Page ──────────────────────────────────────────────────────────── // // ── Lazy-loaded Admin page (admin/moderator only) ───────────────────────── @@ -924,8 +920,31 @@ function App() { .catch(() => {}); }, [user, notifDisabled]); + // Whether this account has a node linked, which is what shows the sidebar's + // Node section. Asked again whenever a node may just have been linked (the + // Create Group wizard), not only when the session changes -- the section + // stayed hidden until a reload after the first group -- and retried rather + // than left false by one failed request after a session blip. + const nodeKeyAskedForRef = useRef(null); + const refreshNodeKey = useCallback(() => { + nodeKeyAskedForRef.current = user; + if (!user || !platform.capabilities.nodeAdmin) return; + // A late answer, or a retry, must not land on a session that has changed. + const current = () => nodeKeyAskedForRef.current === user; + const ask = (attempt) => hubFetch(`/v1/users/${user.username}/pubkeys`, { token: user.token }) + .then(data => { if (current()) setHasNodeKey(Boolean(data.pk_node_ed25519)); }) + .catch(() => { + if (attempt < 3 && current()) setTimeout(() => ask(attempt + 1), 2000 * attempt); + }); + ask(1); + }, [user]); + useEffect(() => { - if (!user) { setGroups([]); setNotifications([]); setUnreadCount(0); setHasNodeKey(false); return; } + if (!user) { + nodeKeyAskedForRef.current = null; + setGroups([]); setNotifications([]); setUnreadCount(0); setHasNodeKey(false); + return; + } hubFetch('/v1/groups/mine', { token: user.token }) .then(data => setGroups(data.groups || [])) .catch(() => setGroups([])); @@ -935,11 +954,7 @@ function App() { if (prefs.notifications_disabled === 'true') setNotifDisabled(true); }) .catch(() => {}); - if (platform.capabilities.nodeAdmin) { - hubFetch(`/v1/users/${user.username}/pubkeys`, { token: user.token }) - .then(data => setHasNodeKey(Boolean(data.pk_node_ed25519))) - .catch(() => {}); - } + refreshNodeKey(); fetchNotifications(); }, [user]); @@ -1176,10 +1191,12 @@ function App() { } else if (route === '/create-group') { page = html`<${LazyCreateGroupPage} token=${user.token} username=${user.username} allowPublicGroups=${allowPublicGroups} + onNodeLinked=${refreshNodeKey} onCreated=${() => { hubFetch('/v1/groups/mine', { token: user.token }) .then(data => setGroups(data.groups || [])) .catch(() => {}); + refreshNodeKey(); }} />`; } else if (route === '/node' && platform.capabilities.nodeAdmin && hasNodeKey) { page = html`<${LazyNodePage} groups=${groups} token=${user.token} username=${user.username} />`; |