add navigation atoms
This commit is contained in:
parent
c7e668eed2
commit
23de3aa4a3
4 changed files with 58 additions and 2 deletions
|
@ -1,5 +1,6 @@
|
|||
import React from 'react';
|
||||
import { Icon, Icons, Badge, AvatarFallback, Text } from 'folds';
|
||||
import { useAtom } from 'jotai';
|
||||
|
||||
import {
|
||||
Sidebar,
|
||||
|
@ -8,8 +9,11 @@ import {
|
|||
SidebarStack,
|
||||
SidebarAvatar,
|
||||
} from '../../components/sidebar';
|
||||
import { selectedTabAtom, SidebarTab } from '../../state/selectedTab';
|
||||
|
||||
export function Sidebar1() {
|
||||
const [selectedTab, setSelectedTab] = useAtom(selectedTabAtom);
|
||||
|
||||
return (
|
||||
<Sidebar>
|
||||
<SidebarContent
|
||||
|
@ -17,12 +21,19 @@ export function Sidebar1() {
|
|||
<>
|
||||
<SidebarStack>
|
||||
<SidebarAvatar
|
||||
active
|
||||
active={selectedTab === SidebarTab.Home}
|
||||
outlined
|
||||
tooltip="Home"
|
||||
avatarChildren={<Icon src={Icons.Home} filled />}
|
||||
onClick={() => setSelectedTab(SidebarTab.Home)}
|
||||
/>
|
||||
<SidebarAvatar
|
||||
active={selectedTab === SidebarTab.People}
|
||||
outlined
|
||||
tooltip="People"
|
||||
avatarChildren={<Icon src={Icons.User} />}
|
||||
onClick={() => setSelectedTab(SidebarTab.People)}
|
||||
/>
|
||||
<SidebarAvatar outlined tooltip="People" avatarChildren={<Icon src={Icons.User} />} />
|
||||
</SidebarStack>
|
||||
<SidebarStackSeparator />
|
||||
<SidebarStack>
|
||||
|
|
3
src/app/state/selectedRoom.ts
Normal file
3
src/app/state/selectedRoom.ts
Normal file
|
@ -0,0 +1,3 @@
|
|||
import { atom } from 'jotai';
|
||||
|
||||
export const selectedRoomAtom = atom<string | undefined>(undefined);
|
8
src/app/state/selectedTab.ts
Normal file
8
src/app/state/selectedTab.ts
Normal file
|
@ -0,0 +1,8 @@
|
|||
import { atom } from 'jotai';
|
||||
|
||||
export enum SidebarTab {
|
||||
Home = 'Home',
|
||||
People = 'People',
|
||||
}
|
||||
|
||||
export const selectedTabAtom = atom<SidebarTab | string>(SidebarTab.Home);
|
34
src/app/state/tabToRoom.ts
Normal file
34
src/app/state/tabToRoom.ts
Normal file
|
@ -0,0 +1,34 @@
|
|||
import produce from 'immer';
|
||||
import { atom } from 'jotai';
|
||||
import { MatrixClient } from 'matrix-js-sdk';
|
||||
|
||||
type RoomInfo = {
|
||||
roomId: string;
|
||||
timestamp: number;
|
||||
};
|
||||
type TabToRoom = Map<string, RoomInfo>;
|
||||
|
||||
type TabToRoomAction = {
|
||||
type: 'PUT';
|
||||
tabInfo: { tabId: string; roomInfo: RoomInfo };
|
||||
};
|
||||
|
||||
const baseTabToRoom = atom<TabToRoom>(new Map());
|
||||
export const tabToRoomAtom = atom<TabToRoom, TabToRoomAction>(
|
||||
(get) => get(baseTabToRoom),
|
||||
(get, set, action) => {
|
||||
if (action.type === 'PUT') {
|
||||
set(
|
||||
baseTabToRoom,
|
||||
produce(get(baseTabToRoom), (draft) => {
|
||||
draft.set(action.tabInfo.tabId, action.tabInfo.roomInfo);
|
||||
})
|
||||
);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
export const useBindTabToRoomAtom = (mx: MatrixClient) => {
|
||||
console.log(mx);
|
||||
// TODO:
|
||||
};
|
Loading…
Add table
Reference in a new issue