mirror of
https://github.com/cinnyapp/cinny.git
synced 2025-11-06 23:30:28 +03:00
Refactor navigation
Signed-off-by: Ajay Bura <ajbura@gmail.com>
This commit is contained in:
parent
f47998a553
commit
992da7c7be
7 changed files with 130 additions and 55 deletions
21
src/app/hooks/useSelectedSpace.js
Normal file
21
src/app/hooks/useSelectedSpace.js
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
/* eslint-disable import/prefer-default-export */
|
||||
import { useState, useEffect } from 'react';
|
||||
|
||||
import cons from '../../client/state/cons';
|
||||
import navigation from '../../client/state/navigation';
|
||||
|
||||
export function useSelectedSpace() {
|
||||
const [spaceId, setSpaceId] = useState(navigation.selectedSpaceId);
|
||||
|
||||
useEffect(() => {
|
||||
const onSpaceSelected = (roomId) => {
|
||||
setSpaceId(roomId);
|
||||
};
|
||||
navigation.on(cons.events.navigation.SPACE_SELECTED, onSpaceSelected);
|
||||
return () => {
|
||||
navigation.removeListener(cons.events.navigation.SPACE_SELECTED, onSpaceSelected);
|
||||
};
|
||||
}, []);
|
||||
|
||||
return [spaceId];
|
||||
}
|
||||
21
src/app/hooks/useSelectedTab.js
Normal file
21
src/app/hooks/useSelectedTab.js
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
/* eslint-disable import/prefer-default-export */
|
||||
import { useState, useEffect } from 'react';
|
||||
|
||||
import cons from '../../client/state/cons';
|
||||
import navigation from '../../client/state/navigation';
|
||||
|
||||
export function useSelectedTab() {
|
||||
const [selectedTab, setSelectedTab] = useState(navigation.selectedTab);
|
||||
|
||||
useEffect(() => {
|
||||
const onTabSelected = (tabId) => {
|
||||
setSelectedTab(tabId);
|
||||
};
|
||||
navigation.on(cons.events.navigation.TAB_SELECTED, onTabSelected);
|
||||
return () => {
|
||||
navigation.removeListener(cons.events.navigation.TAB_SELECTED, onTabSelected);
|
||||
};
|
||||
}, []);
|
||||
|
||||
return [selectedTab];
|
||||
}
|
||||
22
src/app/hooks/useSpaceShortcut.js
Normal file
22
src/app/hooks/useSpaceShortcut.js
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
/* eslint-disable import/prefer-default-export */
|
||||
import { useState, useEffect } from 'react';
|
||||
|
||||
import initMatrix from '../../client/initMatrix';
|
||||
import cons from '../../client/state/cons';
|
||||
|
||||
export function useSpaceShortcut() {
|
||||
const { roomList } = initMatrix;
|
||||
const [spaceShortcut, setSpaceShortcut] = useState([...roomList.spaceShortcut]);
|
||||
|
||||
useEffect(() => {
|
||||
const onSpaceShortcutUpdated = () => {
|
||||
setSpaceShortcut([...roomList.spaceShortcut]);
|
||||
};
|
||||
roomList.on(cons.events.roomList.SPACE_SHORTCUT_UPDATED, onSpaceShortcutUpdated);
|
||||
return () => {
|
||||
roomList.removeListener(cons.events.roomList.SPACE_SHORTCUT_UPDATED, onSpaceShortcutUpdated);
|
||||
};
|
||||
}, []);
|
||||
|
||||
return [spaceShortcut];
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue