Skip to content

Commit

Permalink
⚡️ :: (#28) fixed top and left
Browse files Browse the repository at this point in the history
  • Loading branch information
KJG04 committed Jan 25, 2022
1 parent ea9649a commit 0c2b652
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 9 deletions.
4 changes: 2 additions & 2 deletions functions/src/components/LogicGate/Gates/AND/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ const ANDGate: FC<Gate & { index: number }> = ({ position, index }) => {

const name = names[i] as "input1" | "input2" | "output";

const { offsetTop, offsetLeft } = refs[i];
const { left, top, height, width } = refs[i].getBoundingClientRect();

copyGates[index][name] = {
id: id,
connectNode: null,
position: [offsetLeft, offsetTop],
position: [left + width / 2, top + height / 2],
};
});
}
Expand Down
9 changes: 2 additions & 7 deletions functions/src/components/LogicGate/LogicGate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ const LogicGate = () => {
const onMouseDown = useCallback(
(e: React.MouseEvent<SVGSVGElement>) => {
const mouse: Point = [e.nativeEvent.offsetX, e.nativeEvent.offsetY];

const dots: Dot[] = [];

gates.forEach((value) => {
Expand Down Expand Up @@ -109,8 +108,8 @@ const LogicGate = () => {
return (
<>
<S.Container>
{dots.current.map(([x, y], index) => {
return <S.Dot key={index} style={{ top: `${y}px`, left: `${x}px` }} />;
{gates.map((value, index) => {
return <ANDGate key={value.id} {...{ ...value, index }} />;
})}

<S.PathContainer onMouseDown={onMouseDown} onMouseUp={onMouseUp} onMouseMove={onMouseMove}>
Expand All @@ -131,10 +130,6 @@ const LogicGate = () => {
/>
))}
</S.PathContainer>

{gates.map((value, index) => {
return <ANDGate {...{ ...value, index }} />;
})}
</S.Container>
</>
);
Expand Down

0 comments on commit 0c2b652

Please sign in to comment.