(
focusTrap
dialogLabel="Emoji picker"
sheetClassName={messageCss.MessageMobileOptionsContainerPicker}
- keyboardAware
skipReturnFocusRef={emojiBoardSkipReturnFocusRef}
>
{() => emojiBoard}
diff --git a/src/app/features/room/message/Message.tsx b/src/app/features/room/message/Message.tsx
index e1e62ee27..d976bd4e5 100644
--- a/src/app/features/room/message/Message.tsx
+++ b/src/app/features/room/message/Message.tsx
@@ -887,6 +887,7 @@ function MessageInternal(
canPinEvent: canPinEvent,
canDelete: canDelete,
setIsEmoji: setIsEmoji,
+ imagePackRooms: imagePackRooms,
ActualMessage: (
void | Promise;
requestClose: () => void;
anchor?: RectCords;
+ open?: boolean;
};
export function useProfiles(
@@ -501,6 +502,7 @@ export function TemporaryPersonaPicker({
mx,
onPersonaSelect,
anchor,
+ open,
requestClose,
}: TemporaryPersonaPickerProps) {
const [AddPersonaMenuAnchor, setAddPersonaMenuAnchor] = useState(anchor);
@@ -529,6 +531,7 @@ export function TemporaryPersonaPicker({
return (
= {
+ type: ModalType.MobileOptions,
+ options: { mEvent, room, closeMenu: vi.fn<() => void>(), onReplyClick: vi.fn<() => void>() },
+};
+
+const picker: Extract = {
+ type: ModalType.ReactionPicker,
+ mEvent,
+ closeMenu: vi.fn<() => void>(),
+};
+
+const reactions: Extract = {
+ type: ModalType.Reactions,
+ room,
+ relations: {} as never,
+};
+
+describe('modalAtom', () => {
+ it('shows nothing until a modal opens', () => {
+ expect(createStore().get(modalAtom)).toBeNull();
+ });
+
+ it('replaces rather than stacks when set directly', () => {
+ const store = createStore();
+
+ store.set(modalAtom, options);
+ store.set(modalAtom, reactions);
+ expect(store.get(modalAtom)).toBe(reactions);
+
+ store.set(popModalAtom);
+ expect(store.get(modalAtom)).toBeNull();
+ });
+
+ it('closes everything when set to null', () => {
+ const store = createStore();
+
+ store.set(modalAtom, options);
+ store.set(pushModalAtom, picker);
+ store.set(modalAtom, null);
+
+ expect(store.get(modalAtom)).toBeNull();
+ });
+});
+
+describe('pushModalAtom', () => {
+ it('shows only the pushed modal, so the one beneath cannot render behind it', () => {
+ const store = createStore();
+
+ store.set(modalAtom, options);
+ store.set(pushModalAtom, picker);
+
+ expect(store.get(modalAtom)).toBe(picker);
+ });
+
+ it('returns to the modal underneath when popped', () => {
+ const store = createStore();
+
+ store.set(modalAtom, options);
+ store.set(pushModalAtom, picker);
+ store.set(popModalAtom);
+
+ expect(store.get(modalAtom)).toBe(options);
+ });
+});
+
+describe('popModalAtom', () => {
+ it('closes a modal that opened on its own', () => {
+ const store = createStore();
+
+ store.set(modalAtom, reactions);
+ store.set(popModalAtom);
+
+ expect(store.get(modalAtom)).toBeNull();
+ });
+
+ it('does nothing when no modal is open', () => {
+ const store = createStore();
+
+ store.set(popModalAtom);
+
+ expect(store.get(modalAtom)).toBeNull();
+ });
+});
diff --git a/src/app/state/modal.ts b/src/app/state/modal.ts
index e6399a686..ea4586e1f 100644
--- a/src/app/state/modal.ts
+++ b/src/app/state/modal.ts
@@ -4,6 +4,8 @@ import type { OptionMenuProps } from '$components/message/modals/Options';
export enum ModalType {
MobileOptions = 'mobile_options',
+ ReactionPicker = 'reaction_picker',
+ ReproxyPicker = 'reproxy_picker',
Delete = 'delete',
// for forwarding a message to another room, not to be confused with the "share" action which is for sharing a message to another app
Forward = 'forward',
@@ -14,8 +16,16 @@ export enum ModalType {
ReadReceipts = 'read_receipts',
}
-type ModalState =
+export type ModalState =
| { type: ModalType.MobileOptions; options: OptionMenuProps }
+ | {
+ type: ModalType.ReactionPicker;
+ mEvent: MatrixEvent;
+ imagePackRooms?: Room[];
+ onReactionToggle?: (targetEventId: string, key: string, shortcode?: string) => void;
+ closeMenu: () => void;
+ }
+ | { type: ModalType.ReproxyPicker; room: Room; mEvent: MatrixEvent; closeMenu: () => void }
| { type: ModalType.Delete; room: Room; mEvent: MatrixEvent }
| { type: ModalType.Forward; room: Room; mEvent: MatrixEvent }
| { type: ModalType.Report; room: Room; mEvent: MatrixEvent }
@@ -25,4 +35,19 @@ type ModalState =
| { type: ModalType.ReadReceipts; room: Room; eventId: string }
| null;
-export const modalAtom = atom(null);
+const modalStackAtom = atom[]>([]);
+
+export const modalAtom = atom(
+ (get) => get(modalStackAtom).at(-1) ?? null,
+ (_get, set, next: ModalState) => {
+ set(modalStackAtom, next ? [next] : []);
+ }
+);
+
+export const pushModalAtom = atom(null, (get, set, next: NonNullable) => {
+ set(modalStackAtom, [...get(modalStackAtom), next]);
+});
+
+export const popModalAtom = atom(null, (get, set) => {
+ set(modalStackAtom, get(modalStackAtom).slice(0, -1));
+});