Skip to content

Commit

Permalink
Merge branch 'max/feedback'
Browse files Browse the repository at this point in the history
  • Loading branch information
0xd22f9c committed Sep 16, 2024
2 parents b9f10a0 + 360efea commit 4fdfff5
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 28 deletions.
32 changes: 11 additions & 21 deletions src/modules/blockchains/Buy/hooks/useCheckEdges.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,29 @@ import useOrderFormStoreV3 from '@/modules/blockchains/Buy/stores/index_v3';
import useFlowStore from '@/modules/blockchains/Buy/stores/useFlowStore';
import React from 'react';
import { needReactFlowRenderSignal } from '../studio/ReactFlowRender';
import { removeItemAtIndex } from '@/modules/blockchains/dapp/utils';

const useCheckEdges = () => {
const { field } = useOrderFormStoreV3();
const { nodes, setNodes, edges, setEdges } = useFlowStore();
const { nodes, setNodes, edges, setEdges, removedNode, setRemovedNode } = useFlowStore();

const checkEdges = () => {
const blockchainNodeIndex = nodes.findIndex(
(node) => node.id === 'blockchain',
);
const blockchainNode = nodes[blockchainNodeIndex];
const indexEdgeRemoved = edges.findIndex(edge => edge.target === removedNode?.id ||edge.source === removedNode?.id);
console.log('indexEdgeRemoved', indexEdgeRemoved);
if(indexEdgeRemoved === -1) return;

if (!blockchainNode) return;

const sourceHandles = blockchainNode.data.sourceHandles;
const edgesData = edges.filter((edge) => edge.source === 'blockchain');

const newSourceHandles = sourceHandles.filter((sourceHandle) => {
const edgeIndex = edgesData.findIndex(
(edge) => edge.sourceHandle === sourceHandle,
);

return edgeIndex !== -1;
});

blockchainNode.data.sourceHandles = newSourceHandles;

setNodes([...nodes]);
setEdges(removeItemAtIndex(edges, indexEdgeRemoved));
setRemovedNode(null)
needReactFlowRenderSignal.value = true;
};

React.useEffect(() => {
console.log('runmnnn here');
if(removedNode === null) return;
checkEdges();
}, [nodes.length]);
}, [removedNode]);

};

export default useCheckEdges;
12 changes: 11 additions & 1 deletion src/modules/blockchains/Buy/hooks/useHandleDragging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import useOverlappingChainLegoStore from '../stores/useOverlappingChainLegoStore

export default function useHandleDragging() {
const { setOverlappingId } = useOverlappingChainLegoStore();
const { nodes, setNodes, edges, setEdges } = useFlowStore();
const { nodes, setNodes, edges, setEdges, setRemovedNode } = useFlowStore();
const {
setIdDragging,
rightDragging,
Expand Down Expand Up @@ -297,6 +297,8 @@ export default function useHandleDragging() {
index,
);
}
console.log('nodessssss', nodes[ index + 1 + totalTemplateDapps]);
setRemovedNode(nodes[ index + 1 + totalTemplateDapps])
setNodes(removeItemAtIndex(nodes, index + 1 + totalTemplateDapps));
}

Expand All @@ -313,6 +315,8 @@ export default function useHandleDragging() {
index,
);
}
console.log('nodessssss1', nodes[ index + 1 + totalTemplateDapps]);
setRemovedNode(nodes[ index + 1 + totalTemplateDapps])
setNodes(removeItemAtIndex(nodes, index + 1 + totalTemplateDapps));
}

