add room list atom

This commit is contained in:
Ajay Bura 2022-12-27 20:16:20 +05:30
parent 6b559404b2
commit 08070d41c5

27
src/app/state/roomList.ts Normal file
View file

@ -0,0 +1,27 @@
import { atom } from 'jotai';
import { mx } from '../../client/mx';
import { Membership } from '../../types/matrix/room';
import { isRoom, isSpace, isUnsupportedRoom } from '../utils/room';
import { mDirectAtom } from './mDirectList';
import { atomRoomsWithMemberships } from './utils';
export const allRoomsAtom = atom<string[]>([]);
allRoomsAtom.onMount = (setAtom) => atomRoomsWithMemberships(setAtom, mx(), [Membership.Join]);
export const spacesAtom = atom((get) =>
get(allRoomsAtom).filter((roomId) => isSpace(mx().getRoom(roomId)))
);
export const roomsAtom = atom((get) =>
get(allRoomsAtom).filter(
(roomId) => isRoom(mx().getRoom(roomId)) && !get(mDirectAtom).has(roomId)
)
);
export const directsAtom = atom((get) =>
get(allRoomsAtom).filter((roomId) => isRoom(mx().getRoom(roomId)) && get(mDirectAtom).has(roomId))
);
export const unsupportedRoomsAtom = atom((get) =>
get(allRoomsAtom).filter((roomId) => isUnsupportedRoom(mx().getRoom(roomId)))
);