mirror of
https://github.com/cinnyapp/cinny.git
synced 2025-02-23 05:33:07 +01:00
add selected navigation hooks
This commit is contained in:
parent
08def422fe
commit
389a1bbd26
4 changed files with 54 additions and 0 deletions
12
src/app/hooks/useDirectSelected.ts
Normal file
12
src/app/hooks/useDirectSelected.ts
Normal file
|
@ -0,0 +1,12 @@
|
|||
import { useMatch } from 'react-router-dom';
|
||||
import { getDirectPath } from '../pages/pathUtils';
|
||||
|
||||
export const useDirectSelected = (): boolean => {
|
||||
const directMatch = useMatch({
|
||||
path: getDirectPath(),
|
||||
caseSensitive: true,
|
||||
end: false,
|
||||
});
|
||||
|
||||
return !!directMatch;
|
||||
};
|
12
src/app/hooks/useHomeSelected.ts
Normal file
12
src/app/hooks/useHomeSelected.ts
Normal file
|
@ -0,0 +1,12 @@
|
|||
import { useMatch } from 'react-router-dom';
|
||||
import { getHomePath } from '../pages/pathUtils';
|
||||
|
||||
export const useHomeSelected = (): boolean => {
|
||||
const homeMatch = useMatch({
|
||||
path: getHomePath(),
|
||||
caseSensitive: true,
|
||||
end: false,
|
||||
});
|
||||
|
||||
return !!homeMatch;
|
||||
};
|
15
src/app/hooks/useSelectedRoom.ts
Normal file
15
src/app/hooks/useSelectedRoom.ts
Normal file
|
@ -0,0 +1,15 @@
|
|||
import { useParams } from 'react-router-dom';
|
||||
import { getCanonicalAliasRoomId, isRoomAlias } from '../utils/matrix';
|
||||
import { useMatrixClient } from './useMatrixClient';
|
||||
|
||||
export const useSelectedRoom = (): string | undefined => {
|
||||
const mx = useMatrixClient();
|
||||
|
||||
const { roomIdOrAlias } = useParams();
|
||||
const roomId =
|
||||
roomIdOrAlias && isRoomAlias(roomIdOrAlias)
|
||||
? getCanonicalAliasRoomId(mx, roomIdOrAlias)
|
||||
: roomIdOrAlias;
|
||||
|
||||
return roomId;
|
||||
};
|
15
src/app/hooks/useSelectedSpace.ts
Normal file
15
src/app/hooks/useSelectedSpace.ts
Normal file
|
@ -0,0 +1,15 @@
|
|||
import { useParams } from 'react-router-dom';
|
||||
import { getCanonicalAliasRoomId, isRoomAlias } from '../utils/matrix';
|
||||
import { useMatrixClient } from './useMatrixClient';
|
||||
|
||||
export const useSelectedSpace = (): string | undefined => {
|
||||
const mx = useMatrixClient();
|
||||
|
||||
const { spaceIdOrAlias } = useParams();
|
||||
const spaceId =
|
||||
spaceIdOrAlias && isRoomAlias(spaceIdOrAlias)
|
||||
? getCanonicalAliasRoomId(mx, spaceIdOrAlias)
|
||||
: spaceIdOrAlias;
|
||||
|
||||
return spaceId;
|
||||
};
|
Loading…
Reference in a new issue