Expand Down Expand Up @@ -404,6 +408,8 @@ export default function useHandleDragging() {
draggedIds2DSignal.value,
index,
);
console.log('nodessssss2', nodes[ index + 1 + totalTemplateDapps]);
setRemovedNode(nodes[ index + 1 + totalTemplateDapps])
setNodes(removeItemAtIndex(nodes, index + 1 + totalTemplateDapps));
}
}
Expand All @@ -420,6 +426,8 @@ export default function useHandleDragging() {
draggedIds2DSignal.value,
index,
);
console.log('nodessssss3', nodes[ index + 1 + totalTemplateDapps]);
setRemovedNode(nodes[ index + 1 + totalTemplateDapps])
setNodes(removeItemAtIndex(nodes, index + 1 + totalTemplateDapps));
}
}
Expand Down Expand Up @@ -1123,6 +1131,8 @@ export default function useHandleDragging() {
totalTemplateDapps,
});
const rootNode = 'blockchain';
console.log('nodessssss', nodes[removeIndex]);
setRemovedNode(nodes[removeIndex])

let newNodes = removeItemAtIndex(nodes, removeIndex);
let getHandleNodeBlockChain = nodes.find(
Expand Down
4 changes: 1 addition & 3 deletions src/modules/blockchains/Buy/hooks/useNodeFlowControl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,6 @@ export default function useNodeFlowControl() {
// sourceHandles: [],
},
};

setNodes([...nodesData, newNode]);
setEdges([
...edges,
Expand Down Expand Up @@ -450,12 +449,11 @@ export default function useNodeFlowControl() {
// sourceHandles: [],
},
};

console.log('statusMapping', statusMapping);
setNodes([...nodesData, newNode]);
setEdges([
...edges,
{
// id: `${edges.length + 1}`,
id: `${Math.random()}`,
source: rootNode,
sourceHandle: `${rootNode}-s-${suffix}`,
Expand Down
4 changes: 2 additions & 2 deletions src/modules/blockchains/Buy/index_v8.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import useOnlyFetchDapp from './hooks/useOnlyFetchDapp';
import useSetDefaultDapp from './hooks/useSetDefaultDapp';
import s from './styles_v6.module.scss';
import useLineIssueToken from '@/modules/blockchains/Buy/hooks/useLineIssueToken';
import useCheckEdges from '@/modules/blockchains/Buy/hooks/useCheckEdges';

const BuyPage = () => {
const { handleDragStart, handleDragEnd, sensors } = useHandleDragging();
Expand All @@ -31,8 +32,7 @@ const BuyPage = () => {
useGettingDappLego();
useCheckNodes();
useSetDefaultDapp();

// useCheckEdges();
useCheckEdges();

const { tabActive } = useTabs((state) => state);
const isTabCode = React.useMemo(() => {
Expand Down
6 changes: 6 additions & 0 deletions src/modules/blockchains/Buy/stores/useFlowStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ export type AppState = {
onConnect: OnConnect;
setNodes: (nodes: AppNode[]) => void;
setEdges: (edges: Edge[]) => void;
removedNode: AppNode | null;
setRemovedNode: (node: AppNode | null) => void;
};

const useFlowStore = create<AppState>((set, get) => ({
Expand All @@ -47,6 +49,10 @@ const useFlowStore = create<AppState>((set, get) => ({
setEdges: (edges) => {
set({ edges });
},
removedNode: null,
setRemovedNode: (node) => {
set({ removedNode: node });
},
}));

export default useFlowStore;
3 changes: 2 additions & 1 deletion src/utils/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ function handleStatusEdgeByBox(status: any) {
switch (status) {
case 'draft':
case 'setting_up':
case 'Drafting Modules':
case EAirdropStatus.new:
case '':
//draft
Expand Down Expand Up @@ -291,7 +292,7 @@ function handleStatusEdgeByBox(status: any) {

export default function handleStatusEdges(statusDapp: any, status: aa | string, idNode: string) {
if (idNode === 'account_abstraction' || idNode === 'bridge_apps' || idNode === 'gaming_apps') {
console.log('status here', status);
console.log('status here', status, idNode);
return handleStatusEdgeByBox(status);
}

Expand Down

0 comments on commit 4fdfff5

Please sign in to comment.