From f82d4821f913bb2981ac8de4a2a2f2b3ed38ed20 Mon Sep 17 00:00:00 2001
From: asharonbaltazar <58940073+asharonbaltazar@users.noreply.github.com>
Date: Mon, 22 May 2023 15:48:25 -0400
Subject: [PATCH] Context Menu Feature (#410)
* create `ContextMenuContext` component
---
apps/client/src/App.tsx | 23 +++---
.../context/ContextMenuContext.module.scss | 9 +++
.../src/common/context/ContextMenuContext.tsx | 76 +++++++++++++++++++
.../src/common/hooks/useContextMenu.tsx | 23 ++++++
.../rundown/event-block/EventBlock.tsx | 13 +++-
5 files changed, 133 insertions(+), 11 deletions(-)
create mode 100644 apps/client/src/common/context/ContextMenuContext.module.scss
create mode 100644 apps/client/src/common/context/ContextMenuContext.tsx
create mode 100644 apps/client/src/common/hooks/useContextMenu.tsx
diff --git a/apps/client/src/App.tsx b/apps/client/src/App.tsx
index e2b8b247d..e2aa429b9 100644
--- a/apps/client/src/App.tsx
+++ b/apps/client/src/App.tsx
@@ -6,6 +6,7 @@ import { ReactQueryDevtools } from '@tanstack/react-query-devtools';
import ErrorBoundary from './common/components/error-boundary/ErrorBoundary';
import { AppContextProvider } from './common/context/AppContext';
+import { ContextMenuProvider } from './common/context/ContextMenuContext';
import useElectronEvent from './common/hooks/useElectronEvent';
import { ontimeQueryClient } from './common/queryClient';
import { connectSocket } from './common/utils/socket';
@@ -49,16 +50,18 @@ function App() {
-
-
-
+
+
+
+
+
diff --git a/apps/client/src/common/context/ContextMenuContext.module.scss b/apps/client/src/common/context/ContextMenuContext.module.scss
new file mode 100644
index 000000000..e9cca7c35
--- /dev/null
+++ b/apps/client/src/common/context/ContextMenuContext.module.scss
@@ -0,0 +1,9 @@
+.contextMenuButton {
+ position: absolute;
+ cursor: pointer;
+}
+
+.contextMenuBackdrop {
+ position: fixed;
+ inset: 0;
+}
diff --git a/apps/client/src/common/context/ContextMenuContext.tsx b/apps/client/src/common/context/ContextMenuContext.tsx
new file mode 100644
index 000000000..2504c332e
--- /dev/null
+++ b/apps/client/src/common/context/ContextMenuContext.tsx
@@ -0,0 +1,76 @@
+// logic (with some modifications) culled from:
+// https://github.com/lukasbach/chakra-ui-contextmenu/blob/main/src/ContextMenu.tsx
+
+import { createContext, ReactNode, useState } from 'react';
+import { Menu, MenuButton, MenuItem, MenuList } from '@chakra-ui/react';
+import { IconType } from '@react-icons/all-files';
+
+import style from './ContextMenuContext.module.scss';
+
+type ContextMenuCoords = {
+ x: number;
+ y: number;
+};
+
+type ContextMenuContextType = {
+ createContextMenu: (options: Option[], menuCoordinates: ContextMenuCoords) => void;
+};
+
+export const ContextMenuContext = createContext(null);
+
+export type Option = {
+ label: string;
+ icon: IconType;
+ onClick: () => void;
+};
+
+interface ContextMenuProviderProps {
+ children: ReactNode;
+}
+
+export const ContextMenuProvider = ({ children }: ContextMenuProviderProps) => {
+ const [isOpen, setIsOpen] = useState(false);
+
+ const [coords, setCoords] = useState({ x: 0, y: 0 });
+ const [options, setOptions] = useState