From 8c14e7de305780f9976ec64fc37e6a94015d0cbb Mon Sep 17 00:00:00 2001 From: Nariman Jelveh Date: Sat, 7 Nov 2026 10:40:42 -0800 Subject: [PATCH] Add account links and Send feedback to (#4536) The signed-in menu now shows the user's picture, username and email (hidden when whoami leaves the email out), links to Manage account, Usage and Open Puter on the GUI origin in a new tab, and Send feedback, which calls puter.ui.showFeedbackDialog(). Each new item takes a label attribute like the existing ones. The menu opens on its first item, and the arrow, Home and End keys move between items. --- src/puter-js/src/ui/components.md | 11 +- .../src/ui/components/PuterUserMenu.js | 158 +++++++++++++++--- .../src/ui/components/PuterUserMenu.test.js | 99 ++++++++++- 3 files changed, 242 insertions(+), 26 deletions(-) diff --git a/src/puter-js/src/ui/components.md b/src/puter-js/src/ui/components.md index 52804aa65..5f6b034ab 100644 --- a/src/puter-js/src/ui/components.md +++ b/src/puter-js/src/ui/components.md @@ -340,7 +340,12 @@ el.open(); The account button and Puter's app browser for a first-party app on a Puter subdomain (`notes.puter.com`). It is internal and left out of the public docs, because the app browser only works one subdomain under the Puter origin. It follows the page's own puter.js sign-in, never the Puter session's. - Signed out, it shows **Sign in**, which calls `puter.auth.signIn()`. A temporary account counts as signed out. -- Signed in, it shows the user's profile picture, or the username's initial when there is none. Clicking it opens a menu with the username and **Sign out**, which calls `puter.auth.signOut()`. +- Signed in, it shows the user's profile picture, or the username's initial when there is none. Clicking it opens a menu with: + - The user's picture, username and email. The email line is hidden when whoami leaves it out, such as for an app that can't read it. + - **Manage account**, **Usage** and **Open Puter**, links that open the GUI origin's `/dashboard/#account`, `/dashboard/#usage` and `/` in a new tab. + - **Send feedback**, which calls `puter.ui.showFeedbackDialog()`. + - **Sign out**, which calls `puter.auth.signOut()`. +- The menu opens with focus on its first item. ArrowUp and ArrowDown move between items and wrap around, and Home and End jump to the first and last. - On a page exactly one label under the Puter origin, with the same scheme and port, an **Apps** button opens the app browser (`/embed/apps`) in a panel under the button. It names the signed-in user as `#user=`, so the app browser shows the Puter session's apps only to that user (see `doc/embedding-app-browser.md`), and passes a forced `theme` on as `theme=`. Elsewhere the button is hidden, because the server refuses the framing. - The menu and the Apps panel hang under their button with a caret pointing at it, and close on Escape, a press outside them, or their button. They're in the browser's top layer where it has one, so a host's `transform`, `overflow` or `z-index` can't clip or cover them. On screens up to 600px wide, the Apps panel spans the width below the button. - Closing the Apps panel keeps the app browser, so reopening it keeps its scroll and search. Any change to the page's sign-in discards it, so it never stays loaded for the previous user. @@ -355,6 +360,10 @@ The account button and Puter's app browser for a first-party app on a Puter subd | `sign-out-label` | `Sign out` | Sign-out menu item text | | `close-label` | `Close` | The Apps panel's close button label | | `account-label` | `Account` | Account button label, read as `Account: ` | +| `manage-account-label` | `Manage account` | Menu link to the account settings | +| `usage-label` | `Usage` | Menu link to the usage page | +| `open-puter-label` | `Open Puter` | Menu link to Puter | +| `feedback-label` | `Send feedback` | Menu item that opens the feedback dialog | | `theme` | follows the OS | `light` or `dark`, for the component and the app browser in it | Changing an attribute updates the component in place. diff --git a/src/puter-js/src/ui/components/PuterUserMenu.js b/src/puter-js/src/ui/components/PuterUserMenu.js index 4f3691247..b0797b13e 100644 --- a/src/puter-js/src/ui/components/PuterUserMenu.js +++ b/src/puter-js/src/ui/components/PuterUserMenu.js @@ -4,7 +4,8 @@ * * Signed out (a temporary account counts as signed out), it shows a Sign in * button. Signed in, it shows the user's profile picture (or initial), which - * opens a menu with the username and Sign out. On a page one subdomain under + * opens a menu with the account, links to manage it, see its usage and open + * Puter, Send feedback, and Sign out. On a page one subdomain under * the Puter origin, an Apps button opens Puter's app browser in a panel under * it, for the same user: signed out, or signed in as an account other than * the Puter session's, the browser shows only recommended apps. The browser @@ -12,7 +13,8 @@ * Renders nothing inside the Puter desktop. * * Attributes: theme, apps-label, sign-in-label, sign-out-label, close-label, - * account-label + * account-label, manage-account-label, usage-label, open-puter-label, + * feedback-label * Parts: apps-button, avatar, sign-in, menu, apps-panel * Events: signin (detail.user), signout */ @@ -24,6 +26,7 @@ import { canFrameGuiEmbed } from '../../lib/guiEmbed.js'; const APPS_ICON = ``; +const EXTERNAL_ICON = ''; const CLOSE_ICON = ''; const LABELS = { @@ -32,8 +35,19 @@ const LABELS = { 'sign-out-label': 'Sign out', 'close-label': 'Close', 'account-label': 'Account', + 'manage-account-label': 'Manage account', + 'usage-label': 'Usage', + 'open-puter-label': 'Open Puter', + 'feedback-label': 'Send feedback', }; +// Menu links, each opening a page of the Puter GUI in a new tab. +const MENU_LINKS = [ + { className: 'manage-account', label: 'manage-account-label', path: '/dashboard/#account' }, + { className: 'usage', label: 'usage-label', path: '/dashboard/#usage' }, + { className: 'open-puter', label: 'open-puter-label', path: '/' }, +]; + // Gap between a panel and the viewport edge, and between its caret and corners. const EDGE = 8; const CARET_INSET = 20; @@ -216,7 +230,8 @@ class PuterUserMenu extends PuterWebComponent { text-align: center; } .avatar[aria-expanded="true"] { box-shadow: 0 0 0 3px rgba(8, 142, 240, .25); } - .avatar img { + .avatar img, + .menu-avatar img { position: absolute; inset: 0; width: 100%; @@ -285,31 +300,78 @@ class PuterUserMenu extends PuterWebComponent { } .menu { - min-width: 200px; + min-width: 220px; max-width: min(300px, calc(100vw - ${EDGE * 2}px)); padding: 4px 0; text-align: left; } .menu-user { + display: flex; + align-items: center; + gap: 10px; padding: 8px 14px 10px; margin-bottom: 4px; border-bottom: 1px solid #eee; - color: #414650; - font-size: 14px; + } + .menu-avatar { + position: relative; + flex: none; + width: 40px; + height: 40px; + overflow: hidden; + border-radius: 50%; + background: linear-gradient(#34a5f8, #088ef0); + color: #fff; + font-size: 18px; font-weight: 600; + line-height: 40px; + text-align: center; + } + .menu-identity { + display: flex; + flex-direction: column; + min-width: 0; + } + .menu-username, + .menu-email { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } + .menu-username { + color: #414650; + font-size: 14px; + font-weight: 600; + } + .menu-email { + color: #6b7280; + font-size: 12px; + } .menu-item { - display: block; + display: flex; + align-items: center; + gap: 4px; + box-sizing: border-box; width: 100%; padding: 8px 14px; border: none; background: none; color: #333; font-size: 14px; + line-height: normal; text-align: left; + text-decoration: none; + cursor: pointer; + } + .menu-external { + flex: none; + fill: currentColor; + opacity: .7; + } + .menu-separator { + height: 1px; + margin: 4px 0; + background-color: #eee; } .menu-item:focus-visible { outline: none; @@ -411,7 +473,9 @@ class PuterUserMenu extends PuterWebComponent { } :host(.puter-theme-dark) .menu-user, :host(.puter-theme-dark) .apps-header { border-color: #3a3a3a; } - :host(.puter-theme-dark) .menu-user, + :host(.puter-theme-dark) .menu-separator { background-color: #3a3a3a; } + :host(.puter-theme-dark) .menu-email { color: #a0a0a0; } + :host(.puter-theme-dark) .menu-username, :host(.puter-theme-dark) .apps-title, :host(.puter-theme-dark) .menu-item { color: #e6e6e6; } :host(.puter-theme-dark) .menu-item:focus-visible { background-color: #3a3a3a; color: #fff; } @@ -442,7 +506,16 @@ class PuterUserMenu extends PuterWebComponent {