Skip to content

Commit

Permalink
⚡️ :: (#28) realize start node & end node
Browse files Browse the repository at this point in the history
  • Loading branch information
KJG04 committed Jan 24, 2022
1 parent 12127ea commit 83f2e35
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 6 deletions.
28 changes: 24 additions & 4 deletions functions/src/components/Providers/GateContextProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,33 @@
import { FC, useCallback, useMemo, useState } from "react";
import { Dot, Gate, GateContext, GateContextType, Node, Point } from "../../context/GateContext";
import {
CurrentNode,
Gate,
GateContext,
GateContextType,
Node,
Point,
} from "../../context/GateContext";

const GateContextProvider: FC = ({ children }) => {
const [gates, setGates] = useState<Gate[]>([]);
const [nodes, setNodes] = useState<Node[]>([]);
const [currentNode, setCurrentNode] = useState<Node | null>(null);
const [currentNode, setCurrentNode] = useState<CurrentNode | null>(null);

const startNode = useCallback((position: Point) => {
setCurrentNode({ start: position, end: position });
}, []);

const endNode = useCallback(
(position: Point) => {
if (!currentNode) {
return;
}

setCurrentNode({ ...currentNode, end: position });
},
[currentNode]
);

const startNode = useCallback((dot: Dot) => {}, []);
const endNode = useCallback((position: Point) => {}, []);
const addNode = useCallback((startDotId: string, endDotId: string) => {}, []);
const setNodeIsActive = useCallback((nodeId: string, isActive: boolean) => {}, []);

Expand Down
9 changes: 7 additions & 2 deletions functions/src/context/GateContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,16 @@ export interface Node {
isActive: boolean;
}

export interface CurrentNode {
start: Point;
end: Point;
}

export interface GateContextType {
gates: Gate[];
nodes: Node[];
currentNode: Node | null;
startNode: (dot: Dot) => void;
currentNode: CurrentNode | null;
startNode: (position: Point) => void;
endNode: (position: Point) => void;
addNode: (startDotId: string, endDotId: string) => void;
setNodeIsActive: (nodeId: string, isActive: boolean) => void;
Expand Down

0 comments on commit 83f2e35

Please sign in to comment.