From 5d5acd4a417816a663211582299b664608120c09 Mon Sep 17 00:00:00 2001 From: Hebi Li Date: Thu, 4 May 2023 14:48:39 -0700 Subject: [PATCH 1/3] add new pod buttons --- ui/src/components/nodes/Code.tsx | 161 ++++++++++++++++++++++++++++++- 1 file changed, 160 insertions(+), 1 deletion(-) diff --git a/ui/src/components/nodes/Code.tsx b/ui/src/components/nodes/Code.tsx index a9db7e6f..9c75907a 100644 --- a/ui/src/components/nodes/Code.tsx +++ b/ui/src/components/nodes/Code.tsx @@ -359,6 +359,163 @@ function MyFloatingToolbar({ id, layout, setLayout }) { ); } +function NewPodButtons({ pod, xPos, yPos }) { + const store = useContext(RepoContext); + if (!store) throw new Error("Missing BearContext.Provider in the tree"); + const addNode = useStore(store, (state) => state.addNode); + return ( + <> + {/* Bottom 1 */} + + + {/* Bottom 2 */} + + {/* Left 1 */} + + + {/* Left 2 */} + + + {/* Right 1 */} + + + {/* Right 2 */} + + + ); +} + export const CodeNode = memo(function ({ data, id, @@ -536,6 +693,8 @@ export const CodeNode = memo(function ({ /> + + {/* The header of code pods. */} {devMode && ( @@ -549,7 +708,7 @@ export const CodeNode = memo(function ({ className="nodrag" > {id} at ({Math.round(xPos)}, {Math.round(yPos)}, w:{" "} - {pod.width}, h: {pod.height}) + {pod.width}, h: {pod.height}), parent: {pod.parent} )} Date: Thu, 4 May 2023 14:52:19 -0700 Subject: [PATCH 2/3] add both code and note --- ui/src/components/nodes/Code.tsx | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/ui/src/components/nodes/Code.tsx b/ui/src/components/nodes/Code.tsx index 9c75907a..b5e3ee96 100644 --- a/ui/src/components/nodes/Code.tsx +++ b/ui/src/components/nodes/Code.tsx @@ -387,7 +387,7 @@ function NewPodButtons({ pod, xPos, yPos }) { addNode("CODE", { x: xPos, y: yPos + pod!.height! + 50 }, pod.parent); }} > - + New Pod + + Code {/* Bottom 2 */} @@ -408,10 +408,10 @@ function NewPodButtons({ pod, xPos, yPos }) { }, }} onClick={() => { - addNode("CODE", { x: xPos, y: yPos + pod!.height! + 50 }, pod.parent); + addNode("RICH", { x: xPos, y: yPos + pod!.height! + 50 }, pod.parent); }} > - + New Pod + + Note {/* Left 1 */} {/* Left 2 */} @@ -457,10 +457,10 @@ function NewPodButtons({ pod, xPos, yPos }) { }, }} onClick={() => { - addNode("CODE", { x: xPos - pod!.width! - 50, y: yPos }, pod.parent); + addNode("RICH", { x: xPos - pod!.width! - 50, y: yPos }, pod.parent); }} > - + New Pod + + Note {/* Right 1 */} @@ -485,7 +485,7 @@ function NewPodButtons({ pod, xPos, yPos }) { addNode("CODE", { x: xPos + pod!.width! + 50, y: yPos }, pod.parent); }} > - + New Pod + + Code {/* Right 2 */} @@ -507,10 +507,10 @@ function NewPodButtons({ pod, xPos, yPos }) { }, }} onClick={() => { - addNode("CODE", { x: xPos + pod!.width! + 50, y: yPos }, pod.parent); + addNode("RICH", { x: xPos + pod!.width! + 50, y: yPos }, pod.parent); }} > - + New Pod + + Note ); From 4940035c4b5cda12dcac1460cb117fa39b95d52b Mon Sep 17 00:00:00 2001 From: Hebi Li Date: Thu, 4 May 2023 14:57:11 -0700 Subject: [PATCH 3/3] add create pod buttons to rich-text pod as well --- ui/src/components/nodes/Code.tsx | 159 +--------------------------- ui/src/components/nodes/Rich.tsx | 2 + ui/src/components/nodes/utils.tsx | 165 ++++++++++++++++++++++++++++++ 3 files changed, 168 insertions(+), 158 deletions(-) diff --git a/ui/src/components/nodes/Code.tsx b/ui/src/components/nodes/Code.tsx index b5e3ee96..986cbb0a 100644 --- a/ui/src/components/nodes/Code.tsx +++ b/ui/src/components/nodes/Code.tsx @@ -59,7 +59,7 @@ import { useApolloClient } from "@apollo/client"; import { NodeResizeControl, NodeResizer } from "reactflow"; import "@reactflow/node-resizer/dist/style.css"; -import { ResizeIcon } from "./utils"; +import { NewPodButtons, ResizeIcon } from "./utils"; export const ResultBlock = memo(function ResultBlock({ id }) { const store = useContext(RepoContext)!; @@ -359,163 +359,6 @@ function MyFloatingToolbar({ id, layout, setLayout }) { ); } -function NewPodButtons({ pod, xPos, yPos }) { - const store = useContext(RepoContext); - if (!store) throw new Error("Missing BearContext.Provider in the tree"); - const addNode = useStore(store, (state) => state.addNode); - return ( - <> - {/* Bottom 1 */} - - - {/* Bottom 2 */} - - {/* Left 1 */} - - - {/* Left 2 */} - - - {/* Right 1 */} - - - {/* Right 2 */} - - - ); -} - export const CodeNode = memo(function ({ data, id, diff --git a/ui/src/components/nodes/Rich.tsx b/ui/src/components/nodes/Rich.tsx index d22b0deb..343f920f 100644 --- a/ui/src/components/nodes/Rich.tsx +++ b/ui/src/components/nodes/Rich.tsx @@ -108,6 +108,7 @@ import { ProsemirrorPlugin, cx, htmlToProsemirrorNode } from "remirror"; import { styled } from "@mui/material"; import { MyYjsExtension } from "./YjsRemirror"; +import { NewPodButtons } from "./utils"; function useLinkShortcut() { const [linkShortcut, setLinkShortcut] = useState< @@ -808,6 +809,7 @@ export const RichNode = memo(function ({ isConnectable={isConnectable} /> + {devMode && ( state.addNode); + return ( + <> + {/* Bottom 1 */} + + + {/* Bottom 2 */} + + {/* Left 1 */} + + + {/* Left 2 */} + + + {/* Right 1 */} + + + {/* Right 2 */} + + + ); +}