Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Display subspaces in minimized space panel #6555

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion res/css/structures/_SpacePanel.scss
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ $activeBorderColor: $secondary-fg-color;

> .mx_SpaceItem {
padding-left: 16px;

&.mx_SpaceItem_narrow {
padding-left: 4px;
}
}
}

Expand All @@ -87,6 +91,7 @@ $activeBorderColor: $secondary-fg-color;

&.mx_SpaceItem_narrow {
align-self: baseline;
max-width: 60px;
}
}

Expand Down Expand Up @@ -126,14 +131,14 @@ $activeBorderColor: $secondary-fg-color;
.mx_SpaceButton_selectionWrapper {
position: relative;
display: flex;
flex: 1;
align-items: center;
border-radius: 12px;
padding: 4px;
}

&:not(.mx_SpaceButton_narrow) {
.mx_SpaceButton_selectionWrapper {
flex: 1;
width: 100%;
padding-right: 16px;
overflow: hidden;
Expand Down
2 changes: 0 additions & 2 deletions src/components/views/spaces/SpacePanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,6 @@ const InnerSpacePanel = React.memo<IInnerSpacePanelProps>(({ children, isPanelCo
space={s}
activeSpaces={activeSpaces}
isPanelCollapsed={isPanelCollapsed}
onExpand={() => setPanelCollapsed(false)}
/>
)) }
{ spaces.map((s, i) => (
Expand All @@ -188,7 +187,6 @@ const InnerSpacePanel = React.memo<IInnerSpacePanelProps>(({ children, isPanelCo
space={s}
activeSpaces={activeSpaces}
isPanelCollapsed={isPanelCollapsed}
onExpand={() => setPanelCollapsed(false)}
/>
) }
</Draggable>
Expand Down
30 changes: 12 additions & 18 deletions src/components/views/spaces/SpaceTreeLevel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ interface IItemProps extends InputHTMLAttributes<HTMLLIElement> {
activeSpaces: Room[];
isNested?: boolean;
isPanelCollapsed?: boolean;
onExpand?: Function;
parents?: Set<string>;
innerRef?: LegacyRef<HTMLLIElement>;
}
Expand Down Expand Up @@ -181,15 +180,8 @@ export class SpaceItem extends React.PureComponent<IItemProps, IItemState> {
.filter(s => !this.props.parents?.has(s.roomId));
}

private get isCollapsed() {
return this.state.collapsed || this.props.isPanelCollapsed;
}

private toggleCollapse = evt => {
if (this.props.onExpand && this.isCollapsed) {
this.props.onExpand();
}
const newCollapsedState = !this.isCollapsed;
const newCollapsedState = !this.state.collapsed;

SpaceTreeLevelLayoutStore.instance.setSpaceCollapsedState(
this.props.space.roomId,
Expand All @@ -208,7 +200,7 @@ export class SpaceItem extends React.PureComponent<IItemProps, IItemState> {
const hasChildren = this.state.childSpaces?.length;
switch (action) {
case RoomListAction.CollapseSection:
if (hasChildren && !this.isCollapsed) {
if (hasChildren && !this.state.collapsed) {
this.toggleCollapse(ev);
} else {
const parentItem = this.buttonRef?.current?.parentElement?.parentElement;
Expand All @@ -219,7 +211,7 @@ export class SpaceItem extends React.PureComponent<IItemProps, IItemState> {

case RoomListAction.ExpandSection:
if (hasChildren) {
if (this.isCollapsed) {
if (this.state.collapsed) {
this.toggleCollapse(ev);
} else {
const childLevel = this.buttonRef?.current?.nextElementSibling;
Expand Down Expand Up @@ -247,15 +239,13 @@ export class SpaceItem extends React.PureComponent<IItemProps, IItemState> {

render() {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { space, activeSpaces, isNested, isPanelCollapsed, onExpand, parents, innerRef,
const { space, activeSpaces, isNested, isPanelCollapsed, parents, innerRef,
...otherProps } = this.props;

const collapsed = this.isCollapsed;

const itemClasses = classNames(this.props.className, {
"mx_SpaceItem": true,
"mx_SpaceItem_narrow": isPanelCollapsed,
"collapsed": collapsed,
"collapsed": this.state.collapsed,
"hasSubSpaces": this.state.childSpaces?.length,
});

Expand All @@ -266,11 +256,12 @@ export class SpaceItem extends React.PureComponent<IItemProps, IItemState> {
: SpaceStore.instance.getNotificationState(space.roomId);

let childItems;
if (this.state.childSpaces?.length && !collapsed) {
if (this.state.childSpaces?.length && !this.state.collapsed) {
childItems = <SpaceTreeLevel
spaces={this.state.childSpaces}
activeSpaces={activeSpaces}
isNested={true}
isPanelCollapsed={isPanelCollapsed}
parents={new Set(parents).add(space.roomId)}
/>;
}
Expand All @@ -280,7 +271,7 @@ export class SpaceItem extends React.PureComponent<IItemProps, IItemState> {
className="mx_SpaceButton_toggleCollapse"
onClick={this.toggleCollapse}
tabIndex={-1}
aria-label={collapsed ? _t("Expand") : _t("Collapse")}
aria-label={this.state.collapsed ? _t("Expand") : _t("Collapse")}
/> : null;

return (
Expand All @@ -296,7 +287,7 @@ export class SpaceItem extends React.PureComponent<IItemProps, IItemState> {
avatarSize={isNested ? 24 : 32}
onClick={this.onClick}
onKeyDown={this.onKeyDown}
aria-expanded={!collapsed}
aria-expanded={!this.state.collapsed}
ContextMenuComponent={this.props.space.getMyMembership() === "join"
? SpaceContextMenu : undefined}
>
Expand All @@ -313,13 +304,15 @@ interface ITreeLevelProps {
spaces: Room[];
activeSpaces: Room[];
isNested?: boolean;
isPanelCollapsed?: boolean;
parents: Set<string>;
}

const SpaceTreeLevel: React.FC<ITreeLevelProps> = ({
spaces,
activeSpaces,
isNested,
isPanelCollapsed,
parents,
}) => {
return <ul className="mx_SpaceTreeLevel">
Expand All @@ -329,6 +322,7 @@ const SpaceTreeLevel: React.FC<ITreeLevelProps> = ({
activeSpaces={activeSpaces}
space={s}
isNested={isNested}
isPanelCollapsed={isPanelCollapsed}
parents={parents}
/>);
}) }
Expand Down