TypeScript
fix(web): keep sparse sidebar shelves at the bottom (#11595)
maria0118b5229526
diff --git a/apps/web/src/components/Sidebar.drag.test.ts b/apps/web/src/components/Sidebar.drag.test.tsindex 1058dfcd885..c757eca87aa 100644--- a/apps/web/src/components/Sidebar.drag.test.ts+++ b/apps/web/src/components/Sidebar.drag.test.ts@@ -253,6 +253,37 @@ describe("sidebar collision detection", () => {});describe("sidebar drag projection", () => {+ it.each([+ ["a1", "a2"],+ ["a1", sidebarMarkerId("settled-header")],+ ["z", "a2"],+ ])("keeps sparse shelves at the bottom when dragging %s over %s", (active, over) => {+ const items = [+ pinnedHeader,+ divider,+ thread("a1", "active"),+ thread("a2", "active"),+ marker("snoozed-header"),+ thread("z", "snoozed"),+ settledHeader,+ thread("s", "settled"),+ ];+ const strategy = createSidebarSortingStrategy({+ items,+ settledOrder: over === sidebarMarkerId("settled-header") ? ["a1", "s"] : ["s"],+ settledExpanded: true,+ boundaryLabelHeight: 24,+ snoozedThreadCount: 1,+ });+ const args = layout(items, active, over);+ for (const rect of args.rects.slice(4)) {+ rect.top += 400;+ rect.bottom += 400;+ }+ const lastIndex = items.length - 1;+ expect(strategy({ ...args, index: lastIndex })).toEqual(stationary);+ });+const pinned = [pinnedHeader,thread("p1", "pinned"),diff --git a/apps/web/src/components/Sidebar.drag.ts b/apps/web/src/components/Sidebar.drag.tsindex c64de1c27b7..0b5710c671f 100644--- a/apps/web/src/components/Sidebar.drag.ts+++ b/apps/web/src/components/Sidebar.drag.ts@@ -194,27 +194,58 @@ export function createSidebarSortingStrategy(input: {}marker("settled-header");section("settled");- const result = items.map(() => hidden);- let top = rects[0].top;- for (const item of projected) {+ const heights = projected.map((item) => {const index = indices.get(sidebarListItemId(item));const rect = index === undefined ? undefined : rects[index];- if (index !== undefined && rect) result[index] = { ...stationary, y: top - rect.top };const fallback =item.kind === "thread" && (item.section === "pinned" || item.section === "active")? cardHeight: slimHeight;const moved = item.kind === "thread" && item.key === active.key;- const height =- item.kind === "marker" &&+ return item.kind === "marker" &&(item.marker === "pinned-header" || item.marker === "pinned-divider")- ? labelHeight- : item.kind === "marker" && item.marker.endsWith("placeholder")- ? slimHeight- : moved- ? fallback- : (rect?.height ?? fallback);- top += height + 1;+ ? labelHeight+ : item.kind === "marker" && item.marker.endsWith("placeholder")+ ? slimHeight+ : moved+ ? fallback+ : (rect?.height ?? fallback);+ });+ const firstShelf = items.findIndex(+ (item) =>+ item.kind === "marker" &&+ (item.marker === "snoozed-header" || item.marker === "settled-header"),+ );+ const shelfRect = rects[firstShelf];+ const beforeShelf = rects[firstShelf - 1];+ const lastRect = rects.at(-1);+ // Consume the shelf's auto margin as drag labels and resized rows need+ // room, keeping the combined shelves at their measured bottom.+ let shelfSpace =+ !input.compact &&+ shelfRect &&+ beforeShelf &&+ lastRect &&+ shelfRect.top > beforeShelf.bottom + 1+ ? Math.max(+ 0,+ lastRect.bottom - rects[0].top - heights.reduce((sum, height) => sum + height + 1, -1),+ )+ : 0;+ const result = items.map(() => hidden);+ let top = rects[0].top;+ for (const [projectedIndex, item] of projected.entries()) {+ if (+ item.kind === "marker" &&+ (item.marker === "snoozed-header" || item.marker === "settled-header")+ ) {+ top += shelfSpace;+ shelfSpace = 0;+ }+ const index = indices.get(sidebarListItemId(item));+ const rect = index === undefined ? undefined : rects[index];+ if (index !== undefined && rect) result[index] = { ...stationary, y: top - rect.top };+ top += heights[projectedIndex]! + 1;}result[activeIndex] = stationary;return result;diff --git a/apps/web/src/components/Sidebar.tsx b/apps/web/src/components/Sidebar.tsxindex 1b850f1875b..a86bb9a3868 100644--- a/apps/web/src/components/Sidebar.tsx+++ b/apps/web/src/components/Sidebar.tsx@@ -661,6 +661,7 @@ function SidebarDragBoundary(props: {function SidebarSectionHeader(props: {marker: "snoozed-header" | "settled-header";label: string;+ className?: string;// While dragging, the settled header reads at full strength and takes the// accent while the lifted row is over it.dragging?: boolean;@@ -712,7 +713,7 @@ function SidebarSectionHeader(props: {<SortableSidebarMarkermarker={props.marker}data-testid={`sidebar-${props.marker}`}- className="mx-0.5 h-8"+ className={cn("mx-0.5 h-8", props.className)}><Tooltip disabled={!compact}><TooltipTrigger@@ -4541,7 +4542,10 @@ export default function Sidebar() {<><SidebarChromeHeader isElectron={isElectron} /><SidebarContent- className={cn("gap-0", compact && "group-data-[collapsible=icon]:overflow-visible")}+ className={cn(+ "gap-0",+ compact ? "group-data-[collapsible=icon]:overflow-visible" : "min-h-full",+ )}fixedFooter={compact && !isSearchingThreads && snoozedThreads.length > 0 ? (<ul@@ -4717,7 +4721,12 @@ export default function Sidebar() {</SidebarGroup>}>- <SidebarGroup className="ps-[calc(var(--sidebar-content-inset)+1px)] pe-[var(--sidebar-content-inset)] pb-1 pt-0">+ <SidebarGroup+ className={cn(+ "ps-[calc(var(--sidebar-content-inset)+1px)] pe-[var(--sidebar-content-inset)] pb-1 pt-0",+ !compact && "flex-1",+ )}+ >{isSearchingThreads ? (threadSearchResults.length > 0 ? (<TooltipProvider@@ -4806,7 +4815,10 @@ export default function Sidebar() {<ulref={attachListMotionRef}role="list"- className="relative flex flex-col gap-px"+ className={cn(+ "relative flex flex-col gap-px",+ !compact && sidebarListItems.length > 0 && "flex-1",+ )}>{(() => {const renderThreadRowInner = (@@ -5021,6 +5033,7 @@ export default function Sidebar() {<SidebarSectionHeaderkey="snoozed-shelf-header"marker="snoozed-header"+ className={cn(!compact && "mt-auto")}label={snoozedShelfExpanded? "Snoozed"@@ -5038,6 +5051,7 @@ export default function Sidebar() {<SidebarSectionHeaderkey="settled-shelf-header"marker="settled-header"+ className={cn(!compact && snoozedThreads.length === 0 && "mt-auto")}label={settledShelfExpanded? "Settled"