mirror of
https://github.com/cinnyapp/cinny.git
synced 2025-11-16 04:00:29 +03:00
Added space nesting (#52)
This commit is contained in:
parent
6c1a602bdc
commit
4efc320f23
18 changed files with 368 additions and 91 deletions
|
|
@ -1,9 +1,10 @@
|
|||
import React, { useState, useEffect } from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
|
||||
import initMatrix from '../../../client/initMatrix';
|
||||
import cons from '../../../client/state/cons';
|
||||
import navigation from '../../../client/state/navigation';
|
||||
import { selectRoom } from '../../../client/action/navigation';
|
||||
import { selectSpace, selectRoom } from '../../../client/action/navigation';
|
||||
import Postie from '../../../util/Postie';
|
||||
|
||||
import Text from '../../atoms/text/Text';
|
||||
|
|
@ -12,20 +13,32 @@ import Selector from './Selector';
|
|||
import { AtoZ } from './common';
|
||||
|
||||
const drawerPostie = new Postie();
|
||||
function Home() {
|
||||
const { roomList } = initMatrix;
|
||||
const spaceIds = [...roomList.spaces].sort(AtoZ);
|
||||
const roomIds = [...roomList.rooms].sort(AtoZ);
|
||||
|
||||
function Home({ spaceId }) {
|
||||
const [, forceUpdate] = useState({});
|
||||
const { roomList } = initMatrix;
|
||||
let spaceIds = [];
|
||||
let roomIds = [];
|
||||
let directIds = [];
|
||||
|
||||
function selectorChanged(activeRoomID, prevActiveRoomId) {
|
||||
const spaceChildIds = roomList.getSpaceChildren(spaceId);
|
||||
if (spaceChildIds) {
|
||||
spaceIds = spaceChildIds.filter((roomId) => roomList.spaces.has(roomId)).sort(AtoZ);
|
||||
roomIds = spaceChildIds.filter((roomId) => roomList.rooms.has(roomId)).sort(AtoZ);
|
||||
directIds = spaceChildIds.filter((roomId) => roomList.directs.has(roomId)).sort(AtoZ);
|
||||
} else {
|
||||
spaceIds = [...roomList.spaces]
|
||||
.filter((roomId) => !roomList.roomIdToParents.has(roomId)).sort(AtoZ);
|
||||
roomIds = [...roomList.rooms]
|
||||
.filter((roomId) => !roomList.roomIdToParents.has(roomId)).sort(AtoZ);
|
||||
}
|
||||
|
||||
function selectorChanged(selectedRoomId, prevSelectedRoomId) {
|
||||
if (!drawerPostie.hasTopic('selector-change')) return;
|
||||
const addresses = [];
|
||||
if (drawerPostie.hasSubscriber('selector-change', activeRoomID)) addresses.push(activeRoomID);
|
||||
if (drawerPostie.hasSubscriber('selector-change', prevActiveRoomId)) addresses.push(prevActiveRoomId);
|
||||
if (drawerPostie.hasSubscriber('selector-change', selectedRoomId)) addresses.push(selectedRoomId);
|
||||
if (drawerPostie.hasSubscriber('selector-change', prevSelectedRoomId)) addresses.push(prevSelectedRoomId);
|
||||
if (addresses.length === 0) return;
|
||||
drawerPostie.post('selector-change', addresses, activeRoomID);
|
||||
drawerPostie.post('selector-change', addresses, selectedRoomId);
|
||||
}
|
||||
function unreadChanged(roomId) {
|
||||
if (!drawerPostie.hasTopic('unread-change')) return;
|
||||
|
|
@ -36,9 +49,9 @@ function Home() {
|
|||
function roomListUpdated() {
|
||||
const { spaces, rooms, directs } = initMatrix.roomList;
|
||||
if (!(
|
||||
spaces.has(navigation.getActiveRoomId())
|
||||
|| rooms.has(navigation.getActiveRoomId())
|
||||
|| directs.has(navigation.getActiveRoomId()))
|
||||
spaces.has(navigation.selectedRoomId)
|
||||
|| rooms.has(navigation.selectedRoomId)
|
||||
|| directs.has(navigation.selectedRoomId))
|
||||
) {
|
||||
selectRoom(null);
|
||||
}
|
||||
|
|
@ -67,6 +80,7 @@ function Home() {
|
|||
roomId={id}
|
||||
isDM={false}
|
||||
drawerPostie={drawerPostie}
|
||||
onClick={() => selectSpace(id)}
|
||||
/>
|
||||
))}
|
||||
|
||||
|
|
@ -77,10 +91,27 @@ function Home() {
|
|||
roomId={id}
|
||||
isDM={false}
|
||||
drawerPostie={drawerPostie}
|
||||
onClick={() => selectRoom(id)}
|
||||
/>
|
||||
)) }
|
||||
|
||||
{ directIds.length !== 0 && <Text className="cat-header" variant="b3">People</Text> }
|
||||
{ directIds.map((id) => (
|
||||
<Selector
|
||||
key={id}
|
||||
roomId={id}
|
||||
drawerPostie={drawerPostie}
|
||||
onClick={() => selectRoom(id)}
|
||||
/>
|
||||
))}
|
||||
</>
|
||||
);
|
||||
}
|
||||
Home.defaultProps = {
|
||||
spaceId: null,
|
||||
};
|
||||
Home.propTypes = {
|
||||
spaceId: PropTypes.string,
|
||||
};
|
||||
|
||||
export default Home;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue