Skip to content

Commit 5433f67

Browse files
committed
fix(web): keep sparse sidebar shelves at the bottom
1 parent e628683 commit 5433f67

3 files changed

Lines changed: 78 additions & 17 deletions

File tree

‎apps/web/src/components/Sidebar.drag.test.ts‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,37 @@ describe("sidebar collision detection", () => {
253253
});
254254

255255
describe("sidebar drag projection", () => {
256+
it.each([
257+
["a1", "a2"],
258+
["a1", sidebarMarkerId("settled-header")],
259+
["z", "a2"],
260+
])("keeps sparse shelves at the bottom when dragging %s over %s", (active, over) => {
261+
const items = [
262+
pinnedHeader,
263+
divider,
264+
thread("a1", "active"),
265+
thread("a2", "active"),
266+
marker("snoozed-header"),
267+
thread("z", "snoozed"),
268+
settledHeader,
269+
thread("s", "settled"),
270+
];
271+
const strategy = createSidebarSortingStrategy({
272+
items,
273+
settledOrder: over === sidebarMarkerId("settled-header") ? ["a1", "s"] : ["s"],
274+
settledExpanded: true,
275+
boundaryLabelHeight: 24,
276+
snoozedThreadCount: 1,
277+
});
278+
const args = layout(items, active, over);
279+
for (const rect of args.rects.slice(4)) {
280+
rect.top += 400;
281+
rect.bottom += 400;
282+
}
283+
const lastIndex = items.length - 1;
284+
expect(strategy({ ...args, index: lastIndex })).toEqual(stationary);
285+
});
286+
256287
const pinned = [
257288
pinnedHeader,
258289
thread("p1", "pinned"),

‎apps/web/src/components/Sidebar.drag.ts‎

Lines changed: 40 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -190,27 +190,54 @@ export function createSidebarSortingStrategy(input: {
190190
}
191191
marker("settled-header");
192192
section("settled");
193-
const result = items.map(() => hidden);
194-
let top = rects[0].top;
195-
for (const item of projected) {
193+
const heights = projected.map((item) => {
196194
const index = indices.get(sidebarListItemId(item));
197195
const rect = index === undefined ? undefined : rects[index];
198-
if (index !== undefined && rect) result[index] = { ...stationary, y: top - rect.top };
199196
const fallback =
200197
item.kind === "thread" && (item.section === "pinned" || item.section === "active")
201198
? cardHeight
202199
: slimHeight;
203200
const moved = item.kind === "thread" && item.key === active.key;
204-
const height =
205-
item.kind === "marker" &&
201+
return item.kind === "marker" &&
206202
(item.marker === "pinned-header" || item.marker === "pinned-divider")
207-
? labelHeight
208-
: item.kind === "marker" && item.marker.endsWith("placeholder")
209-
? slimHeight
210-
: moved
211-
? fallback
212-
: (rect?.height ?? fallback);
213-
top += height + 1;
203+
? labelHeight
204+
: item.kind === "marker" && item.marker.endsWith("placeholder")
205+
? slimHeight
206+
: moved
207+
? fallback
208+
: (rect?.height ?? fallback);
209+
});
210+
const firstShelf = items.findIndex(
211+
(item) =>
212+
item.kind === "marker" &&
213+
(item.marker === "snoozed-header" || item.marker === "settled-header"),
214+
);
215+
const shelfRect = rects[firstShelf];
216+
const beforeShelf = rects[firstShelf - 1];
217+
const lastRect = rects.at(-1);
218+
// Consume the shelf's auto margin as drag labels and resized rows need
219+
// room, keeping the combined shelves at their measured bottom.
220+
let shelfSpace =
221+
shelfRect && beforeShelf && lastRect && shelfRect.top > beforeShelf.bottom + 1
222+
? Math.max(
223+
0,
224+
lastRect.bottom - rects[0].top - heights.reduce((sum, height) => sum + height + 1, -1),
225+
)
226+
: 0;
227+
const result = items.map(() => hidden);
228+
let top = rects[0].top;
229+
for (const [projectedIndex, item] of projected.entries()) {
230+
if (
231+
item.kind === "marker" &&
232+
(item.marker === "snoozed-header" || item.marker === "settled-header")
233+
) {
234+
top += shelfSpace;
235+
shelfSpace = 0;
236+
}
237+
const index = indices.get(sidebarListItemId(item));
238+
const rect = index === undefined ? undefined : rects[index];
239+
if (index !== undefined && rect) result[index] = { ...stationary, y: top - rect.top };
240+
top += heights[projectedIndex]! + 1;
214241
}
215242
result[activeIndex] = stationary;
216243
return result;

‎apps/web/src/components/Sidebar.tsx‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -633,6 +633,7 @@ function SidebarDragBoundary(props: {
633633
function SidebarSectionHeader(props: {
634634
marker: "snoozed-header" | "settled-header";
635635
label: string;
636+
className?: string;
636637
// While dragging, the settled header reads at full strength and takes the
637638
// accent while the lifted row is over it.
638639
dragging?: boolean;
@@ -671,7 +672,7 @@ function SidebarSectionHeader(props: {
671672
<SortableSidebarMarker
672673
marker={props.marker}
673674
data-testid={`sidebar-${props.marker}`}
674-
className="mx-0.5 h-8"
675+
className={cn("mx-0.5 h-8", props.className)}
675676
>
676677
<button
677678
type="button"
@@ -4321,7 +4322,7 @@ export default function Sidebar() {
43214322
<>
43224323
<SidebarChromeHeader isElectron={isElectron} />
43234324
<SidebarContent
4324-
className="gap-0"
4325+
className="min-h-full gap-0"
43254326
fixedHeader={
43264327
// Lifted above the stage backdrop, whose fade bleeds below the
43274328
// header and would otherwise paint across the search row's outline.
@@ -4484,7 +4485,7 @@ export default function Sidebar() {
44844485
</SidebarGroup>
44854486
}
44864487
>
4487-
<SidebarGroup className="ps-[calc(var(--sidebar-content-inset)+1px)] pe-[var(--sidebar-content-inset)] pb-1 pt-0">
4488+
<SidebarGroup className="flex-1 ps-[calc(var(--sidebar-content-inset)+1px)] pe-[var(--sidebar-content-inset)] pb-1 pt-0">
44884489
{isSearchingThreads ? (
44894490
threadSearchResults.length > 0 ? (
44904491
<TooltipProvider
@@ -4567,7 +4568,7 @@ export default function Sidebar() {
45674568
<ul
45684569
ref={attachListMotionRef}
45694570
role="list"
4570-
className="relative flex flex-col gap-px"
4571+
className="relative flex flex-1 flex-col gap-px"
45714572
>
45724573
{(() => {
45734574
const renderThreadRowInner = (
@@ -4759,6 +4760,7 @@ export default function Sidebar() {
47594760
<SidebarSectionHeader
47604761
key="snoozed-shelf-header"
47614762
marker="snoozed-header"
4763+
className="mt-auto"
47624764
label={
47634765
snoozedShelfExpanded
47644766
? "Snoozed"
@@ -4776,6 +4778,7 @@ export default function Sidebar() {
47764778
<SidebarSectionHeader
47774779
key="settled-shelf-header"
47784780
marker="settled-header"
4781+
className={cn(snoozedThreads.length === 0 && "mt-auto")}
47794782
label={
47804783
settledShelfExpanded
47814784
? "Settled"

0 commit comments

Comments
 (0)