Skip to content

Commit e5ea85e

Browse files
cynfriaPeppermint ButlerCarlMongoPrincess Donut
authored
Polish the channel sidebar (#235)
Signed-off-by: Peppermint Butler <29b529ff43be424db89f51bff58a38cf86942acbffff98a14ce50b38c2a57d8f@buzz.block.builderlab.xyz> Signed-off-by: Carl <32a2e2c9d428ee08902cab75d956da2c1d235a22d4766b0dd4138bf6e2e5db1d@buzz.block.builderlab.xyz> Co-authored-by: Peppermint Butler <29b529ff43be424db89f51bff58a38cf86942acbffff98a14ce50b38c2a57d8f@buzz.block.builderlab.xyz> Co-authored-by: Carl <32a2e2c9d428ee08902cab75d956da2c1d235a22d4766b0dd4138bf6e2e5db1d@buzz.block.builderlab.xyz> Co-authored-by: Mongo <81cabd2ca1792494372ed410283c00770c0cf35afca052e940fa522883212b45@buzz.block.builderlab.xyz> Co-authored-by: Princess Donut <5d97ac8c272fa949af56c71e586146b1706e5c4c3daa125db5b4625e12e0686c@buzz.block.builderlab.xyz> Co-authored-by: Mordecai <f314b6033b6e13df94c8e9e1187d3666b6b9ce54e66ee986e31cdaa909e8dcbc@buzz.block.builderlab.xyz>
1 parent 07f071a commit e5ea85e

77 files changed

Lines changed: 2659 additions & 1313 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎public/buzz-mark.svg‎

Lines changed: 10 additions & 0 deletions
Loading

‎src/app/App.tsx‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ export function App({ services }: { services: AppServices }) {
6060
<ToastProvider>
6161
<ChannelNavigationProvider relay={services.relay}>
6262
<AppShell
63-
sidebar={(pageNavigation) => (
63+
sidebar={() => (
6464
<ChannelSidebar
6565
relay={services.relay}
6666
navigator={services.navigation}
@@ -69,9 +69,10 @@ export function App({ services }: { services: AppServices }) {
6969
sessionsEnabled={route.pages.some(
7070
(page) => page.pluginId === "buzz.sessions",
7171
)}
72-
>
73-
<div className="shell-page-navigation-slot">{pageNavigation}</div>
74-
</ChannelSidebar>
72+
agentsEnabled={route.pages.some(
73+
(page) => page.key === "buzz.agents/agents",
74+
)}
75+
/>
7576
)}
7677
navigationControls={
7778
<NavigationControls navigation={services.navigation} />

‎src/app/Settings.module.css‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
container-type: inline-size;
77
overflow: hidden;
88
}
9+
.root > [data-buzz-surface] {
10+
height: 100%;
11+
overflow-y: auto;
12+
}
913
.layout {
1014
display: grid;
1115
grid-template-columns: var(--size-navigator) minmax(0, 1fr);
@@ -67,3 +71,29 @@
6771
padding-bottom: var(--space-16);
6872
}
6973
}
74+
75+
.settingsSidebar {
76+
height: 100%;
77+
min-height: 0;
78+
overflow-y: auto;
79+
padding-block-start: var(--sidebar-padding);
80+
}
81+
.settingsNavigation {
82+
display: flex;
83+
flex-direction: column;
84+
gap: var(--space-5);
85+
padding-block: var(--space-5) var(--space-2);
86+
}
87+
.settingsGroupTitle {
88+
margin: 0 0 var(--space-1);
89+
padding-inline: var(--space-2);
90+
color: var(--text-unavailable);
91+
font-size: var(--text-body-sm);
92+
line-height: var(--text-body-sm--line-height);
93+
font-weight: var(--type-weight-normal);
94+
}
95+
.settingsGroupItems {
96+
display: flex;
97+
flex-direction: column;
98+
gap: var(--space-half);
99+
}

‎src/app/Settings.test.tsx‎

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
fireEvent,
77
render,
88
screen,
9+
waitFor,
910
} from "@testing-library/react";
1011
import { afterEach, expect, it, vi } from "vitest";
1112
import type { Contribution } from "../plugins/contributions";
@@ -105,36 +106,50 @@ it("keeps grouped cards available without a selected community", () => {
105106
expect(screen.queryByRole("button", { name: "Personal groups" })).toBeNull();
106107
});
107108

108-
it("gives contributed cards their own community sections and retires removed cards", () => {
109+
it("gives contributed cards their own community sections and retires removed cards", async () => {
109110
const { cards, set } = registry([
110111
card("hosted", "Hosted communities", "Communities"),
111112
card("groups", "Personal groups"),
112113
]);
113-
render(<Settings {...host} cards={cards} />);
114+
const complete = vi.fn(() => true);
115+
const onSection = vi.fn();
116+
render(
117+
<Settings
118+
{...host}
119+
cards={cards}
120+
navigation={
121+
{
122+
target: {
123+
version: 1,
124+
kind: "settings",
125+
section: "example/hosted",
126+
},
127+
complete,
128+
} as never
129+
}
130+
onSection={onSection}
131+
/>,
132+
);
114133
const nav = screen.getByRole("navigation", { name: "Settings sections" });
115134
expect(nav).toHaveTextContent("Primary");
116135
expect(nav).toHaveTextContent("Communities");
117-
expect(screen.queryByText("Hosted communities body")).toBeNull();
118-
119-
fireEvent.click(screen.getByRole("button", { name: "Hosted communities" }));
120-
expect(screen.getByText("Hosted communities body")).toBeVisible();
136+
expect(await screen.findByText("Hosted communities body")).toBeVisible();
121137
expect(
122138
screen.getByRole("button", { name: "Hosted communities" }),
123139
).toHaveAttribute("aria-current", "page");
124140
expect(screen.queryByText("Personal groups body")).toBeNull();
141+
expect(complete).toHaveBeenLastCalledWith({ status: "opened" });
125142

126-
fireEvent.click(screen.getByRole("button", { name: "Personal groups" }));
127-
expect(screen.getByText("Personal groups body")).toBeVisible();
128-
expect(screen.queryByText("Hosted communities body")).toBeNull();
129-
130-
fireEvent.click(screen.getByRole("button", { name: "Hosted communities" }));
131143
act(() => set([card("groups", "Personal groups")]));
144+
await waitFor(() => expect(onSection).toHaveBeenLastCalledWith("profile"));
132145
expect(screen.queryByText("Hosted communities body")).toBeNull();
146+
expect(screen.queryByRole("alert")).toBeNull();
133147
expect(nav).not.toHaveTextContent("Hosted communities");
134148
expect(screen.getByRole("button", { name: "Profile" })).toHaveAttribute(
135149
"aria-current",
136150
"page",
137151
);
152+
expect(nav.querySelectorAll('[aria-current="page"]')).toHaveLength(1);
138153
});
139154

140155
it("keeps same-id community cards from different plugins distinct", () => {

‎src/app/Settings.tsx‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,11 @@ export function Settings({
138138
visibleSections.some((section) => section.id === requestedSection)
139139
)
140140
setSelected(requestedSection);
141-
else if (!visibleSections.some((section) => section.id === selected))
141+
else if (!visibleSections.some((section) => section.id === selected)) {
142142
setSelected(defaultSection);
143-
}, [defaultSection, requestedSection, selected, visibleSections]);
143+
if (requestedSection === selected) onSection?.(defaultSection);
144+
}
145+
}, [defaultSection, onSection, requestedSection, selected, visibleSections]);
144146
useEffect(() => {
145147
if (requestedSection === selected)
146148
navigation?.complete({ status: "opened" });

‎src/app/navigation.ts‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import {
22
useEffect,
33
useLayoutEffect,
44
useMemo,
5+
useRef,
56
useState,
67
useSyncExternalStore,
78
} from "react";
@@ -34,6 +35,8 @@ export function useAppNavigation(services: AppServices) {
3435
);
3536
const startup = plugins.configuration.status;
3637
const target = state.entry.target;
38+
const lastNonSettings = useRef<OpenTarget | undefined>(undefined);
39+
if (target.kind !== "settings") lastNonSettings.current = target;
3740
const scope = "scope" in target ? target.scope : undefined;
3841
const pageKey =
3942
target.kind === "page"
@@ -239,6 +242,31 @@ export function useAppNavigation(services: AppServices) {
239242
waiting,
240243
failure,
241244
selected: pageKey ?? target.kind,
245+
leaveSettings() {
246+
const previous = lastNonSettings.current;
247+
if (previous) {
248+
void navigation.open(previous);
249+
return;
250+
}
251+
const selectedClient = services.communities.snapshot();
252+
if (!selectedClient.viewer) return;
253+
void navigation.open({
254+
version: 1,
255+
kind: "page",
256+
pluginId: "buzz.channels",
257+
pageId: "channels",
258+
...(selectedClient.selected
259+
? {
260+
scope: {
261+
viewer: selectedClient.viewer,
262+
communityOrigin: communityDestination(selectedClient.selected)
263+
.url,
264+
},
265+
}
266+
: { scope: null }),
267+
route: { version: 1, params: "Inbox" },
268+
});
269+
},
242270
retry() {
243271
// Retrying presentation must also repair its failed dependency. Only touch the
244272
// selected, authorized destination; never reconnect an unrelated community.

‎src/app/shell/PageSearch.test.tsx‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,3 +251,33 @@ it("renders a restored prototype-named search key and remains resettable", async
251251
await root.fiber.dispose();
252252
}
253253
});
254+
255+
it.each(["pointer", "keyboard"])(
256+
"hands %s page selection to main, not its first control",
257+
async (method) => {
258+
Object.defineProperty(HTMLElement.prototype, "scrollIntoView", {
259+
configurable: true,
260+
value: vi.fn(),
261+
});
262+
const user = userEvent.setup();
263+
const select = vi.fn();
264+
render(
265+
<>
266+
<PageSearch pages={[]} onSelect={select} />
267+
<main id="main-content" tabIndex={-1}>
268+
<button type="button">First control</button>
269+
</main>
270+
</>,
271+
);
272+
const trigger = screen.getByRole("button", { name: "Search Buzz" });
273+
await user.click(trigger);
274+
if (method === "pointer")
275+
await user.click(screen.getByRole("option", { name: "Settings" }));
276+
else await user.keyboard("{ArrowDown}{Enter}");
277+
expect(select).toHaveBeenCalledExactlyOnceWith("settings");
278+
await vi.waitFor(() => expect(screen.getByRole("main")).toHaveFocus());
279+
await user.click(trigger);
280+
await user.keyboard("{Escape}");
281+
await vi.waitFor(() => expect(trigger).toHaveFocus());
282+
},
283+
);

‎src/app/shell/PageSearch.tsx‎

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,22 @@ export function PageSearch({
124124
motion="none"
125125
closeLabel="Close search"
126126
initialFocus={input}
127-
finalFocus={returnFocus}
127+
finalFocus={() =>
128+
returnFocus.current?.id === "main-content"
129+
? false
130+
: returnFocus.current
131+
}
132+
onOpenChangeComplete={(open) => {
133+
// Base UI otherwise chooses main's first tabbable child. Preserve a
134+
// destination's own focus target if it already presented one.
135+
const main = returnFocus.current;
136+
if (
137+
!open &&
138+
main?.id === "main-content" &&
139+
!main.contains(document.activeElement)
140+
)
141+
main.focus({ preventScroll: true });
142+
}}
128143
>
129144
{open &&
130145
(services ? (

‎src/bundled/agents/AgentControlPanel.tsx‎

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -128,14 +128,8 @@ export function AgentControlPanel({
128128
aria-label="Local agent controls"
129129
className="agent-controls flex min-w-0 flex-col gap-section-gap text-body text-primary"
130130
>
131-
<header className="flex flex-wrap items-center justify-between gap-4">
132-
<div className="flex min-w-0 flex-col gap-2">
133-
<h1 className="m-0 text-title">Agents</h1>
134-
<p className="m-0 text-body-sm text-secondary">
135-
Manage your agents and bring them into a conversation.
136-
</p>
137-
</div>
138-
{state.data && (
131+
{state.data && (
132+
<div className="flex justify-end">
139133
<Button
140134
variant="primary"
141135
aria-haspopup="dialog"
@@ -149,8 +143,8 @@ export function AgentControlPanel({
149143
<PlusIcon size={16} aria-hidden="true" />
150144
Add agent
151145
</Button>
152-
)}
153-
</header>
146+
</div>
147+
)}
154148
{(state.status === "idle" || state.status === "loading") && (
155149
<p role="status">Reading local agent status…</p>
156150
)}

0 commit comments

Comments
 (0)