Skip to content

Commit

Permalink
Remove StickyNotePreview from ComponentPreview
Browse files Browse the repository at this point in the history
  • Loading branch information
philemone committed Dec 10, 2024
1 parent b86157d commit c76fbc4
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 19 deletions.
35 changes: 21 additions & 14 deletions designer/client/src/components/ComponentDragPreview.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { css } from "@emotion/css";
import React, { forwardRef, useEffect, useMemo, useState } from "react";
import React, { forwardRef, ReactPortal, useEffect, useMemo, useState } from "react";
import { useDragDropManager, useDragLayer } from "react-dnd";
import { createPortal } from "react-dom";
import { useDebouncedValue } from "rooks";
import { NodeType } from "../types";
import { ComponentPreview } from "./ComponentPreview";
import { DndTypes } from "./toolbars/creator/Tool";
import { StickyNotePreview } from "./StickyNotePreview";
import { StickyNoteType } from "../types/stickyNote";

function useNotNull<T>(value: T) {
const [current, setCurrent] = useState(() => value);
Expand Down Expand Up @@ -53,17 +55,22 @@ export const ComponentDragPreview = forwardRef<HTMLDivElement, { scale: () => nu
return null;
}

return createPortal(
<div ref={forwardedRef} className={wrapperStyles} style={{ transform: `translate(${x}px, ${y}px)` }}>
<div
style={{
transformOrigin: "top left",
transform: `scale(${scale()})`,
}}
>
<ComponentPreview node={node} isActive={active} isOver={isOver} />
</div>
</div>,
document.body,
);
function createPortalForPreview(child: JSX.Element): ReactPortal {
return createPortal(
<div ref={forwardedRef} className={wrapperStyles} style={{ transform: `translate(${x}px, ${y}px)` }}>
<div
style={{
transformOrigin: "top left",
transform: `scale(${scale()})`,
}}
>
{child}
</div>
</div>,
document.body,
);
}

if (node?.type === StickyNoteType) return createPortalForPreview(<StickyNotePreview isActive={active} isOver={isOver} />);
return createPortalForPreview(<ComponentPreview node={node} isActive={active} isOver={isOver} />);
});
6 changes: 1 addition & 5 deletions designer/client/src/components/ComponentPreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import { ComponentIcon } from "./toolbars/creator/ComponentIcon";
import { alpha, styled, useTheme } from "@mui/material";
import { blend } from "@mui/system";
import { blendLighten, getBorderColor } from "../containers/theme/helpers";
import { StickyNotePreview } from "./StickyNotePreview";
import { StickyNoteType } from "../types/stickyNote";

export function ComponentPreview({ node, isActive, isOver }: { node: NodeType; isActive?: boolean; isOver?: boolean }): JSX.Element {
const theme = useTheme();
Expand Down Expand Up @@ -77,9 +75,7 @@ export function ComponentPreview({ node, isActive, isOver }: { node: NodeType; i

const colors = isOver ? nodeColorsHover : nodeColors;

return node?.type === StickyNoteType ? (
<StickyNotePreview isActive={isActive} isOver={isOver} />
) : (
return (
<div className={cx(colors, nodeStyles)}>
<div className={cx(imageStyles, imageColors)}>
<ComponentIcon node={node} />
Expand Down

0 comments on commit c76fbc4

Please sign in to comment.