Skip to content

Commit

Permalink
bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
daoauth committed Jan 13, 2025
1 parent f1b8007 commit d846d8a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 19 deletions.
17 changes: 1 addition & 16 deletions packages/ptb-builder/src/ptbFlow/components/CmdParamsVector.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import React, { useEffect, useState } from 'react';

import { useUpdateNodeInternals } from '@xyflow/react';

import { useStateContext } from '../../provider';
import { PtbHandle, PtbHandleArray, PtbHandleVector } from '../nodes/handles';
import { ButtonStyles, InputStyle } from '../nodes/styles';
Expand All @@ -17,7 +15,6 @@ const YStart = 74;
const YGap = 24;

interface CmdParamsVectorProps {
id: string;
data: PTBNodeData;
resetEdge: (handle: 'source' | 'target') => void;
updateState: (type: TYPE_PARAMS, omit: boolean, splitInputs?: number) => void;
Expand All @@ -37,13 +34,11 @@ const PARAMS: TYPE_PARAMS[] = [
];

export const CmdParamsVector = ({
id,
data,
resetEdge,
updateState,
}: CmdParamsVectorProps) => {
const { canEdit } = useStateContext();
const updateNodeInternals = useUpdateNodeInternals();

const [isSplitInputs, setIsSplitInputs] = useState<boolean>(
!!data.splitInputs || false,
Expand Down Expand Up @@ -84,7 +79,6 @@ export const CmdParamsVector = ({
resetEdge('target');
setInputs((old) => old.slice(0, -1));
updateState(type, omit, inputs.length - 1);
updateNodeInternals(id);
}
};

Expand All @@ -93,15 +87,6 @@ export const CmdParamsVector = ({
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

const handleResetEdge = (handle: 'source' | 'target') => {
resetEdge(handle);
updateNodeInternals(id);
};

useEffect(() => {
updateNodeInternals(id);
}, [id, updateNodeInternals]);

return (
<>
<div className="flex items-center gap-2">
Expand Down Expand Up @@ -146,7 +131,7 @@ export const CmdParamsVector = ({
onChange={(e) => {
setIsSplitInputs(e.target.checked);
handleAdd(e.target.checked);
handleResetEdge('target');
resetEdge('target');
}}
/>
</>
Expand Down
12 changes: 9 additions & 3 deletions packages/ptb-builder/src/ptbFlow/nodes/commands/MakeMoveVec.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import React, { useEffect } from 'react';

import { useReactFlow } from '@xyflow/react';
import { useReactFlow, useUpdateNodeInternals } from '@xyflow/react';

import { PTBNodeProp } from '..';
import { CmdParamsVector } from '../../components';
Expand All @@ -10,6 +10,7 @@ import { TYPE_PARAMS } from '../types';

export const MakeMoveVec = ({ id, data }: PTBNodeProp) => {
const { setEdges, setNodes } = useReactFlow();
const updateNodeInternals = useUpdateNodeInternals();

const resetEdge = (handle: 'source' | 'target') => {
setEdges((eds) =>
Expand All @@ -22,8 +23,13 @@ export const MakeMoveVec = ({ id, data }: PTBNodeProp) => {
),
),
);
updateNodeInternals(id);
};

useEffect(() => {
updateNodeInternals(id);
}, [id, updateNodeInternals]);

return (
<div className={NodeStyles.command}>
<p className="text-base text-center text-gray-700 dark:text-gray-400">
Expand All @@ -42,7 +48,6 @@ export const MakeMoveVec = ({ id, data }: PTBNodeProp) => {
}}
/>
<CmdParamsVector
id={id}
data={data}
resetEdge={resetEdge}
updateState={(
Expand All @@ -65,6 +70,7 @@ export const MakeMoveVec = ({ id, data }: PTBNodeProp) => {
return node;
}),
);
updateNodeInternals(id);
}}
/>
</div>
Expand Down

0 comments on commit d846d8a

Please sign in to comment.