mirror of
https://github.com/SableClient/Sable.git
synced 2026-11-20 17:11:17 -08:00
fix(mobile): keep the reaction picker in place when the keyboard opens
This commit is contained in:
15 files changed
+469
-76
No files matched your search
@@ -214,6 +214,54 @@ describe('MobileSwipeDownModal', () => {
|
||||
}
|
||||
});
|
||||
|
||||
it('lifts clear of the keyboard without being asked to', () => {
|
||||
const viewport = mockVisualViewport(800);
|
||||
|
||||
try {
|
||||
setInnerHeight(800);
|
||||
render(
|
||||
<MobileSwipeDownModal requestClose={vi.fn<() => void>()} sheetClassName="default-sheet">
|
||||
{() => <div data-testid="default-content" />}
|
||||
</MobileSwipeDownModal>
|
||||
);
|
||||
|
||||
const panel = screen.getByTestId('default-content').closest('.default-sheet') as HTMLElement;
|
||||
|
||||
viewport.resizeTo(500);
|
||||
|
||||
expect(panel.style.transform).toBe('translate3d(0, -300px, 0)');
|
||||
} finally {
|
||||
viewport.restore();
|
||||
}
|
||||
});
|
||||
|
||||
it('stays put for a sheet that opts out', () => {
|
||||
const viewport = mockVisualViewport(800);
|
||||
|
||||
try {
|
||||
setInnerHeight(800);
|
||||
render(
|
||||
<MobileSwipeDownModal
|
||||
requestClose={vi.fn<() => void>()}
|
||||
keyboardAware={false}
|
||||
sheetClassName="opted-out-sheet"
|
||||
>
|
||||
{() => <div data-testid="opted-out-content" />}
|
||||
</MobileSwipeDownModal>
|
||||
);
|
||||
|
||||
const panel = screen
|
||||
.getByTestId('opted-out-content')
|
||||
.closest('.opted-out-sheet') as HTMLElement;
|
||||
|
||||
viewport.resizeTo(500);
|
||||
|
||||
expect(panel.style.transform).toBe('');
|
||||
} finally {
|
||||
viewport.restore();
|
||||
}
|
||||
});
|
||||
|
||||
it('ignores the transient where only the visual viewport has shrunk', () => {
|
||||
const viewport = mockVisualViewport(807);
|
||||
|
||||
|
||||
@@ -104,7 +104,7 @@ export function MobileSwipeDownModal({
|
||||
skipReturnFocusRef,
|
||||
sheetClassName,
|
||||
sheetStyle,
|
||||
keyboardAware = false,
|
||||
keyboardAware = true,
|
||||
overlayDragHandle = false,
|
||||
}: MobileSwipeDownModalProps) {
|
||||
const sheetRef = useRef<HTMLDivElement>(null);
|
||||
|
||||
@@ -16,6 +16,7 @@ type FocusTrapOptions = NonNullable<ComponentProps<typeof FocusTrap>['focusTrapO
|
||||
|
||||
type ResponsiveMenuProps = {
|
||||
anchor: RectCords | undefined;
|
||||
open?: boolean;
|
||||
requestClose: () => void;
|
||||
menu: ReactNode;
|
||||
/** The element the menu hangs off on desktop. */
|
||||
@@ -135,6 +136,7 @@ function InlineMenuDialog({
|
||||
*/
|
||||
export function ResponsiveMenu({
|
||||
anchor,
|
||||
open,
|
||||
requestClose,
|
||||
menu,
|
||||
children,
|
||||
@@ -149,6 +151,7 @@ export function ResponsiveMenu({
|
||||
overlayDragHandle = false,
|
||||
}: ResponsiveMenuProps) {
|
||||
const isMobile = useCompactLayout();
|
||||
const isOpen = open ?? !!anchor;
|
||||
|
||||
const isKeyForward = (evt: KeyboardEvent) =>
|
||||
evt.key === 'ArrowDown' || (arrowNavigation === 'both' && evt.key === 'ArrowRight');
|
||||
@@ -172,7 +175,7 @@ export function ResponsiveMenu({
|
||||
return (
|
||||
<>
|
||||
{children}
|
||||
{anchor && (
|
||||
{isOpen && anchor && (
|
||||
<InlineMenuDialog
|
||||
anchor={anchor}
|
||||
requestClose={requestClose}
|
||||
@@ -192,12 +195,12 @@ export function ResponsiveMenu({
|
||||
return (
|
||||
<>
|
||||
{children}
|
||||
{anchor && mobile === 'dialog' && (
|
||||
{isOpen && mobile === 'dialog' && (
|
||||
<MenuDialog requestClose={requestClose} focusTrapOptions={focusTrapOptions}>
|
||||
{menu}
|
||||
</MenuDialog>
|
||||
)}
|
||||
{anchor && mobile === 'sheet' && (
|
||||
{isOpen && mobile === 'sheet' && (
|
||||
<MobileSwipeDownModal
|
||||
requestClose={requestClose}
|
||||
sheetStyle={sheetStyle}
|
||||
|
||||
@@ -0,0 +1,82 @@
|
||||
import { render, screen } from '@testing-library/react';
|
||||
import { Provider } from 'jotai';
|
||||
import { createStore } from 'jotai';
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
import type { MatrixEvent, Room } from '$types/matrix-sdk';
|
||||
import { modalAtom, ModalType, pushModalAtom } from '$state/modal';
|
||||
import { GlobalModalManager } from './GlobalModalManager';
|
||||
|
||||
vi.mock('./Options', () => ({
|
||||
MobileOptionsInternal: () => <div data-testid="options-sheet" />,
|
||||
}));
|
||||
vi.mock('./MessageReactionPicker', () => ({
|
||||
MessageReactionPickerInternal: () => <div data-testid="reaction-picker" />,
|
||||
}));
|
||||
vi.mock('./MessageReproxyPicker', () => ({
|
||||
MessageReproxyPickerInternal: () => <div data-testid="reproxy-picker" />,
|
||||
}));
|
||||
vi.mock('./MessageReport', () => ({ MessageReportInternal: () => <div /> }));
|
||||
vi.mock('./MessageDelete', () => ({ MessageDeleteInternal: () => <div /> }));
|
||||
vi.mock('./MessageEditHistory', () => ({ MessageEditHistoryInternal: () => <div /> }));
|
||||
vi.mock('./MessageSource', () => ({ MessageSourceInternal: () => <div /> }));
|
||||
vi.mock('./MessageForward', () => ({ MessageForwardInternal: () => <div /> }));
|
||||
vi.mock('./MessageReactions', () => ({ MessageAllReactionInternal: () => <div /> }));
|
||||
vi.mock('./MessageReadRecipts', () => ({ MessageReadReceiptInternal: () => <div /> }));
|
||||
|
||||
const mEvent = {} as MatrixEvent;
|
||||
const room = {} as Room;
|
||||
|
||||
const openOptions = (store: ReturnType<typeof createStore>) =>
|
||||
store.set(modalAtom, {
|
||||
type: ModalType.MobileOptions,
|
||||
options: { mEvent, room, closeMenu: vi.fn<() => void>(), onReplyClick: vi.fn<() => void>() },
|
||||
});
|
||||
|
||||
const renderWith = (store: ReturnType<typeof createStore>) =>
|
||||
render(
|
||||
<Provider store={store}>
|
||||
<GlobalModalManager />
|
||||
</Provider>
|
||||
);
|
||||
|
||||
describe('GlobalModalManager', () => {
|
||||
it('renders the options sheet on its own', () => {
|
||||
const store = createStore();
|
||||
openOptions(store);
|
||||
|
||||
renderWith(store);
|
||||
|
||||
expect(screen.getByTestId('options-sheet')).toBeTruthy();
|
||||
});
|
||||
|
||||
it('unmounts the options sheet while the reaction picker is over it', () => {
|
||||
const store = createStore();
|
||||
openOptions(store);
|
||||
store.set(pushModalAtom, {
|
||||
type: ModalType.ReactionPicker,
|
||||
mEvent,
|
||||
closeMenu: vi.fn<() => void>(),
|
||||
});
|
||||
|
||||
renderWith(store);
|
||||
|
||||
expect(screen.getByTestId('reaction-picker')).toBeTruthy();
|
||||
expect(screen.queryByTestId('options-sheet')).toBeNull();
|
||||
});
|
||||
|
||||
it('unmounts the options sheet while the persona picker is over it', () => {
|
||||
const store = createStore();
|
||||
openOptions(store);
|
||||
store.set(pushModalAtom, {
|
||||
type: ModalType.ReproxyPicker,
|
||||
room,
|
||||
mEvent,
|
||||
closeMenu: vi.fn<() => void>(),
|
||||
});
|
||||
|
||||
renderWith(store);
|
||||
|
||||
expect(screen.getByTestId('reproxy-picker')).toBeTruthy();
|
||||
expect(screen.queryByTestId('options-sheet')).toBeNull();
|
||||
});
|
||||
});
|
||||
@@ -1,11 +1,10 @@
|
||||
import { useCallback } from 'react';
|
||||
import { useAtom } from 'jotai';
|
||||
import { useAtomValue, useSetAtom } from 'jotai';
|
||||
import { OverlayBackdrop, OverlayCenter, Box, Modal } from 'folds';
|
||||
import { Overlay } from '$components/overlay-stack';
|
||||
import FocusTrap from 'focus-trap-react';
|
||||
import { stopPropagation } from '$utils/keyboard';
|
||||
import { useDismissOnBack } from '$utils/androidBack';
|
||||
import { modalAtom, ModalType } from '$state/modal';
|
||||
import { modalAtom, ModalType, popModalAtom } from '$state/modal';
|
||||
import { MessageReportInternal } from './MessageReport';
|
||||
import { MessageDeleteInternal } from './MessageDelete';
|
||||
import { MessageEditHistoryInternal } from './MessageEditHistory';
|
||||
@@ -14,23 +13,44 @@ import { MessageForwardInternal } from './MessageForward';
|
||||
import { MessageAllReactionInternal } from './MessageReactions';
|
||||
import { MessageReadReceiptInternal } from './MessageReadRecipts';
|
||||
import { MobileOptionsInternal } from './Options';
|
||||
import { MessageReactionPickerInternal } from './MessageReactionPicker';
|
||||
import { MessageReproxyPickerInternal } from './MessageReproxyPicker';
|
||||
|
||||
const OWNS_BACK_HANDLER: ReadonlySet<ModalType> = new Set([
|
||||
ModalType.Forward,
|
||||
ModalType.MobileOptions,
|
||||
ModalType.ReactionPicker,
|
||||
ModalType.ReproxyPicker,
|
||||
]);
|
||||
|
||||
export function GlobalModalManager() {
|
||||
const [modal, setModal] = useAtom(modalAtom);
|
||||
const modal = useAtomValue(modalAtom);
|
||||
const close = useSetAtom(popModalAtom);
|
||||
|
||||
// stable so modals memoizing on it don't rebuild on every room view render
|
||||
const close = useCallback(() => {
|
||||
setModal(null);
|
||||
}, [setModal]);
|
||||
|
||||
// Forward and MobileOptions render their own back handlers via their children.
|
||||
useDismissOnBack(
|
||||
close,
|
||||
!!modal && modal.type !== ModalType.Forward && modal.type !== ModalType.MobileOptions
|
||||
);
|
||||
useDismissOnBack(close, !!modal && !OWNS_BACK_HANDLER.has(modal.type));
|
||||
|
||||
if (!modal) return null;
|
||||
|
||||
if (modal.type === ModalType.ReactionPicker) {
|
||||
return (
|
||||
<MessageReactionPickerInternal
|
||||
mEvent={modal.mEvent}
|
||||
imagePackRooms={modal.imagePackRooms}
|
||||
onReactionToggle={modal.onReactionToggle}
|
||||
closeMenu={modal.closeMenu}
|
||||
/>
|
||||
);
|
||||
}
|
||||
if (modal.type === ModalType.ReproxyPicker) {
|
||||
return (
|
||||
<MessageReproxyPickerInternal
|
||||
room={modal.room}
|
||||
mEvent={modal.mEvent}
|
||||
closeMenu={modal.closeMenu}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
if (modal.type === ModalType.Forward) {
|
||||
return <MessageForwardInternal room={modal.room} mEvent={modal.mEvent} onClose={close} />;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
import { useRef } from 'react';
|
||||
import { useSetAtom } from 'jotai';
|
||||
import type { MatrixEvent, Room } from '$types/matrix-sdk';
|
||||
import { EmojiBoard } from '$components/emoji-board';
|
||||
import { MobileSwipeDownModal } from '$components/MobileSwipeDownModal';
|
||||
import { modalAtom, popModalAtom } from '$state/modal';
|
||||
import * as messageCss from '$features/room/message/styles.css';
|
||||
|
||||
type MessageReactionPickerInternalProps = {
|
||||
mEvent: MatrixEvent;
|
||||
imagePackRooms?: Room[];
|
||||
onReactionToggle?: (targetEventId: string, key: string, shortcode?: string) => void;
|
||||
closeMenu: () => void;
|
||||
};
|
||||
|
||||
export function MessageReactionPickerInternal({
|
||||
mEvent,
|
||||
imagePackRooms,
|
||||
onReactionToggle,
|
||||
closeMenu,
|
||||
}: MessageReactionPickerInternalProps) {
|
||||
const setModal = useSetAtom(modalAtom);
|
||||
const popModal = useSetAtom(popModalAtom);
|
||||
const reactedRef = useRef(false);
|
||||
|
||||
const requestClose = () => {
|
||||
if (!reactedRef.current) {
|
||||
popModal();
|
||||
return;
|
||||
}
|
||||
setModal(null);
|
||||
closeMenu();
|
||||
};
|
||||
|
||||
const react = (key: string, shortcode?: string) => {
|
||||
reactedRef.current = true;
|
||||
onReactionToggle?.(mEvent.getId() ?? '', key, shortcode);
|
||||
};
|
||||
|
||||
return (
|
||||
<MobileSwipeDownModal
|
||||
requestClose={requestClose}
|
||||
focusTrap
|
||||
dialogLabel="Add reaction"
|
||||
sheetClassName={messageCss.MessageMobileOptionsContainerPicker}
|
||||
>
|
||||
{() => (
|
||||
<EmojiBoard
|
||||
sheet
|
||||
isFullWidth
|
||||
allowTextCustomEmoji
|
||||
imagePackRooms={imagePackRooms ?? []}
|
||||
requestClose={requestClose}
|
||||
onEmojiSelect={(key) => react(key)}
|
||||
onCustomEmojiSelect={(mxc, shortcode) => react(mxc, shortcode)}
|
||||
/>
|
||||
)}
|
||||
</MobileSwipeDownModal>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
import { useRef } from 'react';
|
||||
import { useSetAtom } from 'jotai';
|
||||
import type { MatrixEvent, Room, RoomMessageEventContent } from '$types/matrix-sdk';
|
||||
import { useMatrixClient } from '$hooks/useMatrixClient';
|
||||
import { TemporaryPersonaPicker } from '$features/room/persona-picker/PersonaPicker';
|
||||
import type { PerMessageProfileMsc4461 } from '$hooks/usePerMessageProfile';
|
||||
import { buildReplacementPmpContent } from '$features/room/buildReplacementContent';
|
||||
import { modalAtom, popModalAtom } from '$state/modal';
|
||||
|
||||
type MessageReproxyPickerInternalProps = {
|
||||
room: Room;
|
||||
mEvent: MatrixEvent;
|
||||
closeMenu: () => void;
|
||||
};
|
||||
|
||||
export function MessageReproxyPickerInternal({
|
||||
room,
|
||||
mEvent,
|
||||
closeMenu,
|
||||
}: MessageReproxyPickerInternalProps) {
|
||||
const mx = useMatrixClient();
|
||||
const setModal = useSetAtom(modalAtom);
|
||||
const popModal = useSetAtom(popModalAtom);
|
||||
const reproxiedRef = useRef(false);
|
||||
|
||||
const requestClose = () => {
|
||||
if (!reproxiedRef.current) {
|
||||
popModal();
|
||||
return;
|
||||
}
|
||||
setModal(null);
|
||||
closeMenu();
|
||||
};
|
||||
|
||||
const reproxyMessage = async (profile: PerMessageProfileMsc4461 | undefined) => {
|
||||
reproxiedRef.current = true;
|
||||
const content = buildReplacementPmpContent(mEvent.getContent(), mEvent.getId()!, profile);
|
||||
await mx.sendMessage(room.roomId, content as RoomMessageEventContent);
|
||||
requestClose();
|
||||
};
|
||||
|
||||
return (
|
||||
<TemporaryPersonaPicker
|
||||
open
|
||||
mx={mx}
|
||||
onPersonaSelect={reproxyMessage}
|
||||
requestClose={requestClose}
|
||||
/>
|
||||
);
|
||||
}
|
||||
@@ -46,7 +46,7 @@ import { useCallback, useEffect, useLayoutEffect, useState } from 'react';
|
||||
import { MessageDeleteItem } from './MessageDelete';
|
||||
import FocusTrap from 'focus-trap-react';
|
||||
import { stopPropagation } from '$utils/keyboard';
|
||||
import { modalAtom, ModalType } from '$state/modal';
|
||||
import { modalAtom, ModalType, pushModalAtom } from '$state/modal';
|
||||
import { copyToClipboard } from '$utils/dom';
|
||||
import { getMatrixToRoomEvent } from '$plugins/matrix-to';
|
||||
import { getViaServers } from '$plugins/via-servers';
|
||||
@@ -343,8 +343,6 @@ type OptionEmojiMenuProps = {
|
||||
emojiBoardAnchor?: RectCords;
|
||||
imagePackRooms?: Room[];
|
||||
isQuickOptions?: boolean;
|
||||
isModal?: boolean;
|
||||
ActualMessage?: ReactNode;
|
||||
};
|
||||
function OptionsEmojiBoard({
|
||||
mEvent,
|
||||
@@ -354,8 +352,6 @@ function OptionsEmojiBoard({
|
||||
emojiBoardAnchor,
|
||||
imagePackRooms,
|
||||
isQuickOptions,
|
||||
isModal,
|
||||
ActualMessage,
|
||||
}: OptionEmojiMenuProps) {
|
||||
const position =
|
||||
(!isQuickOptions && 'Left') ||
|
||||
@@ -367,15 +363,12 @@ function OptionsEmojiBoard({
|
||||
align={isQuickOptions ? 'End' : 'Start'}
|
||||
offset={undefined}
|
||||
anchor={emojiBoardAnchor}
|
||||
style={isModal ? { width: '100%' } : {}}
|
||||
content={
|
||||
<Menu className={isModal ? css.MessageOptionsMenu : undefined}>
|
||||
{ActualMessage}
|
||||
<Menu>
|
||||
<EmojiBoard
|
||||
imagePackRooms={imagePackRooms ?? []}
|
||||
returnFocusOnDeactivate={false}
|
||||
allowTextCustomEmoji
|
||||
isFullWidth={isModal}
|
||||
onEmojiSelect={(key) => {
|
||||
onReactionToggle?.(mEvent.getId() ?? '', key);
|
||||
setEmojiBoardAnchor?.(undefined);
|
||||
@@ -576,6 +569,14 @@ export function OptionQuickMenu({
|
||||
);
|
||||
}
|
||||
|
||||
const triggerRect = (evt: Parameters<MouseEventHandler<HTMLButtonElement>>[0]): RectCords =>
|
||||
evt.currentTarget.parentElement?.parentElement?.getBoundingClientRect() ?? {
|
||||
x: 0,
|
||||
y: 0,
|
||||
width: 0,
|
||||
height: 0,
|
||||
};
|
||||
|
||||
export type OptionMenuProps = {
|
||||
mEvent: MatrixEvent;
|
||||
room: Room;
|
||||
@@ -603,6 +604,7 @@ export type OptionMenuProps = {
|
||||
setIsEmoji?: Dispatch<SetStateAction<boolean>>;
|
||||
ActualMessage?: ReactNode;
|
||||
isModal?: boolean;
|
||||
closeMessageMenu?: () => void;
|
||||
};
|
||||
|
||||
function OptionMenu({
|
||||
@@ -624,10 +626,12 @@ function OptionMenu({
|
||||
ActualMessage,
|
||||
isModal,
|
||||
isGif,
|
||||
closeMessageMenu,
|
||||
}: OptionMenuProps) {
|
||||
const mobileSheetClose = useMobileSheetClose();
|
||||
const closeMenu = mobileSheetClose ?? requestClose;
|
||||
const setModal = useSetAtom(modalAtom);
|
||||
const pushModal = useSetAtom(pushModalAtom);
|
||||
const store = useStore();
|
||||
const mx = useMatrixClient();
|
||||
const isThreadedMessage = isThreadRelationEvent(mEvent, mEvent.threadRootId);
|
||||
@@ -640,6 +644,8 @@ function OptionMenu({
|
||||
const isEdited = !!edits?.length;
|
||||
const [showPersonaSetting] = useSetting(settingsAtom, 'showPersonaSetting');
|
||||
|
||||
const closeAfterHandOff = closeMessageMenu ?? requestClose;
|
||||
|
||||
const onTotalClose = () => {
|
||||
setModal(null);
|
||||
closeMenu();
|
||||
@@ -655,28 +661,30 @@ function OptionMenu({
|
||||
const [reproxyPickerAnchor, setReproxyPickerAnchor] = useState<RectCords>();
|
||||
|
||||
const handleOpenReproxyPicker: MouseEventHandler<HTMLButtonElement> = (evt) => {
|
||||
const target = isModal
|
||||
? { x: 0, y: innerHeight, width: 0, height: 0 }
|
||||
: (evt.currentTarget.parentElement?.parentElement?.getBoundingClientRect() ?? {
|
||||
x: 0,
|
||||
y: 0,
|
||||
width: 0,
|
||||
height: 0,
|
||||
});
|
||||
setReproxyPickerAnchor(target);
|
||||
if (isModal) {
|
||||
pushModal({
|
||||
type: ModalType.ReproxyPicker,
|
||||
room,
|
||||
mEvent,
|
||||
closeMenu: closeAfterHandOff,
|
||||
});
|
||||
return;
|
||||
}
|
||||
setReproxyPickerAnchor(triggerRect(evt));
|
||||
};
|
||||
|
||||
const handleOpenEmojiBoard: MouseEventHandler<HTMLButtonElement> = (evt) => {
|
||||
// THIS MAGIC NUMBER SHOULD BE FIXED WHEN SOMEONE FIGURES OUT WHY THE LACK OF IT CREATES A GAP IN THE EMOJIBOARD
|
||||
const target = isModal
|
||||
? { x: 0, y: innerHeight + 10, width: 0, height: 0 }
|
||||
: (evt.currentTarget.parentElement?.parentElement?.getBoundingClientRect() ?? {
|
||||
x: 0,
|
||||
y: 0,
|
||||
width: 0,
|
||||
height: 0,
|
||||
});
|
||||
setEmojiBoardAnchor?.(target);
|
||||
if (isModal) {
|
||||
pushModal({
|
||||
type: ModalType.ReactionPicker,
|
||||
mEvent,
|
||||
imagePackRooms,
|
||||
onReactionToggle,
|
||||
closeMenu: closeAfterHandOff,
|
||||
});
|
||||
return;
|
||||
}
|
||||
setEmojiBoardAnchor?.(triggerRect(evt));
|
||||
setIsEmoji?.(true);
|
||||
};
|
||||
|
||||
@@ -690,8 +698,6 @@ function OptionMenu({
|
||||
setEmojiBoardAnchor={setEmojiBoardAnchor}
|
||||
emojiBoardAnchor={emojiBoardAnchor}
|
||||
imagePackRooms={imagePackRooms}
|
||||
isModal={isModal}
|
||||
ActualMessage={<WrappedMessage isModal={isModal} ActualMessage={ActualMessage} />}
|
||||
/>
|
||||
)}
|
||||
{reproxyPickerAnchor !== undefined && (
|
||||
@@ -719,7 +725,7 @@ function OptionMenu({
|
||||
}}
|
||||
>
|
||||
<Menu className={isModal ? css.MessageOptionsSheetMenu : ''}>
|
||||
{ActualMessage && !emojiBoardAnchor && (
|
||||
{ActualMessage && (
|
||||
<>
|
||||
<WrappedMessage isModal={isModal} ActualMessage={ActualMessage} />
|
||||
<Line direction="Horizontal" variant="SurfaceVariant" />
|
||||
@@ -942,6 +948,8 @@ export function MobileOptionsInternal({ options }: { options: OptionMenuProps })
|
||||
canPinEvent={options.canPinEvent}
|
||||
canDelete={options.canDelete}
|
||||
setIsEmoji={options.setIsEmoji}
|
||||
imagePackRooms={options.imagePackRooms}
|
||||
closeMessageMenu={options.closeMenu}
|
||||
ActualMessage={options.ActualMessage}
|
||||
canSendReaction={options.canSendReaction}
|
||||
isModal
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
import { describe, expect, it } from 'vitest';
|
||||
|
||||
const srcDir = path.resolve(__dirname, '../../..');
|
||||
|
||||
function sourceFiles(dir: string): string[] {
|
||||
return fs.readdirSync(dir, { withFileTypes: true }).flatMap((entry) => {
|
||||
const full = path.join(dir, entry.name);
|
||||
if (entry.isDirectory()) return sourceFiles(full);
|
||||
if (!/\.tsx?$/.test(entry.name) || entry.name.includes('.test.')) return [];
|
||||
return [full];
|
||||
});
|
||||
}
|
||||
|
||||
const VIEWPORT_DERIVED_RECT = /\by:\s*(window\.)?innerHeight/;
|
||||
|
||||
describe('popout anchor contract', () => {
|
||||
it('builds every anchor from a measured element', () => {
|
||||
const offenders = sourceFiles(srcDir).filter((file) =>
|
||||
VIEWPORT_DERIVED_RECT.test(fs.readFileSync(file, 'utf8'))
|
||||
);
|
||||
|
||||
expect(offenders.map((file) => path.relative(srcDir, file))).toEqual([]);
|
||||
});
|
||||
});
|
||||
@@ -2457,7 +2457,6 @@ export const RoomInput = forwardRef<HTMLDivElement, RoomInputProps>(
|
||||
focusTrap
|
||||
dialogLabel="Emoji picker"
|
||||
sheetClassName={messageCss.MessageMobileOptionsContainerPicker}
|
||||
keyboardAware
|
||||
skipReturnFocusRef={emojiBoardSkipReturnFocusRef}
|
||||
>
|
||||
{() => emojiBoard}
|
||||
|
||||
@@ -887,6 +887,7 @@ function MessageInternal(
|
||||
canPinEvent: canPinEvent,
|
||||
canDelete: canDelete,
|
||||
setIsEmoji: setIsEmoji,
|
||||
imagePackRooms: imagePackRooms,
|
||||
ActualMessage: (
|
||||
<div style={{ width: '100%' }}>
|
||||
<WrappedMessage
|
||||
|
||||
@@ -52,30 +52,6 @@ const messageOptionsMenuLayout = {
|
||||
flexDirection: 'column',
|
||||
} as const;
|
||||
|
||||
// Portaled out of the sheet by PopOut, so it still draws its own sheet-like surface
|
||||
// and pads for the safe area itself.
|
||||
export const MessageOptionsMenu = style({
|
||||
...messageOptionsMenuLayout,
|
||||
borderBottomLeftRadius: '0 !important',
|
||||
borderBottomRightRadius: '0 !important',
|
||||
borderBottom: 'none !important',
|
||||
borderTopLeftRadius: `${toRem(20)} !important`,
|
||||
borderTopRightRadius: `${toRem(20)} !important`,
|
||||
paddingBottom: `calc(${config.space.S400} + var(--safe-area-inset-bottom, env(safe-area-inset-bottom, 0px))) !important`,
|
||||
selectors: {
|
||||
'&::after': {
|
||||
content: '""',
|
||||
position: 'absolute',
|
||||
top: '100%',
|
||||
left: 0,
|
||||
right: 0,
|
||||
height: '300px',
|
||||
backgroundColor: 'inherit',
|
||||
border: 'none',
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
// Inside the sheet panel, which owns the background, radius, shadow and safe area.
|
||||
export const MessageOptionsSheetMenu = style({
|
||||
...messageOptionsMenuLayout,
|
||||
|
||||
@@ -75,6 +75,7 @@ type TemporaryPersonaPickerProps = {
|
||||
onPersonaSelect: (persona: PerMessageProfileMsc4461 | undefined) => void | Promise<void>;
|
||||
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<RectCords | undefined>(anchor);
|
||||
@@ -529,6 +531,7 @@ export function TemporaryPersonaPicker({
|
||||
return (
|
||||
<ResponsiveMenu
|
||||
anchor={AddPersonaMenuAnchor}
|
||||
open={open}
|
||||
position={'Left'}
|
||||
align="Start"
|
||||
offset={16}
|
||||
|
||||
@@ -0,0 +1,92 @@
|
||||
import { createStore } from 'jotai';
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
import type { MatrixEvent, Room } from '$types/matrix-sdk';
|
||||
import { modalAtom, ModalType, popModalAtom, pushModalAtom } from './modal';
|
||||
import type { ModalState } from './modal';
|
||||
|
||||
const mEvent = {} as MatrixEvent;
|
||||
const room = {} as Room;
|
||||
|
||||
const options: Extract<ModalState, { type: ModalType.MobileOptions }> = {
|
||||
type: ModalType.MobileOptions,
|
||||
options: { mEvent, room, closeMenu: vi.fn<() => void>(), onReplyClick: vi.fn<() => void>() },
|
||||
};
|
||||
|
||||
const picker: Extract<ModalState, { type: ModalType.ReactionPicker }> = {
|
||||
type: ModalType.ReactionPicker,
|
||||
mEvent,
|
||||
closeMenu: vi.fn<() => void>(),
|
||||
};
|
||||
|
||||
const reactions: Extract<ModalState, { type: ModalType.Reactions }> = {
|
||||
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();
|
||||
});
|
||||
});
|
||||
+27
-2
@@ -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<ModalState>(null);
|
||||
const modalStackAtom = atom<NonNullable<ModalState>[]>([]);
|
||||
|
||||
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<ModalState>) => {
|
||||
set(modalStackAtom, [...get(modalStackAtom), next]);
|
||||
});
|
||||
|
||||
export const popModalAtom = atom(null, (get, set) => {
|
||||
set(modalStackAtom, get(modalStackAtom).slice(0, -1));
|
||||
});
|
||||
Reference in new issue
Block a user