2021-09-05 15:26:34 +02:00
|
|
|
import React, { useEffect, useRef } from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
2021-09-03 14:28:01 +02:00
|
|
|
import './DrawerBreadcrumb.scss';
|
|
|
|
|
|
|
|
import initMatrix from '../../../client/initMatrix';
|
|
|
|
import cons from '../../../client/state/cons';
|
|
|
|
import { selectSpace } from '../../../client/action/navigation';
|
|
|
|
import navigation from '../../../client/state/navigation';
|
|
|
|
|
|
|
|
import Text from '../../atoms/text/Text';
|
|
|
|
import RawIcon from '../../atoms/system-icons/RawIcon';
|
|
|
|
import Button from '../../atoms/button/Button';
|
|
|
|
import ScrollView from '../../atoms/scroll/ScrollView';
|
|
|
|
|
|
|
|
import ChevronRightIC from '../../../../public/res/ic/outlined/chevron-right.svg';
|
|
|
|
|
2021-09-05 15:26:34 +02:00
|
|
|
function DrawerBreadcrumb({ spaceId }) {
|
2021-09-03 14:28:01 +02:00
|
|
|
const scrollRef = useRef(null);
|
|
|
|
const mx = initMatrix.matrixClient;
|
|
|
|
const spacePath = navigation.selectedSpacePath;
|
|
|
|
|
2021-09-05 15:26:34 +02:00
|
|
|
useEffect(() => {
|
2021-09-03 14:28:01 +02:00
|
|
|
requestAnimationFrame(() => {
|
|
|
|
if (scrollRef?.current === null) return;
|
|
|
|
scrollRef.current.scrollLeft = scrollRef.current.scrollWidth;
|
|
|
|
});
|
2021-09-05 15:26:34 +02:00
|
|
|
}, [spaceId]);
|
2021-09-03 14:28:01 +02:00
|
|
|
|
2021-09-05 15:26:34 +02:00
|
|
|
if (spacePath.length === 1) return null;
|
2021-09-03 14:28:01 +02:00
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="breadcrumb__wrapper">
|
|
|
|
<ScrollView ref={scrollRef} horizontal vertical={false} invisible>
|
|
|
|
<div className="breadcrumb">
|
|
|
|
{
|
2021-09-05 15:26:34 +02:00
|
|
|
spacePath.map((id, index) => {
|
|
|
|
if (index === 0) {
|
|
|
|
return (
|
|
|
|
<Button key={id} onClick={() => selectSpace(id)}>
|
|
|
|
<Text variant="b2">{id === cons.tabs.HOME ? 'Home' : mx.getRoom(id).name}</Text>
|
|
|
|
</Button>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
return (
|
|
|
|
<React.Fragment
|
|
|
|
key={id}
|
2021-09-03 14:28:01 +02:00
|
|
|
>
|
2021-09-05 15:26:34 +02:00
|
|
|
<RawIcon size="extra-small" src={ChevronRightIC} />
|
|
|
|
<Button
|
|
|
|
className={index === spacePath.length - 1 ? 'breadcrumb__btn--selected' : ''}
|
|
|
|
onClick={() => selectSpace(id)}
|
|
|
|
>
|
|
|
|
<Text variant="b2">{ mx.getRoom(id).name }</Text>
|
|
|
|
</Button>
|
|
|
|
</React.Fragment>
|
|
|
|
);
|
|
|
|
})
|
2021-09-03 14:28:01 +02:00
|
|
|
}
|
|
|
|
<div style={{ width: 'var(--sp-extra-tight)', height: '100%' }} />
|
|
|
|
</div>
|
|
|
|
</ScrollView>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-09-05 15:26:34 +02:00
|
|
|
DrawerBreadcrumb.defaultProps = {
|
|
|
|
spaceId: null,
|
|
|
|
};
|
|
|
|
|
|
|
|
DrawerBreadcrumb.propTypes = {
|
|
|
|
spaceId: PropTypes.string,
|
|
|
|
};
|
|
|
|
|
2021-09-03 14:28:01 +02:00
|
|
|
export default DrawerBreadcrumb;
|