fix(sidebar): keep room list visible when category mutations fire from an enclave page #134
Loading…
Reference in a new issue
No description provided.
Delete branch "fix/sidebar-categories-respect-current-enclave"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Bug
After LC-79 merged, creating a category, toggling collapsed, assigning a room, or reordering anything from
/enclave/{id}or/room/{id}wiped the "All rooms" section (and any expanded category's room list) from the returned sidebar swap. Refreshing the page brought the rooms back.Root cause
render_sidebar_fragmentinroutes/sidebar_categories.rsalways calledsuper::load_sidebar(state, user, None).Nonemeans "Home view" toload_sidebar, which returns an emptysidebar_rooms(Home shows DMs only). Every category mutation therefore re-rendered the sidebar as if the user had clicked Home, hiding their current enclave's rooms.Fix
Read
HX-Current-URL(orRefereras fallback) and parse the path:/enclave/{id}-> use the id./room/{id}-> resolve the room's enclave via the existingenclave_for_roomhelper.None(Home shape preserved on purpose).Threaded through every handler in the module via an extra
headers: HeaderMapextractor.render_sidebar_fragmentnow takes the header map and callscurrent_enclave_from_headersto derive context.Test plan
create_category_preserves_room_list_when_viewing_enclaveposts to/sidebar/categorieswithHX-Current-URL: http://localhost:8080/enclave/1and asserts the rebuilt fragment still contains/room/1"(the seeded General room link).just check(fmt + clippy across standalone + saas)../dev/cargo test -p lets-chat-server --test routes_sidebar_categories- 11 tests pass (10 existing + 1 new).+ Addto create a category - verify the room list stays put.The five sidebar-category endpoints all rebuild the sidebar fragment via `render_sidebar_fragment(state, user, None)`, where `None` means "Home view" to `load_sidebar`. The Home view's sidebar shows only DMs - rooms are empty - so the swap response that came back from creating a category, toggling collapsed, assigning a room, or reordering wiped the "All rooms" section and any open category's room list whenever the user was actually on `/enclave/{id}` or `/room/{id}`. Reads HTMX's `HX-Current-URL` header (falling back to `Referer` for non-HTMX callers) and parses the path: `/enclave/{id}` -> the id; `/room/{id}` -> the room's enclave via the existing `enclave_for_room` helper; anything else -> `None` and the Home shape is preserved on purpose. Missing / malformed URLs drop to `None` silently rather than erroring. Threaded through every handler in the module via an additional `headers: HeaderMap` extractor; `render_sidebar_fragment` now takes the header map and calls `current_enclave_from_headers` to derive context. New regression test `create_category_preserves_room_list_when_viewing_enclave` posts to /sidebar/categories with `HX-Current-URL: .../enclave/1` and asserts the rebuilt fragment still contains the seeded General room link.