π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Fix reaction sheet activation after long press
Anand Baburajanc0584b0a68d4
diff --git a/web/apps/space/src/components/PostComments.tsx b/web/apps/space/src/components/PostComments.tsxindex b9332f5cb3..7403ec60a6 100644--- a/web/apps/space/src/components/PostComments.tsx+++ b/web/apps/space/src/components/PostComments.tsx@@ -662,6 +662,7 @@ export const PostComments: React.FC<{>();const ignoreMouseAwayUntil = React.useRef(0);const menuPointerTarget = React.useRef<Element | null>(null);+ const reactionsPointerTarget = React.useRef<Element | null>(null);const actionAnchor = React.useMemo(() => {if (action?.type != "menu") return undefined;return {@@ -974,13 +975,14 @@ export const PostComments: React.FC<{}onReact={(emoji) => react(comment, emoji)}onReply={() => replyTo(comment)}- onOpenReactions={() =>+ onOpenReactions={() => {+ reactionsPointerTarget.current = null;setAction({type: "reactions",commentId: comment.commentId,open: true,- })- }+ });+ }}onOpenActions={(anchor, source) => {menuPointerTarget.current = null;ignoreMouseAwayUntil.current =@@ -1388,6 +1390,30 @@ export const PostComments: React.FC<{}><Box+ onPointerDownCapture={(event) => {+ reactionsPointerTarget.current =+ event.target instanceof Element+ ? event.target.closest("button")+ : null;+ }}+ onPointerCancel={() => {+ reactionsPointerTarget.current = null;+ }}+ onClickCapture={(event) => {+ const target =+ event.target instanceof Element+ ? event.target.closest("button")+ : null;+ if (+ event.detail &&+ (!target ||+ target != reactionsPointerTarget.current)+ ) {+ event.preventDefault();+ event.stopPropagation();+ }+ reactionsPointerTarget.current = null;+ }}sx={{position: "absolute",inset: "24px 0 0",diff --git a/web/apps/space/tests/comment-mutations.test.tsx b/web/apps/space/tests/comment-mutations.test.tsxindex 966e32bcaa..1cc57ea30f 100644--- a/web/apps/space/tests/comment-mutations.test.tsx+++ b/web/apps/space/tests/comment-mutations.test.tsx@@ -285,7 +285,7 @@ const commentGesture = (constructor(readonly kind: "body" | "button" | "reaction" = "body") {}closest(selector: string) {return (- selector == "a, button"+ selector.includes("button")? this.kind != "body": this.kind == "reaction")@@ -543,6 +543,64 @@ test("long-pressing still opens comment actions without replying", () => {);});+test("releasing a reaction long press cannot activate the sheet, but a fresh tap can", () => {+ const { pointer, Target } = commentGesture();+ pointer("onPointerDown", 100, 0, { target: new Target("reaction") });+ vi.advanceTimersByTime(520);+ const slide = render().find((node) => node.type == "slide")!;+ expect(slide.props.in).toBe(true);+ const sheet = slide.props.children as Element;+ const event = {+ target: new Target("button"),+ detail: 1,+ preventDefault: vi.fn(),+ stopPropagation: vi.fn(),+ };+ const click = sheet.props.onClickCapture as (event: unknown) => void;+ click(event);+ expect(event.preventDefault).toHaveBeenCalled();+ expect(event.stopPropagation).toHaveBeenCalled();++ event.preventDefault.mockClear();+ event.stopPropagation.mockClear();+ (sheet.props.onPointerDownCapture as (event: unknown) => void)(event);+ click(event);+ expect(event.preventDefault).not.toHaveBeenCalled();+ expect(event.stopPropagation).not.toHaveBeenCalled();+});++test.each(["keyboard", "cancelled", "different control"])(+ "reactions sheet handles %s activation",+ (source) => {+ const { pointer, Target } = commentGesture();+ pointer("onPointerDown", 100, 0, { target: new Target("reaction") });+ vi.advanceTimersByTime(520);+ const sheet = render().find((node) => node.type == "slide")!.props+ .children as Element;+ const event = {+ target: new Target("button"),+ detail: source == "keyboard" ? 0 : 1,+ preventDefault: vi.fn(),+ stopPropagation: vi.fn(),+ };+ if (source != "keyboard") {+ (sheet.props.onPointerDownCapture as (event: unknown) => void)(+ event,+ );+ if (source == "cancelled")+ (sheet.props.onPointerCancel as () => void)();+ else event.target = new Target("button");+ }+ (sheet.props.onClickCapture as (event: unknown) => void)(event);+ expect(event.preventDefault).toHaveBeenCalledTimes(+ source == "keyboard" ? 0 : 1,+ );+ expect(event.stopPropagation).toHaveBeenCalledTimes(+ source == "keyboard" ? 0 : 1,+ );+ },+);+test("replying from the long-press menu focuses the input and preserves the draft", () => {const { pointer, focus } = commentGesture();pointer("onPointerDown", 100);