mirror of
https://github.com/cinnyapp/cinny.git
synced 2025-02-23 21:53:05 +01:00
fix space room list
This commit is contained in:
parent
50696be46e
commit
bd68d0b0fa
8 changed files with 176 additions and 144 deletions
24
src/app/components/SpaceChildDirectsProvider.tsx
Normal file
24
src/app/components/SpaceChildDirectsProvider.tsx
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
import { ReactNode } from 'react';
|
||||||
|
import { RoomToParents } from '../../types/matrix/room';
|
||||||
|
import { useMatrixClient } from '../hooks/useMatrixClient';
|
||||||
|
import { allRoomsAtom } from '../state/room-list/roomList';
|
||||||
|
import { useSpaceChildDirects } from '../state/hooks/roomList';
|
||||||
|
|
||||||
|
type SpaceChildDirectsProviderProps = {
|
||||||
|
spaceId: string;
|
||||||
|
mDirects: Set<string>;
|
||||||
|
roomToParents: RoomToParents;
|
||||||
|
children: (rooms: string[]) => ReactNode;
|
||||||
|
};
|
||||||
|
export function SpaceChildDirectsProvider({
|
||||||
|
spaceId,
|
||||||
|
roomToParents,
|
||||||
|
mDirects,
|
||||||
|
children,
|
||||||
|
}: SpaceChildDirectsProviderProps) {
|
||||||
|
const mx = useMatrixClient();
|
||||||
|
|
||||||
|
const childDirects = useSpaceChildDirects(mx, spaceId, allRoomsAtom, mDirects, roomToParents);
|
||||||
|
|
||||||
|
return children(childDirects);
|
||||||
|
}
|
|
@ -6,17 +6,19 @@ import { useSpaceChildRooms } from '../state/hooks/roomList';
|
||||||
|
|
||||||
type SpaceChildRoomsProviderProps = {
|
type SpaceChildRoomsProviderProps = {
|
||||||
spaceId: string;
|
spaceId: string;
|
||||||
|
mDirects: Set<string>;
|
||||||
roomToParents: RoomToParents;
|
roomToParents: RoomToParents;
|
||||||
children: (rooms: string[]) => ReactNode;
|
children: (rooms: string[]) => ReactNode;
|
||||||
};
|
};
|
||||||
export function SpaceChildRoomsProvider({
|
export function SpaceChildRoomsProvider({
|
||||||
spaceId,
|
spaceId,
|
||||||
roomToParents,
|
roomToParents,
|
||||||
|
mDirects,
|
||||||
children,
|
children,
|
||||||
}: SpaceChildRoomsProviderProps) {
|
}: SpaceChildRoomsProviderProps) {
|
||||||
const mx = useMatrixClient();
|
const mx = useMatrixClient();
|
||||||
|
|
||||||
const childRooms = useSpaceChildRooms(mx, spaceId, allRoomsAtom, roomToParents);
|
const childRooms = useSpaceChildRooms(mx, spaceId, allRoomsAtom, mDirects, roomToParents);
|
||||||
|
|
||||||
return children(childRooms);
|
return children(childRooms);
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,7 +42,7 @@ import { ClientLayout, ClientRoot } from './client';
|
||||||
import { Home, HomeSearch } from './client/home';
|
import { Home, HomeSearch } from './client/home';
|
||||||
import { RoomViewer } from '../organisms/room/Room';
|
import { RoomViewer } from '../organisms/room/Room';
|
||||||
import { Direct } from './client/direct';
|
import { Direct } from './client/direct';
|
||||||
import { SpaceViewer } from './client/space';
|
import { RouteSpaceProvider, Space, SpaceSearch } from './client/space';
|
||||||
import { Explore, ExploreRedirect, FeaturedRooms, PublicRooms } from './client/explore';
|
import { Explore, ExploreRedirect, FeaturedRooms, PublicRooms } from './client/explore';
|
||||||
import { Notifications, Inbox, InboxRedirect, Invites } from './client/inbox';
|
import { Notifications, Inbox, InboxRedirect, Invites } from './client/inbox';
|
||||||
import { setAfterLoginRedirectPath } from './afterLoginRedirectPath';
|
import { setAfterLoginRedirectPath } from './afterLoginRedirectPath';
|
||||||
|
@ -94,11 +94,13 @@ const createRouter = (clientConfig: ClientConfig) => {
|
||||||
<Route path={_CREATE_PATH} element={<p>create</p>} />
|
<Route path={_CREATE_PATH} element={<p>create</p>} />
|
||||||
<Route path={_ROOM_PATH} element={<RoomViewer />} />
|
<Route path={_ROOM_PATH} element={<RoomViewer />} />
|
||||||
</Route>
|
</Route>
|
||||||
<Route path={SPACE_PATH} element={<SpaceViewer />}>
|
<Route path={SPACE_PATH} element={<RouteSpaceProvider />}>
|
||||||
<Route index element={<p>welcome</p>} />
|
<Route element={<Space />}>
|
||||||
<Route path={_LOBBY_PATH} element={<p>lobby</p>} />
|
<Route index element={<p>welcome</p>} />
|
||||||
<Route path={_SEARCH_PATH} element={<p>search</p>} />
|
<Route path={_LOBBY_PATH} element={<p>lobby</p>} />
|
||||||
<Route path={_ROOM_PATH} element={<RoomViewer />} />
|
<Route path={_SEARCH_PATH} element={<SpaceSearch />} />
|
||||||
|
<Route path={_ROOM_PATH} element={<RoomViewer />} />
|
||||||
|
</Route>
|
||||||
</Route>
|
</Route>
|
||||||
<Route path={EXPLORE_PATH} element={<Explore />}>
|
<Route path={EXPLORE_PATH} element={<Explore />}>
|
||||||
<Route index element={<ExploreRedirect />} />
|
<Route index element={<ExploreRedirect />} />
|
||||||
|
|
36
src/app/pages/client/space/Search.tsx
Normal file
36
src/app/pages/client/space/Search.tsx
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
import React, { useRef } from 'react';
|
||||||
|
import { Box, Icon, Icons, Text, Scroll } from 'folds';
|
||||||
|
import { Page, PageContent, PageContentCenter, PageHeader } from '../../../components/page';
|
||||||
|
import { MessageSearch } from '../../../features/message-search';
|
||||||
|
|
||||||
|
export function SpaceSearch() {
|
||||||
|
const scrollRef = useRef<HTMLDivElement>(null);
|
||||||
|
const rooms = [''];
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Page>
|
||||||
|
<PageHeader>
|
||||||
|
<Box grow="Yes" justifyContent="Center" alignItems="Center" gap="200">
|
||||||
|
<Icon size="400" src={Icons.Search} />
|
||||||
|
<Text size="H3" truncate>
|
||||||
|
Message Search
|
||||||
|
</Text>
|
||||||
|
</Box>
|
||||||
|
</PageHeader>
|
||||||
|
<Box style={{ position: 'relative' }} grow="Yes">
|
||||||
|
<Scroll ref={scrollRef} hideTrack visibility="Hover">
|
||||||
|
<PageContent>
|
||||||
|
<PageContentCenter>
|
||||||
|
<MessageSearch
|
||||||
|
defaultRoomsFilterName="Space"
|
||||||
|
allowGlobal
|
||||||
|
rooms={rooms}
|
||||||
|
scrollRef={scrollRef}
|
||||||
|
/>
|
||||||
|
</PageContentCenter>
|
||||||
|
</PageContent>
|
||||||
|
</Scroll>
|
||||||
|
</Box>
|
||||||
|
</Page>
|
||||||
|
);
|
||||||
|
}
|
|
@ -1,20 +1,16 @@
|
||||||
import React, { useRef } from 'react';
|
import React, { useRef } from 'react';
|
||||||
import { Outlet, useParams } from 'react-router-dom';
|
import { Outlet } from 'react-router-dom';
|
||||||
import { useAtomValue } from 'jotai';
|
import { useAtomValue } from 'jotai';
|
||||||
import { Avatar, Box, Icon, Icons, Text } from 'folds';
|
import { Avatar, Box, Icon, Icons, Text } from 'folds';
|
||||||
import { Room } from 'matrix-js-sdk';
|
|
||||||
import { ClientContentLayout } from '../ClientContentLayout';
|
import { ClientContentLayout } from '../ClientContentLayout';
|
||||||
import { ClientDrawerLayout } from '../ClientDrawerLayout';
|
import { ClientDrawerLayout } from '../ClientDrawerLayout';
|
||||||
import { ClientDrawerHeaderLayout } from '../ClientDrawerHeaderLayout';
|
import { ClientDrawerHeaderLayout } from '../ClientDrawerHeaderLayout';
|
||||||
import {
|
import { useSpaceChildSpacesRecursive } from '../../../state/hooks/roomList';
|
||||||
useSpaceRecursiveChildDirects,
|
|
||||||
useSpaceRecursiveChildSpaces,
|
|
||||||
} from '../../../state/hooks/roomList';
|
|
||||||
import { useMatrixClient } from '../../../hooks/useMatrixClient';
|
import { useMatrixClient } from '../../../hooks/useMatrixClient';
|
||||||
import { allRoomsAtom } from '../../../state/room-list/roomList';
|
import { allRoomsAtom } from '../../../state/room-list/roomList';
|
||||||
import { mDirectAtom } from '../../../state/mDirectList';
|
import { mDirectAtom } from '../../../state/mDirectList';
|
||||||
import { roomToParentsAtom } from '../../../state/room/roomToParents';
|
import { roomToParentsAtom } from '../../../state/room/roomToParents';
|
||||||
import { factoryRoomIdByAtoZ } from '../../../utils/sort';
|
import { factoryRoomIdByActivity, factoryRoomIdByAtoZ } from '../../../utils/sort';
|
||||||
import { ClientDrawerContentLayout } from '../ClientDrawerContentLayout';
|
import { ClientDrawerContentLayout } from '../ClientDrawerContentLayout';
|
||||||
import {
|
import {
|
||||||
NavCategory,
|
NavCategory,
|
||||||
|
@ -24,43 +20,38 @@ import {
|
||||||
NavLink,
|
NavLink,
|
||||||
} from '../../../components/nav';
|
} from '../../../components/nav';
|
||||||
import { UnreadBadge, UnreadBadgeCenter } from '../../../components/unread-badge';
|
import { UnreadBadge, UnreadBadgeCenter } from '../../../components/unread-badge';
|
||||||
import { RoomIcon } from '../../../components/room-avatar';
|
import { RoomAvatar, RoomIcon } from '../../../components/room-avatar';
|
||||||
import { getSpaceLobbyPath, getSpaceRoomPath, getSpaceSearchPath } from '../../pathUtils';
|
import { getSpaceLobbyPath, getSpaceRoomPath, getSpaceSearchPath } from '../../pathUtils';
|
||||||
import { getCanonicalAliasOrRoomId } from '../../../utils/matrix';
|
import { getCanonicalAliasOrRoomId } from '../../../utils/matrix';
|
||||||
import { RoomUnreadProvider } from '../../../components/RoomUnreadProvider';
|
import { RoomUnreadProvider } from '../../../components/RoomUnreadProvider';
|
||||||
import { useSelectedRoom } from '../../../hooks/router/useSelectedRoom';
|
import { useSelectedRoom } from '../../../hooks/router/useSelectedRoom';
|
||||||
import {
|
import {
|
||||||
useSelectedSpace,
|
|
||||||
useSpaceLobbySelected,
|
useSpaceLobbySelected,
|
||||||
useSpaceSearchSelected,
|
useSpaceSearchSelected,
|
||||||
} from '../../../hooks/router/useSelectedSpace';
|
} from '../../../hooks/router/useSelectedSpace';
|
||||||
import { SpaceChildRoomsProvider } from '../../../components/SpaceChildRoomsProvider';
|
import { SpaceChildRoomsProvider } from '../../../components/SpaceChildRoomsProvider';
|
||||||
|
import { getRoomAvatarUrl } from '../../../utils/room';
|
||||||
|
import { nameInitials } from '../../../utils/common';
|
||||||
|
import { SpaceChildDirectsProvider } from '../../../components/SpaceChildDirectsProvider';
|
||||||
|
import { useSpace } from '../../../hooks/useSpace';
|
||||||
|
|
||||||
export function Space({ spaceIdOrAlias, space }: { spaceIdOrAlias: string; space: Room }) {
|
export function Space() {
|
||||||
const mx = useMatrixClient();
|
const mx = useMatrixClient();
|
||||||
|
const space = useSpace();
|
||||||
|
const spaceIdOrAlias = getCanonicalAliasOrRoomId(mx, space.roomId);
|
||||||
const scrollRef = useRef<HTMLDivElement>(null);
|
const scrollRef = useRef<HTMLDivElement>(null);
|
||||||
|
|
||||||
const mDirects = useAtomValue(mDirectAtom);
|
const mDirects = useAtomValue(mDirectAtom);
|
||||||
const roomToParents = useAtomValue(roomToParentsAtom);
|
const roomToParents = useAtomValue(roomToParentsAtom);
|
||||||
|
|
||||||
const childSpaces = useSpaceRecursiveChildSpaces(mx, space.roomId, allRoomsAtom, roomToParents);
|
const childSpaces = useSpaceChildSpacesRecursive(mx, space.roomId, allRoomsAtom, roomToParents);
|
||||||
const childDirects = useSpaceRecursiveChildDirects(
|
|
||||||
mx,
|
|
||||||
space.roomId,
|
|
||||||
allRoomsAtom,
|
|
||||||
mDirects,
|
|
||||||
roomToParents
|
|
||||||
);
|
|
||||||
|
|
||||||
const selectedRoomId = useSelectedRoom();
|
const selectedRoomId = useSelectedRoom();
|
||||||
const lobbySelected = useSpaceLobbySelected(spaceIdOrAlias);
|
const lobbySelected = useSpaceLobbySelected(spaceIdOrAlias);
|
||||||
const searchSelected = useSpaceSearchSelected(spaceIdOrAlias);
|
const searchSelected = useSpaceSearchSelected(spaceIdOrAlias);
|
||||||
|
|
||||||
const getToLink = (roomId: string) =>
|
const getToLink = (roomId: string) =>
|
||||||
getSpaceRoomPath(
|
getSpaceRoomPath(spaceIdOrAlias, getCanonicalAliasOrRoomId(mx, roomId));
|
||||||
getCanonicalAliasOrRoomId(mx, space.roomId),
|
|
||||||
getCanonicalAliasOrRoomId(mx, roomId)
|
|
||||||
);
|
|
||||||
|
|
||||||
const renderRoomSelector = (roomId: string) => {
|
const renderRoomSelector = (roomId: string) => {
|
||||||
const room = mx.getRoom(roomId);
|
const room = mx.getRoom(roomId);
|
||||||
|
@ -81,7 +72,16 @@ export function Space({ spaceIdOrAlias, space }: { spaceIdOrAlias: string; space
|
||||||
<NavItemContent size="T300">
|
<NavItemContent size="T300">
|
||||||
<Box as="span" grow="Yes" alignItems="Center" gap="200">
|
<Box as="span" grow="Yes" alignItems="Center" gap="200">
|
||||||
<Avatar size="200" radii="400">
|
<Avatar size="200" radii="400">
|
||||||
<RoomIcon filled={selected} size="100" joinRule={room.getJoinRule()} />
|
{mDirects.has(roomId) ? (
|
||||||
|
<RoomAvatar
|
||||||
|
variant="Background"
|
||||||
|
src={getRoomAvatarUrl(mx, room, 96)}
|
||||||
|
alt={room.name}
|
||||||
|
renderInitials={() => <Text size="H6">{nameInitials(room.name)}</Text>}
|
||||||
|
/>
|
||||||
|
) : (
|
||||||
|
<RoomIcon filled={selected} size="100" joinRule={room.getJoinRule()} />
|
||||||
|
)}
|
||||||
</Avatar>
|
</Avatar>
|
||||||
<Box as="span" grow="Yes">
|
<Box as="span" grow="Yes">
|
||||||
<Text as="span" size="Inherit" truncate>
|
<Text as="span" size="Inherit" truncate>
|
||||||
|
@ -151,7 +151,11 @@ export function Space({ spaceIdOrAlias, space }: { spaceIdOrAlias: string; space
|
||||||
</NavLink>
|
</NavLink>
|
||||||
</NavItem>
|
</NavItem>
|
||||||
</NavCategory>
|
</NavCategory>
|
||||||
<SpaceChildRoomsProvider spaceId={space.roomId} roomToParents={roomToParents}>
|
<SpaceChildRoomsProvider
|
||||||
|
spaceId={space.roomId}
|
||||||
|
mDirects={mDirects}
|
||||||
|
roomToParents={roomToParents}
|
||||||
|
>
|
||||||
{(childRooms) =>
|
{(childRooms) =>
|
||||||
childRooms.length > 0 && (
|
childRooms.length > 0 && (
|
||||||
<NavCategory>
|
<NavCategory>
|
||||||
|
@ -167,30 +171,52 @@ export function Space({ spaceIdOrAlias, space }: { spaceIdOrAlias: string; space
|
||||||
<SpaceChildRoomsProvider
|
<SpaceChildRoomsProvider
|
||||||
key={childSpaceId}
|
key={childSpaceId}
|
||||||
spaceId={childSpaceId}
|
spaceId={childSpaceId}
|
||||||
|
mDirects={mDirects}
|
||||||
roomToParents={roomToParents}
|
roomToParents={roomToParents}
|
||||||
>
|
>
|
||||||
{(childRooms) =>
|
{(childRooms) => (
|
||||||
childRooms.length > 0 && (
|
<SpaceChildDirectsProvider
|
||||||
<NavCategory>
|
spaceId={childSpaceId}
|
||||||
<NavCategoryHeader>
|
mDirects={mDirects}
|
||||||
<Text size="O400">{mx.getRoom(childSpaceId)?.name}</Text>
|
roomToParents={roomToParents}
|
||||||
</NavCategoryHeader>
|
>
|
||||||
{Array.from(childRooms)
|
{(childDirects) =>
|
||||||
.sort(factoryRoomIdByAtoZ(mx))
|
(childRooms.length > 0 || childDirects.length > 0) && (
|
||||||
.map(renderRoomSelector)}
|
<NavCategory>
|
||||||
</NavCategory>
|
<NavCategoryHeader>
|
||||||
)
|
<Text size="O400">{mx.getRoom(childSpaceId)?.name}</Text>
|
||||||
}
|
</NavCategoryHeader>
|
||||||
|
{Array.from(childRooms)
|
||||||
|
.sort(factoryRoomIdByAtoZ(mx))
|
||||||
|
.map(renderRoomSelector)}
|
||||||
|
{Array.from(childDirects)
|
||||||
|
.sort(factoryRoomIdByActivity(mx))
|
||||||
|
.map(renderRoomSelector)}
|
||||||
|
</NavCategory>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
</SpaceChildDirectsProvider>
|
||||||
|
)}
|
||||||
</SpaceChildRoomsProvider>
|
</SpaceChildRoomsProvider>
|
||||||
))}
|
))}
|
||||||
{childDirects.length > 0 && (
|
<SpaceChildDirectsProvider
|
||||||
<NavCategory>
|
spaceId={space.roomId}
|
||||||
<NavCategoryHeader>
|
mDirects={mDirects}
|
||||||
<Text size="O400">People</Text>
|
roomToParents={roomToParents}
|
||||||
</NavCategoryHeader>
|
>
|
||||||
{Array.from(childDirects).sort(factoryRoomIdByAtoZ(mx)).map(renderRoomSelector)}
|
{(childDirects) =>
|
||||||
</NavCategory>
|
childDirects.length > 0 && (
|
||||||
)}
|
<NavCategory>
|
||||||
|
<NavCategoryHeader>
|
||||||
|
<Text size="O400">People</Text>
|
||||||
|
</NavCategoryHeader>
|
||||||
|
{Array.from(childDirects)
|
||||||
|
.sort(factoryRoomIdByActivity(mx))
|
||||||
|
.map(renderRoomSelector)}
|
||||||
|
</NavCategory>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
</SpaceChildDirectsProvider>
|
||||||
</Box>
|
</Box>
|
||||||
</ClientDrawerContentLayout>
|
</ClientDrawerContentLayout>
|
||||||
</ClientDrawerLayout>
|
</ClientDrawerLayout>
|
||||||
|
@ -200,17 +226,3 @@ export function Space({ spaceIdOrAlias, space }: { spaceIdOrAlias: string; space
|
||||||
</ClientContentLayout>
|
</ClientContentLayout>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function SpaceViewer() {
|
|
||||||
const mx = useMatrixClient();
|
|
||||||
|
|
||||||
const { spaceIdOrAlias } = useParams();
|
|
||||||
const selectedSpaceId = useSelectedSpace();
|
|
||||||
const space = mx.getRoom(selectedSpaceId);
|
|
||||||
|
|
||||||
if (!space || !spaceIdOrAlias) {
|
|
||||||
return <p>TODO: join space screen</p>;
|
|
||||||
}
|
|
||||||
|
|
||||||
return <Space spaceIdOrAlias={spaceIdOrAlias} space={space} />;
|
|
||||||
}
|
|
||||||
|
|
25
src/app/pages/client/space/SpaceProvider.tsx
Normal file
25
src/app/pages/client/space/SpaceProvider.tsx
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
import React from 'react';
|
||||||
|
import { Outlet } from 'react-router-dom';
|
||||||
|
import { useMatrixClient } from '../../../hooks/useMatrixClient';
|
||||||
|
import { useSpaces } from '../../../state/hooks/roomList';
|
||||||
|
import { allRoomsAtom } from '../../../state/room-list/roomList';
|
||||||
|
import { useSelectedSpace } from '../../../hooks/router/useSelectedSpace';
|
||||||
|
import { SpaceProvider } from '../../../hooks/useSpace';
|
||||||
|
|
||||||
|
export function RouteSpaceProvider() {
|
||||||
|
const mx = useMatrixClient();
|
||||||
|
const joinedSpaces = useSpaces(mx, allRoomsAtom);
|
||||||
|
|
||||||
|
const selectedSpaceId = useSelectedSpace();
|
||||||
|
const space = mx.getRoom(selectedSpaceId);
|
||||||
|
|
||||||
|
if (!space || !joinedSpaces.includes(space.roomId)) {
|
||||||
|
return <p>TODO: join space screen</p>;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<SpaceProvider value={space}>
|
||||||
|
<Outlet />
|
||||||
|
</SpaceProvider>
|
||||||
|
);
|
||||||
|
}
|
|
@ -1 +1,3 @@
|
||||||
|
export * from './SpaceProvider';
|
||||||
export * from './Space';
|
export * from './Space';
|
||||||
|
export * from './Search';
|
||||||
|
|
|
@ -7,12 +7,6 @@ import { compareRoomsEqual } from '../room-list/utils';
|
||||||
import { allRoomsAtom } from '../room-list/roomList';
|
import { allRoomsAtom } from '../room-list/roomList';
|
||||||
import { RoomToParents } from '../../../types/matrix/room';
|
import { RoomToParents } from '../../../types/matrix/room';
|
||||||
|
|
||||||
/**
|
|
||||||
* select list of space room id's from all rooms
|
|
||||||
* @param mx to check room type
|
|
||||||
* @param roomsAtom to pick rooms
|
|
||||||
* @returns list of space id's
|
|
||||||
*/
|
|
||||||
export const useSpaces = (mx: MatrixClient, roomsAtom: typeof allRoomsAtom) => {
|
export const useSpaces = (mx: MatrixClient, roomsAtom: typeof allRoomsAtom) => {
|
||||||
const selector = useCallback(
|
const selector = useCallback(
|
||||||
(rooms: string[]) => rooms.filter((roomId) => isSpace(mx.getRoom(roomId))),
|
(rooms: string[]) => rooms.filter((roomId) => isSpace(mx.getRoom(roomId))),
|
||||||
|
@ -21,13 +15,6 @@ export const useSpaces = (mx: MatrixClient, roomsAtom: typeof allRoomsAtom) => {
|
||||||
return useAtomValue(selectAtom(roomsAtom, selector, compareRoomsEqual));
|
return useAtomValue(selectAtom(roomsAtom, selector, compareRoomsEqual));
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* select list of space room ids from all rooms which doesn't have any parent
|
|
||||||
* @param mx to check room type
|
|
||||||
* @param roomsAtom to pick rooms
|
|
||||||
* @param roomToParents: to exclude space's with parent
|
|
||||||
* @returns list of space ids
|
|
||||||
*/
|
|
||||||
export const useOrphanSpaces = (
|
export const useOrphanSpaces = (
|
||||||
mx: MatrixClient,
|
mx: MatrixClient,
|
||||||
roomsAtom: typeof allRoomsAtom,
|
roomsAtom: typeof allRoomsAtom,
|
||||||
|
@ -41,15 +28,7 @@ export const useOrphanSpaces = (
|
||||||
return useAtomValue(selectAtom(roomsAtom, selector, compareRoomsEqual));
|
return useAtomValue(selectAtom(roomsAtom, selector, compareRoomsEqual));
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
export const useSpaceChildSpacesRecursive = (
|
||||||
* select list of all room ids from all rooms for which spaceId is in all parents
|
|
||||||
* @param mx to check room type
|
|
||||||
* @param spaceId as root parent
|
|
||||||
* @param roomsAtom to pick rooms
|
|
||||||
* @param roomToParents: to include child room
|
|
||||||
* @returns list of space ids
|
|
||||||
*/
|
|
||||||
export const useSpaceRecursiveChildSpaces = (
|
|
||||||
mx: MatrixClient,
|
mx: MatrixClient,
|
||||||
spaceId: string,
|
spaceId: string,
|
||||||
roomsAtom: typeof allRoomsAtom,
|
roomsAtom: typeof allRoomsAtom,
|
||||||
|
@ -68,40 +47,27 @@ export const useSpaceRecursiveChildSpaces = (
|
||||||
return useAtomValue(selectAtom(roomsAtom, selector, compareRoomsEqual));
|
return useAtomValue(selectAtom(roomsAtom, selector, compareRoomsEqual));
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* select list of all room ids from all rooms for which spaceId is in parents
|
|
||||||
* @param mx to check room type
|
|
||||||
* @param spaceId as root parent
|
|
||||||
* @param roomsAtom to pick rooms
|
|
||||||
* @param roomToParents: to include child room
|
|
||||||
* @returns list of space ids
|
|
||||||
*/
|
|
||||||
export const useSpaceChildRooms = (
|
export const useSpaceChildRooms = (
|
||||||
mx: MatrixClient,
|
mx: MatrixClient,
|
||||||
spaceId: string,
|
spaceId: string,
|
||||||
roomsAtom: typeof allRoomsAtom,
|
roomsAtom: typeof allRoomsAtom,
|
||||||
|
mDirects: Set<string>,
|
||||||
roomToParents: RoomToParents
|
roomToParents: RoomToParents
|
||||||
) => {
|
) => {
|
||||||
const selector = useCallback(
|
const selector = useCallback(
|
||||||
(rooms: string[]) =>
|
(rooms: string[]) =>
|
||||||
rooms.filter(
|
rooms.filter(
|
||||||
(roomId) => isRoom(mx.getRoom(roomId)) && roomToParents.get(roomId)?.has(spaceId)
|
(roomId) =>
|
||||||
|
isRoom(mx.getRoom(roomId)) &&
|
||||||
|
!mDirects.has(roomId) &&
|
||||||
|
roomToParents.get(roomId)?.has(spaceId)
|
||||||
),
|
),
|
||||||
[mx, spaceId, roomToParents]
|
[mx, spaceId, mDirects, roomToParents]
|
||||||
);
|
);
|
||||||
return useAtomValue(selectAtom(roomsAtom, selector, compareRoomsEqual));
|
return useAtomValue(selectAtom(roomsAtom, selector, compareRoomsEqual));
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
export const useSpaceChildDirectsRecursive = (
|
||||||
* select list of all room ids from all rooms for which spaceId is in all parents
|
|
||||||
* @param mx to check room type
|
|
||||||
* @param spaceId as root parent
|
|
||||||
* @param roomsAtom to pick rooms
|
|
||||||
* @param mDirects to include only direct rooms
|
|
||||||
* @param roomToParents: to include child room
|
|
||||||
* @returns list of direct room ids
|
|
||||||
*/
|
|
||||||
export const useSpaceRecursiveChildDirects = (
|
|
||||||
mx: MatrixClient,
|
mx: MatrixClient,
|
||||||
spaceId: string,
|
spaceId: string,
|
||||||
roomsAtom: typeof allRoomsAtom,
|
roomsAtom: typeof allRoomsAtom,
|
||||||
|
@ -122,15 +88,6 @@ export const useSpaceRecursiveChildDirects = (
|
||||||
return useAtomValue(selectAtom(roomsAtom, selector, compareRoomsEqual));
|
return useAtomValue(selectAtom(roomsAtom, selector, compareRoomsEqual));
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* select list of all room ids from all rooms for which spaceId is in parents and is in mDirects
|
|
||||||
* @param mx to check room type
|
|
||||||
* @param spaceId as root parent
|
|
||||||
* @param roomsAtom to pick rooms
|
|
||||||
* @param mDirects to include only direct rooms
|
|
||||||
* @param roomToParents: to include child rooms
|
|
||||||
* @returns list of space ids
|
|
||||||
*/
|
|
||||||
export const useSpaceChildDirects = (
|
export const useSpaceChildDirects = (
|
||||||
mx: MatrixClient,
|
mx: MatrixClient,
|
||||||
spaceId: string,
|
spaceId: string,
|
||||||
|
@ -151,13 +108,6 @@ export const useSpaceChildDirects = (
|
||||||
return useAtomValue(selectAtom(roomsAtom, selector, compareRoomsEqual));
|
return useAtomValue(selectAtom(roomsAtom, selector, compareRoomsEqual));
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* select list of room ids from all rooms which are not direct(dm)
|
|
||||||
* @param mx to check room type
|
|
||||||
* @param roomsAtom to pick rooms
|
|
||||||
* @param mDirects to exclude direct rooms
|
|
||||||
* @returns list of room ids
|
|
||||||
*/
|
|
||||||
export const useRooms = (
|
export const useRooms = (
|
||||||
mx: MatrixClient,
|
mx: MatrixClient,
|
||||||
roomsAtom: typeof allRoomsAtom,
|
roomsAtom: typeof allRoomsAtom,
|
||||||
|
@ -171,14 +121,6 @@ export const useRooms = (
|
||||||
return useAtomValue(selectAtom(roomsAtom, selector, compareRoomsEqual));
|
return useAtomValue(selectAtom(roomsAtom, selector, compareRoomsEqual));
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* select list of room ids from all rooms which are not direct(dm) and doesn't have any parent
|
|
||||||
* @param mx to check room type
|
|
||||||
* @param roomsAtom to pick rooms
|
|
||||||
* @param mDirects to exclude direct rooms
|
|
||||||
* @param roomToParents to exclude rooms with parent
|
|
||||||
* @returns list of room ids
|
|
||||||
*/
|
|
||||||
export const useOrphanRooms = (
|
export const useOrphanRooms = (
|
||||||
mx: MatrixClient,
|
mx: MatrixClient,
|
||||||
roomsAtom: typeof allRoomsAtom,
|
roomsAtom: typeof allRoomsAtom,
|
||||||
|
@ -196,13 +138,6 @@ export const useOrphanRooms = (
|
||||||
return useAtomValue(selectAtom(roomsAtom, selector, compareRoomsEqual));
|
return useAtomValue(selectAtom(roomsAtom, selector, compareRoomsEqual));
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* select list of room ids from all rooms which are direct(dm)
|
|
||||||
* @param mx to check room type
|
|
||||||
* @param roomsAtom to pick rooms
|
|
||||||
* @param mDirects to only include direct rooms
|
|
||||||
* @returns list of room ids
|
|
||||||
*/
|
|
||||||
export const useDirects = (
|
export const useDirects = (
|
||||||
mx: MatrixClient,
|
mx: MatrixClient,
|
||||||
roomsAtom: typeof allRoomsAtom,
|
roomsAtom: typeof allRoomsAtom,
|
||||||
|
@ -216,12 +151,6 @@ export const useDirects = (
|
||||||
return useAtomValue(selectAtom(roomsAtom, selector, compareRoomsEqual));
|
return useAtomValue(selectAtom(roomsAtom, selector, compareRoomsEqual));
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* select list of room ids for which room type is unsupported
|
|
||||||
* @param mx to check room type
|
|
||||||
* @param roomsAtom to pick rooms
|
|
||||||
* @returns list of unsupported room ids
|
|
||||||
*/
|
|
||||||
export const useUnsupportedRooms = (mx: MatrixClient, roomsAtom: typeof allRoomsAtom) => {
|
export const useUnsupportedRooms = (mx: MatrixClient, roomsAtom: typeof allRoomsAtom) => {
|
||||||
const selector = useCallback(
|
const selector = useCallback(
|
||||||
(rooms: string[]) => rooms.filter((roomId) => isUnsupportedRoom(mx.getRoom(roomId))),
|
(rooms: string[]) => rooms.filter((roomId) => isUnsupportedRoom(mx.getRoom(roomId))),
|
||||||
|
|
Loading…
Reference in a new issue