diff --git a/src/app/organisms/navigation/Drawer.jsx b/src/app/organisms/navigation/Drawer.jsx index fa273e0..e439d60 100644 --- a/src/app/organisms/navigation/Drawer.jsx +++ b/src/app/organisms/navigation/Drawer.jsx @@ -44,13 +44,13 @@ function AtoZ(aId, bId) { return 0; } -function DrawerHeader({ tabId }) { +function DrawerHeader({ activeTab }) { return (
- {(tabId === 'channels' ? 'Home' : 'Direct messages')} + {(activeTab === 'home' ? 'Home' : 'Direct messages')} - {(tabId === 'dm') + {(activeTab === 'dm') ? openInviteUser()} tooltip="Start DM" src={PlusIC} size="normal" /> : ( { - tabId === 'channels' + activeTab === 'home' ? : } @@ -196,18 +196,30 @@ function Channels({ tabId }) { ); } Channels.propTypes = { - tabId: PropTypes.string.isRequired, + activeTab: PropTypes.string.isRequired, }; -function Drawer({ tabId }) { +function Drawer() { + const [activeTab, setActiveTab] = useState('home'); + + function onTabChanged(tabId) { + setActiveTab(tabId); + } + + useEffect(() => { + navigation.on(cons.events.navigation.TAB_CHANGED, onTabChanged); + return () => { + navigation.removeListener(cons.events.navigation.TAB_CHANGED, onTabChanged); + }; + }, []); return (
- +
- +
@@ -215,8 +227,4 @@ function Drawer({ tabId }) { ); } -Drawer.propTypes = { - tabId: PropTypes.string.isRequired, -}; - export default Drawer; diff --git a/src/app/organisms/navigation/Navigation.jsx b/src/app/organisms/navigation/Navigation.jsx index 380266d..24bd1bd 100644 --- a/src/app/organisms/navigation/Navigation.jsx +++ b/src/app/organisms/navigation/Navigation.jsx @@ -1,34 +1,14 @@ -import React, { useState, useEffect } from 'react'; +import React from 'react'; import './Navigation.scss'; -import cons from '../../../client/state/cons'; -import navigation from '../../../client/state/navigation'; -import { handleTabChange } from '../../../client/action/navigation'; - import SideBar from './SideBar'; import Drawer from './Drawer'; function Navigation() { - const [activeTab, changeActiveTab] = useState(navigation.getActiveTab()); - - function changeTab(tabId) { - handleTabChange(tabId); - } - - useEffect(() => { - const handleTab = () => { - changeActiveTab(navigation.getActiveTab()); - }; - navigation.on(cons.events.navigation.TAB_CHANGED, handleTab); - - return () => { - navigation.removeListener(cons.events.navigation.TAB_CHANGED, handleTab); - }; - }, []); return (
- - + +
); } diff --git a/src/app/organisms/navigation/SideBar.jsx b/src/app/organisms/navigation/SideBar.jsx index 5b86ec8..adb8f51 100644 --- a/src/app/organisms/navigation/SideBar.jsx +++ b/src/app/organisms/navigation/SideBar.jsx @@ -1,12 +1,14 @@ import React, { useState, useEffect } from 'react'; -import PropTypes from 'prop-types'; import './SideBar.scss'; import initMatrix from '../../../client/initMatrix'; import cons from '../../../client/state/cons'; import colorMXID from '../../../util/colorMXID'; import logout from '../../../client/action/logout'; -import { openInviteList, openPublicChannels, openSettings } from '../../../client/action/navigation'; +import { + changeTab, openInviteList, openPublicChannels, openSettings, +} from '../../../client/action/navigation'; +import navigation from '../../../client/state/navigation'; import ScrollView from '../../atoms/scroll/ScrollView'; import SidebarAvatar from '../../molecules/sidebar-avatar/SidebarAvatar'; @@ -52,24 +54,30 @@ function ProfileAvatarMenu() { ); } -function SideBar({ tabId, changeTab }) { +function SideBar() { const totalInviteCount = () => initMatrix.roomList.inviteRooms.size + initMatrix.roomList.inviteSpaces.size + initMatrix.roomList.inviteDirects.size; const [totalInvites, updateTotalInvites] = useState(totalInviteCount()); + const [activeTab, setActiveTab] = useState('home'); + function onTabChanged(tabId) { + setActiveTab(tabId); + } function onInviteListChange() { updateTotalInvites(totalInviteCount()); } useEffect(() => { + navigation.on(cons.events.navigation.TAB_CHANGED, onTabChanged); initMatrix.roomList.on( cons.events.roomList.INVITELIST_UPDATED, onInviteListChange, ); return () => { + navigation.removeListener(cons.events.navigation.TAB_CHANGED, onTabChanged); initMatrix.roomList.removeListener( cons.events.roomList.INVITELIST_UPDATED, onInviteListChange, @@ -83,8 +91,8 @@ function SideBar({ tabId, changeTab }) {
- changeTab('channels')} tooltip="Home" iconSrc={HomeIC} /> - changeTab('dm')} tooltip="People" iconSrc={UserIC} /> + changeTab('home')} tooltip="Home" iconSrc={HomeIC} /> + changeTab('dms')} tooltip="People" iconSrc={UserIC} /> openPublicChannels()} tooltip="Public channels" iconSrc={HashSearchIC} />
@@ -110,9 +118,4 @@ function SideBar({ tabId, changeTab }) { ); } -SideBar.propTypes = { - tabId: PropTypes.string.isRequired, - changeTab: PropTypes.func.isRequired, -}; - export default SideBar; diff --git a/src/client/action/navigation.js b/src/client/action/navigation.js index 543ff4a..78c001f 100644 --- a/src/client/action/navigation.js +++ b/src/client/action/navigation.js @@ -1,7 +1,7 @@ import appDispatcher from '../dispatcher'; import cons from '../state/cons'; -function handleTabChange(tabId) { +function changeTab(tabId) { appDispatcher.dispatch({ type: cons.actions.navigation.CHANGE_TAB, tabId, @@ -71,7 +71,7 @@ function openReadReceipts(roomId, eventId) { } export { - handleTabChange, + changeTab, selectRoom, togglePeopleDrawer, openInviteList,