From 1bb2772ee619e29ebd800192eb3df69dc0f38205 Mon Sep 17 00:00:00 2001 From: bobzel Date: Wed, 15 Jun 2022 21:07:19 -0400 Subject: added contextMenus to dashboards in dashboardView --- src/client/views/DashboardView.tsx | 52 ++++++++++++++++++++++++++------------ 1 file changed, 36 insertions(+), 16 deletions(-) (limited to 'src') diff --git a/src/client/views/DashboardView.tsx b/src/client/views/DashboardView.tsx index 027cfd376..d24cde149 100644 --- a/src/client/views/DashboardView.tsx +++ b/src/client/views/DashboardView.tsx @@ -66,6 +66,35 @@ export class DashboardView extends React.Component { ; } + + _downX: number = 0; + _downY: number = 0; + @action + onContextMenu = (e?: React.MouseEvent, pageX?: number, pageY?: number) => { + // the touch onContextMenu is button 0, the pointer onContextMenu is button 2 + if (e) { + e.preventDefault(); + e.stopPropagation(); + e.persist(); + + if (!navigator.userAgent.includes("Mozilla") && (Math.abs(this._downX - e?.clientX) > 3 || Math.abs(this._downY - e?.clientY) > 3)) { + return; + } + const cm = ContextMenu.Instance; + cm.addItem({ + description: "Share Dashboard", event: async () => { + // ... + }, icon: "edit" + }); + cm.addItem({ + description: "Delete Dashboard", event: async () => { + // ... + }, icon: "trash" + }); + cm.displayMenu((e?.pageX || pageX || 0) - 15, (e?.pageY || pageY || 0) - 15); + } + } + render() { return <> @@ -78,25 +107,16 @@ export class DashboardView extends React.Component {
{this.getDashboards().map((dashboard) => { const href = ImageCast((dashboard.thumb as Doc)?.data)?.url.href; - return
this.clickDashboard(e, dashboard)}> + return
this.clickDashboard(e, dashboard)}>
{StrCast(dashboard.title)}
-
{ - const dashView = DocumentManager.Instance.getDocumentView(dashboard); - console.log(dashView) - ContextMenu.Instance.addItem({ - description: "Share Dashboard", event: async () => { - // ... - }, icon: "edit" - }); - ContextMenu.Instance.addItem({ - description: "Delete Dashboard", event: async () => { - // ... - }, icon: "trash" - }); - dashView?.showContextMenu(e.clientX + 20, e.clientY + 30); - }}> +
{ + this._downX = e.clientX; + this._downY = e.clientY; + }} onClick={this.onContextMenu}>
-- cgit v1.2.3-70-g09d2