Skip to content

Commit

Permalink
animar node clicado
Browse files Browse the repository at this point in the history
  • Loading branch information
Piemontez committed May 21, 2024
1 parent 151ad8c commit a1bd689
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
26 changes: 24 additions & 2 deletions src/core/contexts/NodeStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import nodeStoreToJson from '../utils/nodeStoreToJson';
import { CustomNodeType } from '../types/custom-node-type';
import { useNotificationStore } from '../../ide/components/Notification/store';
import { create } from 'zustand';
import { STORAGE_NODESTORE_ID } from '../../ide/commons/consts';
import { EDGE_IN_COLOR, EDGE_OUT_COLOR, STORAGE_NODESTORE_ID } from '../../ide/commons/consts';
import { useRunnerStore } from './RunnerStore';

const uuidv5Hash = 'c54ab9bc-e083-56f2-9d1e-3eec4bcc93ad';
Expand Down Expand Up @@ -303,7 +303,29 @@ export const useNodeStore = create<NodeState>((set, get) => ({
},

onNodeClick: (_: MouseEvent, node: CVFNode) => {
set({ currentElement: node });
// Retira animação do antigo nó clicado
const edges = get().edges;
if (get().currentElement) {
edges
.filter((edge) => [edge.source, edge.target].includes(get().currentElement!.id))
.forEach((edge) => {
edge.animated = false;
edge.style = undefined;
});
}
// Inicia animação do nó clicado
edges
.filter((edge) => [edge.source, edge.target].includes(node.id))
.forEach((edge) => {
edge.animated = true;
edge.style = {
//
stroke: edge.target === node.id ? EDGE_IN_COLOR : EDGE_OUT_COLOR,
strokeWidth: 2,
};
});

set({ currentElement: node, edges: [...edges] });
},

refreshCurrentElement: () => {
Expand Down
2 changes: 2 additions & 0 deletions src/ide/commons/consts.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
export const EDGE_IN_COLOR = '#f48fb1';
export const EDGE_OUT_COLOR = '#0CEAC5';
export const STORAGE_NODESTORE_ID = 'NodeStore';
export const STORAGE_DARK_MODE = 'color_mode';
export const ZOOM_BOX_SIZE = 50;
Expand Down

0 comments on commit a1bd689

Please sign in to comment.