Skip to content

armgit / alook

Public Imported from GitHub
0

Multi-Agent Collaboration for Team and Friends

fix(community): persist channel reorder across refresh

Gus72f791bda474
diff --git a/src/web/src/components/community/channel-sidebar.tsx b/src/web/src/components/community/channel-sidebar.tsx
index ff43e6727..d8f2dc632 100644
--- a/src/web/src/components/community/channel-sidebar.tsx
+++ b/src/web/src/components/community/channel-sidebar.tsx
@@ -14,7 +14,7 @@ import { SortableChannel, PendingChannelRow } from "./sortable-channel"
import { CreateChannelDialog } from "./create-channel-dialog"
import { CreateCategoryDialog } from "./create-category-dialog"
import { CategorySettingsDialog } from "./category-settings-dialog"
-import { catId, catOf, isCat, type ChannelTree } from "./use-channel-tree"
+import { catId, catOf, isCat, reorderChannelsWithin, type ChannelTree } from "./use-channel-tree"
import { InviteDialog } from "./invite-dialog"
import { ChannelAddMembersDialog } from "./channel-add-members-dialog"
import type { Channel, SettingsSection } from "./_types"
@@ -113,7 +113,17 @@ export const ChannelSidebar = memo(function ChannelSidebar({
}
// Persist a same-privacy cross-category move: write the new categoryId
// (translating the synthetic uncategorized bucket to null), then reorder.
- const allChannelIds = catOrder.flatMap((cat) => (order[cat] ?? []).filter((c) => !c.pending).map((c) => c.id))
+ //
+ // `treeDragEnd(e)` above settles the drop via `setOrder(...)`, which only
+ // applies on the NEXT render — so the `order` closure here is still the
+ // PRE-drop order for a same-category reorder (`onDragOver` never touched
+ // it in that case). Reading it directly would PATCH the old sequence and
+ // the reorder wouldn't persist. Recompute the settled order synchronously
+ // from the same pure helper `treeDragEnd` uses. Cross-category is already
+ // settled by `onDragOver`, and re-settling within the destination is
+ // idempotent — so this is correct for both paths.
+ const settledOrder = reorderChannelsWithin(order, activeStr, overStr)
+ const allChannelIds = catOrder.flatMap((cat) => (settledOrder[cat] ?? []).filter((c) => !c.pending).map((c) => c.id))
if (destCat && originCat && destCat !== originCat) {
// The uncategorized bucket (empty name, synthetic id) maps back to a
// real `categoryId: null` for the PATCH.
diff --git a/src/web/src/components/community/use-channel-tree.test.ts b/src/web/src/components/community/use-channel-tree.test.ts
index 8b77db962..442b1c78b 100644
--- a/src/web/src/components/community/use-channel-tree.test.ts
+++ b/src/web/src/components/community/use-channel-tree.test.ts
@@ -63,6 +63,34 @@ describe("reorderChannelsWithin", () => {
})
})
+// Regression: channel-sidebar's drop handler builds the reorder-PATCH payload
+// from the SETTLED order (reorderChannelsWithin applied synchronously), not the
+// stale pre-drop `order` closure. Same-category reorders previously PATCHed the
+// old sequence → positions rewritten unchanged → reorder didn't persist across
+// refresh. This pins that the payload derivation reflects the moved order.
+describe("reorder-PATCH payload derivation (channel-sidebar drop handler)", () => {
+ const catOrder = ["cat_A", "cat_B"]
+ const payloadFrom = (o: ChannelOrder) =>
+ catOrder.flatMap((cat) => (o[cat] ?? []).map((c) => c.id))
+
+ it("same-category drop: payload reflects the moved order, not the pre-drop order", () => {
+ // Pre-drop order would yield b1,b2,b3 — the stale bug. Settled must move b1 past b3.
+ const settled = reorderChannelsWithin(order, "b1", "b3")
+ expect(payloadFrom(settled)).toEqual(["a1", "a2", "b2", "b3", "b1"])
+ expect(payloadFrom(settled)).not.toEqual(payloadFrom(order))
+ })
+
+ it("re-settling an already-cross-category-settled order is idempotent for the payload", () => {
+ // Cross-category is settled by onDragOver first; applying reorderChannelsWithin
+ // to place it at the drop target within the destination must not corrupt it.
+ const moved = moveChannelAcrossCategories(order, "a1", "b2") // a1 → cat_B before b2
+ const settled = reorderChannelsWithin(moved, "a1", "b2")
+ expect(payloadFrom(settled)).toContain("a1")
+ // a1 left cat_A; cat_A now only a2.
+ expect(settled.cat_A.map((c) => c.id)).toEqual(["a2"])
+ })
+})
+
describe("reorderCategories", () => {
it("reorders the category id list", () => {
expect(reorderCategories(["cat_A", "cat_B", "cat_C"], "cat_A", "cat_C")).toEqual(["cat_B", "cat_C", "cat_A"])