Skip to content

Commit 561265d

Browse files
matt2eclaude
andauthored
fix(profiles): offer Edit profile on your own side-panel profile (#1953)
Signed-off-by: Matt Toohey <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]>
1 parent 8fdb02d commit 561265d

3 files changed

Lines changed: 65 additions & 18 deletions

File tree

‎src/bundled/profiles/ProfilePanel.message.test.tsx‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,29 @@ function deferred() {
103103
return { promise, resolve, reject };
104104
}
105105
const message = () => screen.queryByRole("button", { name: "Message" });
106+
const editProfile = () =>
107+
screen.queryByRole("button", { name: "Edit profile" });
108+
109+
it("offers Edit profile only on the viewer's own profile in a community and opens its Settings there", () => {
110+
const f = fixture();
111+
const view = render(f.panel(person));
112+
expect(message()).toBeTruthy();
113+
expect(editProfile()).toBeNull();
114+
view.rerender(f.panel(viewer));
115+
expect(message()).toBeNull();
116+
fireEvent.click(editProfile() as HTMLElement);
117+
expect(f.navigate).toHaveBeenCalledExactlyOnceWith({
118+
version: 1,
119+
kind: "settings",
120+
section: "profile",
121+
scope: { viewer, communityOrigin: origin },
122+
});
123+
// A scope for another identity names no community for this viewer.
124+
f.reconnect(`${origin}:${other}`);
125+
expect(screen.getByRole("region", { name: "Profile details" })).toBeTruthy();
126+
expect(editProfile()).toBeNull();
127+
f.owner.dispose();
128+
});
106129

107130
it("offers Message only for a foreign profile on a DM-capable connection", () => {
108131
const unavailable = fixture(false);

‎src/bundled/profiles/ProfilePanel.tsx‎

Lines changed: 41 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,11 @@ function ProfileDetails({
360360
[picture, name, knownAgent],
361361
);
362362
usePanelTabTitle(name, tabAvatar);
363+
// Targets opened from this panel stay in its community.
364+
const scoped =
365+
navigation && viewer && communityOrigin
366+
? { navigation, scope: { viewer, communityOrigin } }
367+
: undefined;
363368
const {
364369
available: canMessage,
365370
opening: openingMessage,
@@ -370,17 +375,25 @@ function ProfileDetails({
370375
pubkey,
371376
viewer,
372377
agent: displayAgent,
373-
enabled: !!navigation && !!communityOrigin,
378+
enabled: !!scoped,
374379
onOpened(channelId) {
375-
if (navigation && viewer && communityOrigin)
376-
void navigation.open({
377-
version: 1,
378-
kind: "conversation",
379-
channelId,
380-
scope: { viewer, communityOrigin },
381-
});
380+
void scoped?.navigation.open({
381+
version: 1,
382+
kind: "conversation",
383+
channelId,
384+
scope: scoped.scope,
385+
});
382386
},
383387
});
388+
const canEdit = !!scoped && viewer === pubkey;
389+
// Settings edits the selected community's profile, so bind it to this one.
390+
const editProfile = () =>
391+
void scoped?.navigation.open({
392+
version: 1,
393+
kind: "settings",
394+
section: "profile",
395+
scope: scoped.scope,
396+
});
384397

385398
return (
386399
<section
@@ -419,16 +432,27 @@ function ProfileDetails({
419432
)}
420433
<UserStatusDisplay session={session} userId={pubkey} />
421434
</div>
422-
{canMessage && (
435+
{(canMessage || canEdit) && (
423436
<div className={hero.actions}>
424-
<Button
425-
size="sm"
426-
variant={picture ? "glass" : "subtle"}
427-
loading={openingMessage}
428-
onClick={() => void openMessage()}
429-
>
430-
Message
431-
</Button>
437+
{canMessage && (
438+
<Button
439+
size="sm"
440+
variant={picture ? "glass" : "subtle"}
441+
loading={openingMessage}
442+
onClick={() => void openMessage()}
443+
>
444+
Message
445+
</Button>
446+
)}
447+
{canEdit && (
448+
<Button
449+
size="sm"
450+
variant={picture ? "glass" : "subtle"}
451+
onClick={editProfile}
452+
>
453+
Edit profile
454+
</Button>
455+
)}
432456
</div>
433457
)}
434458
{messageError && (

‎src/bundled/profiles/README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ See who someone is, their status, and the channels they're in.
66

77
1. Click a name or picture in a conversation to open their profile.
88
2. Choose **Message** to start a direct message, or **Copy npub** to share their key.
9-
3. Choose **View your profile** in your profile menu to see your own.
9+
3. Open your own profile the same way, then choose **Edit profile** to change it.

0 commit comments

Comments
 (0)