@broberg/app-shell 0.4.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -51,6 +51,23 @@ the user menu reads and writes theme, palette, surfaces and backdrop through it.
51
51
  | `Avatar` | `picture` when given, otherwise initials. |
52
52
  | `AccountPage` | The user's own name and picture, edited inside the app (0.4.0). |
53
53
 
54
+ ## 0.5.0 — the user menu follows the account page (F095.5)
55
+
56
+ `onProfileChange(profile)` is called with the profile **as the server now holds
57
+ it** after a name save, a picture upload or a removal. It is never called on load
58
+ or after a failed save. Pass it to the shell's `user`, so the menu changes at once:
59
+
60
+ ```tsx
61
+ const [user, setUser] = useState(sessionUser);
62
+ <AppShell user={user} …>
63
+ <AccountPage lang="da" onProfileChange={(p) => setUser({ ...user, name: p.name ?? undefined, picture: p.picture ?? undefined })} />
64
+ </AppShell>
65
+ ```
66
+
67
+ With `@broberg/sso` ≥0.11 the session cookie is re-signed with the new name and
68
+ picture as well, so the menu is also right after a reload. «Gem» is disabled
69
+ while the name (trimmed) equals what the server holds.
70
+
54
71
  ## 0.4.0 — AccountPage: name and picture, edited inside the app (F095.3)
55
72
 
56
73
  The user changes their own name and profile picture without leaving for
package/dist/preact.cjs CHANGED
@@ -1004,7 +1004,7 @@ function defaultReauthHref() {
1004
1004
  const here = typeof location === "undefined" ? "/" : location.pathname + location.search;
1005
1005
  return `/auth/login?returnTo=${encodeURIComponent(here)}`;
1006
1006
  }
1007
- function AccountPage({ lang, adapter, reauthHref }) {
1007
+ function AccountPage({ lang, adapter, reauthHref, onProfileChange }) {
1008
1008
  const t = TEXT[lang];
1009
1009
  const api = hooks.useMemo(() => adapter ?? createFetchAccountAdapter(), [adapter]);
1010
1010
  const [profile, setProfile] = hooks.useState(null);
@@ -1043,7 +1043,9 @@ function AccountPage({ lang, adapter, reauthHref }) {
1043
1043
  setBusy(what);
1044
1044
  setNotice(null);
1045
1045
  try {
1046
- apply(await op());
1046
+ const p = await op();
1047
+ apply(p);
1048
+ onProfileChange?.(p);
1047
1049
  setNotice({ kind: "ok", text: okText });
1048
1050
  } catch (e) {
1049
1051
  fail(e, t.couldNotSave);
@@ -1053,7 +1055,7 @@ function AccountPage({ lang, adapter, reauthHref }) {
1053
1055
  };
1054
1056
  const onSaveName = (e) => {
1055
1057
  e.preventDefault();
1056
- if (busy || reauth) return;
1058
+ if (busy || reauth || unchanged) return;
1057
1059
  void run("name", () => api.saveName(draft), t.saved);
1058
1060
  };
1059
1061
  const onFile = (e) => {
@@ -1073,6 +1075,7 @@ function AccountPage({ lang, adapter, reauthHref }) {
1073
1075
  void run("avatar", () => api.removeAvatar(), t.pictureRemoved);
1074
1076
  };
1075
1077
  const locked = reauth || busy !== null || profile === null;
1078
+ const unchanged = draft.trim() === (profile?.name ?? "").trim();
1076
1079
  const user = { name: profile?.name ?? void 0, email: profile?.email ?? void 0, picture: profile?.picture ?? void 0 };
1077
1080
  return /* @__PURE__ */ jsxRuntime.jsxs("section", { class: "bas-account", "data-testid": "account-page", "aria-busy": busy !== null, children: [
1078
1081
  reauth ? /* @__PURE__ */ jsxRuntime.jsxs("div", { class: "bas-account__note is-reauth", role: "alert", "data-testid": "account-reauth", children: [
@@ -1147,7 +1150,7 @@ function AccountPage({ lang, adapter, reauthHref }) {
1147
1150
  "data-testid": "account-name-input"
1148
1151
  }
1149
1152
  ),
1150
- /* @__PURE__ */ jsxRuntime.jsx("button", { type: "submit", class: "bas-account__btn is-primary", disabled: locked, "data-testid": "account-name-save", children: busy === "name" ? t.saving : t.save })
1153
+ /* @__PURE__ */ jsxRuntime.jsx("button", { type: "submit", class: "bas-account__btn is-primary", disabled: locked || unchanged, "data-testid": "account-name-save", children: busy === "name" ? t.saving : t.save })
1151
1154
  ] })
1152
1155
  ] }),
1153
1156
  profile.account_url ? /* @__PURE__ */ jsxRuntime.jsx(NavLink, { href: profile.account_url, class: "bas-account__link", "data-testid": "account-bid-link", children: t.bidSecurity }) : null