Files
cinny/src/app/state/room-list/inviteList.ts
T

33 lines
954 B
TypeScript
Raw Normal View History

2023-06-12 21:15:23 +10:00
import { atom, WritableAtom } from 'jotai';
import { MatrixClient } from 'matrix-js-sdk';
import { useMemo } from 'react';
import { Membership } from '../../../types/matrix/room';
2023-06-12 21:15:23 +10:00
import { RoomsAction, useBindRoomsWithMembershipsAtom } from './utils';
const baseRoomsAtom = atom<string[]>([]);
2024-01-21 23:50:56 +11:00
export const allInvitesAtom = atom<string[], [RoomsAction], undefined>(
2023-06-12 21:15:23 +10:00
(get) => get(baseRoomsAtom),
(get, set, action) => {
if (action.type === 'INITIALIZE') {
set(baseRoomsAtom, action.rooms);
return;
}
set(baseRoomsAtom, (ids) => {
const newIds = ids.filter((id) => id !== action.roomId);
if (action.type === 'PUT') newIds.push(action.roomId);
return newIds;
});
}
);
export const useBindAllInvitesAtom = (
mx: MatrixClient,
2024-01-21 23:50:56 +11:00
allRooms: WritableAtom<string[], [RoomsAction], undefined>
2023-06-12 21:15:23 +10:00
) => {
useBindRoomsWithMembershipsAtom(
mx,
allRooms,
useMemo(() => [Membership.Invite], [])
);
};