From 4c7c518d4da9ef7b14a172d48e9887f1449596f0 Mon Sep 17 00:00:00 2001
From: Lim Chee Aun <cheeaun@gmail.com>
Date: Sat, 16 Dec 2023 14:10:33 +0800
Subject: [PATCH] Disable context menu inside notifications popover

Popovers over popovers ain't easy
---
 src/components/notification.jsx | 39 ++++++++++++++++++++-------------
 src/pages/home.jsx              |  1 +
 2 files changed, 25 insertions(+), 15 deletions(-)

diff --git a/src/components/notification.jsx b/src/components/notification.jsx
index 823d9f43..a4120ace 100644
--- a/src/components/notification.jsx
+++ b/src/components/notification.jsx
@@ -67,7 +67,12 @@ const contentText = {
 
 const AVATARS_LIMIT = 50;
 
-function Notification({ notification, instance, isStatic }) {
+function Notification({
+  notification,
+  instance,
+  isStatic,
+  disableContextMenu,
+}) {
   const { id, status, account, report, _accounts, _statuses } = notification;
   let { type } = notification;
 
@@ -300,20 +305,24 @@ function Notification({ notification, instance, isStatic }) {
                 ? `/${instance}/s/${actualStatusID}`
                 : `/s/${actualStatusID}`
             }
-            onContextMenu={(e) => {
-              const post = e.target.querySelector('.status');
-              if (post) {
-                // Fire a custom event to open the context menu
-                if (e.metaKey) return;
-                e.preventDefault();
-                post.dispatchEvent(
-                  new MouseEvent('contextmenu', {
-                    clientX: e.clientX,
-                    clientY: e.clientY,
-                  }),
-                );
-              }
-            }}
+            onContextMenu={
+              !disableContextMenu
+                ? (e) => {
+                    const post = e.target.querySelector('.status');
+                    if (post) {
+                      // Fire a custom event to open the context menu
+                      if (e.metaKey) return;
+                      e.preventDefault();
+                      post.dispatchEvent(
+                        new MouseEvent('contextmenu', {
+                          clientX: e.clientX,
+                          clientY: e.clientY,
+                        }),
+                      );
+                    }
+                  }
+                : undefined
+            }
           >
             {isStatic ? (
               <Status status={actualStatus} size="s" />
diff --git a/src/pages/home.jsx b/src/pages/home.jsx
index fe4503cd..621500ac 100644
--- a/src/pages/home.jsx
+++ b/src/pages/home.jsx
@@ -179,6 +179,7 @@ function NotificationsMenu({ anchorRef, state, onClose }) {
                   key={notification.id}
                   instance={instance}
                   notification={notification}
+                  disableContextMenu
                 />
               ))}
           </>