mirror of
https://github.com/SableClient/Sable.git
synced 2026-11-20 09:01:17 -08:00
Update Space sidebar with depth-based link to space lobby
This commit is contained in:
1 parent
61c045375c
commit
bf36587df3
4 files changed
+129
-8
No files matched your search
@@ -0,0 +1,98 @@
|
||||
import { MouseEventHandler, useState } from 'react';
|
||||
import { Room } from '$types/matrix-sdk';
|
||||
import {
|
||||
Box,
|
||||
Icon,
|
||||
Icons,
|
||||
Text,
|
||||
config,
|
||||
RectCords,
|
||||
Avatar,
|
||||
} from 'folds';
|
||||
import { useFocusWithin, useHover } from 'react-aria';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import { NavButton, NavItem, NavItemContent } from '$components/nav';
|
||||
import { useRoomName } from '$hooks/useRoomMeta';
|
||||
|
||||
type SpaceNavItemProps = {
|
||||
room: Room;
|
||||
selected: boolean;
|
||||
linkPath: string;
|
||||
};
|
||||
|
||||
export function SpaceNavItem({
|
||||
room,
|
||||
selected,
|
||||
linkPath,
|
||||
}: SpaceNavItemProps) {
|
||||
const [hover, setHover] = useState(false);
|
||||
const { hoverProps } = useHover({ onHoverChange: setHover });
|
||||
const { focusWithinProps } = useFocusWithin({ onFocusWithinChange: setHover });
|
||||
const [menuAnchor, setMenuAnchor] = useState<RectCords>();
|
||||
|
||||
const matrixRoomName = useRoomName(room);
|
||||
const roomName = matrixRoomName;
|
||||
|
||||
const navigate = useNavigate();
|
||||
|
||||
const handleContextMenu: MouseEventHandler<HTMLElement> = (evt) => {
|
||||
evt.preventDefault();
|
||||
setMenuAnchor({
|
||||
x: evt.clientX,
|
||||
y: evt.clientY,
|
||||
width: 0,
|
||||
height: 0,
|
||||
});
|
||||
};
|
||||
|
||||
const handleNavItemClick: MouseEventHandler<HTMLElement> = (evt) => {
|
||||
navigate(linkPath);
|
||||
};
|
||||
|
||||
const ariaLabel = [
|
||||
roomName,
|
||||
'Space'
|
||||
]
|
||||
.flat()
|
||||
.filter(Boolean)
|
||||
.join(', ');
|
||||
|
||||
return (
|
||||
<Box direction="Column" grow="Yes">
|
||||
<NavItem
|
||||
variant="Background"
|
||||
radii="400"
|
||||
highlight={false}
|
||||
aria-selected={selected}
|
||||
data-hover={!!menuAnchor}
|
||||
onContextMenu={handleContextMenu}
|
||||
{...hoverProps}
|
||||
{...focusWithinProps}
|
||||
>
|
||||
<NavButton onClick={handleNavItemClick} aria-label={ariaLabel}>
|
||||
<NavItemContent>
|
||||
<Box as="span" grow="Yes" alignItems="Center" gap="200">
|
||||
<Avatar size="200" radii="400">
|
||||
<Icon src={Icons.Space}
|
||||
style={{ opacity: config.opacity.P300, }}
|
||||
filled={selected}
|
||||
size="100"
|
||||
/>
|
||||
</Avatar>
|
||||
<Box as="span" grow="Yes">
|
||||
<Text
|
||||
priority="300"
|
||||
as="span"
|
||||
size="Inherit"
|
||||
truncate
|
||||
>
|
||||
{roomName}
|
||||
</Text>
|
||||
</Box>
|
||||
</Box>
|
||||
</NavItemContent>
|
||||
</NavButton>
|
||||
</NavItem>
|
||||
</Box>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
export * from './SpaceNavItem';
|
||||
@@ -49,7 +49,7 @@ const childEventByOrder: SortFunc<MatrixEvent> = (a, b) =>
|
||||
const getHierarchySpaces = (
|
||||
rootSpaceId: string,
|
||||
getRoom: GetRoomCallback,
|
||||
excludeRoom: (parentId: string, roomId: string) => boolean,
|
||||
excludeRoom: (parentId: string, roomId: string, depth: number) => boolean,
|
||||
spaceRooms: Set<string>
|
||||
): HierarchyItemSpace[] => {
|
||||
const rootSpaceItem: HierarchyItemSpace = {
|
||||
@@ -81,7 +81,7 @@ const getHierarchySpaces = (
|
||||
if (!isValidChild(childEvent)) return false;
|
||||
const childId = childEvent.getStateKey();
|
||||
if (!childId || !isRoomId(childId)) return false;
|
||||
if (excludeRoom(spaceItem.roomId, childId)) return false;
|
||||
if (excludeRoom(spaceItem.roomId, childId, spaceItem.depth)) return false;
|
||||
|
||||
// because we can not find if a childId is space without joining
|
||||
// or requesting room summary, we will look it into spaceRooms local
|
||||
@@ -202,7 +202,7 @@ export const useSpaceHierarchy = (
|
||||
const getSpaceJoinedHierarchy = (
|
||||
rootSpaceId: string,
|
||||
getRoom: GetRoomCallback,
|
||||
excludeRoom: (parentId: string, roomId: string) => boolean,
|
||||
excludeRoom: (parentId: string, roomId: string, depth: number) => boolean,
|
||||
sortRoomItems: (parentId: string, items: HierarchyItem[]) => HierarchyItem[]
|
||||
): HierarchyItem[] => {
|
||||
const spaceItems: HierarchyItemSpace[] = getHierarchySpaces(
|
||||
@@ -263,7 +263,7 @@ const getSpaceJoinedHierarchy = (
|
||||
const childId = childEvent.getStateKey();
|
||||
if (!childId) return;
|
||||
|
||||
if (excludeRoom(space.roomId, childId)) return;
|
||||
if (excludeRoom(space.roomId, childId, spaceItem.depth)) return;
|
||||
|
||||
const childItem: HierarchyItemRoom = {
|
||||
roomId: childId,
|
||||
@@ -283,7 +283,7 @@ const getSpaceJoinedHierarchy = (
|
||||
export const useSpaceJoinedHierarchy = (
|
||||
spaceId: string,
|
||||
getRoom: GetRoomCallback,
|
||||
excludeRoom: (parentId: string, roomId: string) => boolean,
|
||||
excludeRoom: (parentId: string, roomId: string, depth: number) => boolean,
|
||||
sortByActivity: (spaceId: string) => boolean
|
||||
): HierarchyItem[] => {
|
||||
const mx = useMatrixClient();
|
||||
|
||||
@@ -33,6 +33,7 @@ import { useSpace } from '$hooks/useSpace';
|
||||
import { VirtualTile } from '$components/virtualizer';
|
||||
import { spaceRoomsAtom } from '$state/spaceRooms';
|
||||
import { RoomNavCategoryButton, RoomNavItem } from '$features/room-nav';
|
||||
import { SpaceNavItem } from '$features/space-nav';
|
||||
import { makeNavCategoryId, getNavCategoryIdParts } from '$state/closedNavCategories';
|
||||
import { roomToUnreadAtom } from '$state/room/roomToUnread';
|
||||
import { useCategoryHandler } from '$hooks/useCategoryHandler';
|
||||
@@ -519,7 +520,11 @@ export function Space() {
|
||||
space.roomId,
|
||||
getRoom,
|
||||
useCallback(
|
||||
(parentId, roomId) => {
|
||||
(parentId, roomId, depth) => {
|
||||
if (depth >= 4)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if (!getInClosedCategories(space.roomId, parentId, roomId)) {
|
||||
return false;
|
||||
}
|
||||
@@ -564,7 +569,7 @@ export function Space() {
|
||||
const getCategoryPadding = (depth: number): string | undefined => {
|
||||
if (depth === 0) return undefined;
|
||||
if (depth === 1) return config.space.S400;
|
||||
return config.space.S200;
|
||||
return config.space.S0;
|
||||
};
|
||||
|
||||
const navigate = useNavigate();
|
||||
@@ -633,7 +638,24 @@ export function Space() {
|
||||
const { roomId, depth } = hierarchy[vItem.index] ?? {};
|
||||
const room = mx.getRoom(roomId);
|
||||
if (!room) return null;
|
||||
|
||||
if (depth == 4 && room.isSpaceRoom()) {
|
||||
return (
|
||||
<VirtualTile
|
||||
virtualItem={vItem}
|
||||
key={vItem.index}
|
||||
ref={virtualizer.measureElement}
|
||||
>
|
||||
<div style={{ paddingLeft: `calc(${depth-2} * ${config.space.S200})` }}>
|
||||
<SpaceNavItem
|
||||
room={room}
|
||||
selected={selectedRoomId === roomId}
|
||||
linkPath={getSpaceLobbyPath(getCanonicalAliasOrRoomId(mx, roomId))}
|
||||
/>
|
||||
</div>
|
||||
</VirtualTile>
|
||||
)
|
||||
}
|
||||
|
||||
const paddingTop = getCategoryPadding(depth)
|
||||
const paddingLeft = `calc(${depth-1} * ${config.space.S200})`
|
||||
|
||||
|
||||
Reference in new issue
Block a user