Room list: scroll to newly creation section (#33210)
* feat(rls): emit tag when section is created * feat(vm): scroll to newly section tag * feat(view): scroll to new section
This commit is contained in:
@@ -153,7 +153,7 @@ export class RoomListViewModel
|
||||
this.disposables.trackListener(
|
||||
RoomListStoreV3.instance,
|
||||
RoomListStoreV3Event.SectionCreated as any,
|
||||
this.onSectionCreated,
|
||||
this.onSectionCreated as (...args: unknown[]) => void,
|
||||
);
|
||||
|
||||
// Subscribe to active room changes to update selected room
|
||||
@@ -500,6 +500,7 @@ export class RoomListViewModel
|
||||
private async updateRoomListData(
|
||||
isRoomChange: boolean = false,
|
||||
roomIdOverride: string | null = null,
|
||||
scrollToSectionTag: string | undefined = undefined,
|
||||
): Promise<void> {
|
||||
// Determine the room ID to use for calculations
|
||||
// Use override if provided (e.g., during space changes), otherwise fall back to RoomViewStore
|
||||
@@ -544,17 +545,23 @@ export class RoomListViewModel
|
||||
// Update filter keys - only update if they have actually changed to prevent unnecessary re-renders of the room list
|
||||
const previousFilterKeys = this.snapshot.current.roomListState.filterKeys;
|
||||
const newFilterKeys = this.roomsResult.filterKeys?.map((k) => String(k));
|
||||
const viewSections = toRoomListSection(this.sections);
|
||||
|
||||
const resolvedScrollToSectionTag =
|
||||
scrollToSectionTag && viewSections.some((s) => s.id === scrollToSectionTag)
|
||||
? scrollToSectionTag
|
||||
: undefined;
|
||||
|
||||
const roomListState: RoomListViewState = {
|
||||
activeRoomIndex,
|
||||
spaceId: this.roomsResult.spaceId,
|
||||
filterKeys: keepIfSame(previousFilterKeys, newFilterKeys),
|
||||
scrollToSectionTag: resolvedScrollToSectionTag,
|
||||
};
|
||||
|
||||
const activeFilterId = this.activeFilter !== undefined ? filterKeyToIdMap.get(this.activeFilter) : undefined;
|
||||
const isRoomListEmpty = this.roomsResult.sections.every((section) => section.rooms.length === 0);
|
||||
const isLoadingRooms = RoomListStoreV3.instance.isLoadingRooms;
|
||||
|
||||
const viewSections = toRoomListSection(this.sections);
|
||||
const previousSections = this.snapshot.current.sections;
|
||||
|
||||
// Single atomic snapshot update
|
||||
@@ -586,7 +593,9 @@ export class RoomListViewModel
|
||||
}
|
||||
};
|
||||
|
||||
public onSectionCreated = (): void => {
|
||||
public onSectionCreated = (tag: string): void => {
|
||||
this.updateRoomListData(false, null, tag);
|
||||
|
||||
clearTimeout(this.toastRef);
|
||||
this.snapshot.merge({
|
||||
toast: "section_created",
|
||||
|
||||
Reference in New Issue
Block a user