feat: Implement sub-room functionality
- Added support for sub-rooms in the SpaceHierarchy component, allowing rooms to have nested child rooms. - Introduced UnjoinedSubRoomItem component to display unjoined sub-rooms with a join button. - Created SubRooms settings page for managing sub-rooms, including adding and removing sub-rooms. - Updated RoomNavItem to include options for creating sub-rooms. - Enhanced room fetching logic to filter out sub-rooms from the main room list. - Added hooks for managing sub-rooms state and permissions. - Updated relevant state management to handle sub-room creation and association with parent rooms.
This commit is contained in:
29
src/app/hooks/useRoomSubRooms.ts
Normal file
29
src/app/hooks/useRoomSubRooms.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
import { Room } from 'matrix-js-sdk';
|
||||
import { useMemo } from 'react';
|
||||
import { useStateEvent } from './useStateEvent';
|
||||
import { StateEvent } from '../../types/matrix/room';
|
||||
|
||||
/**
|
||||
* Content structure for Paarrot sub-rooms
|
||||
*/
|
||||
export interface PaarrotSubRoomsContent {
|
||||
children: string[];
|
||||
}
|
||||
|
||||
/**
|
||||
* Hook to get the sub-rooms (child rooms) for a given room.
|
||||
* Sub-rooms are stored in the room's state as im.paarrot.sub_rooms
|
||||
*
|
||||
* @param room - The parent room
|
||||
* @returns Array of child room IDs
|
||||
*/
|
||||
export const useRoomSubRooms = (room: Room): string[] => {
|
||||
const subRoomsEvent = useStateEvent(room, StateEvent.PaarrotSubRooms);
|
||||
|
||||
const subRooms = useMemo(() => {
|
||||
const content = subRoomsEvent?.getContent<PaarrotSubRoomsContent>();
|
||||
return content?.children ?? [];
|
||||
}, [subRoomsEvent]);
|
||||
|
||||
return subRooms;
|
||||
};
|
||||
Reference in New Issue
Block a user