Skip to content

Commit

Permalink
Don't connect mulitple times
Browse files Browse the repository at this point in the history
  • Loading branch information
alexrudd2 committed Oct 14, 2023
1 parent b4a2949 commit fb916c7
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions src/ui.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1046,9 +1046,18 @@ function PortSelector({driver, setDriver}: {driver: Driver; setDriver: (d: Drive
}

function Root() {
const [driver, setDriver] = useState(
IS_WEB ? null as Driver | null : SaxiDriver.connect()
)
let driver: Driver
let setDriver: null
const [isDriverConnected, setIsDriverConnected] = useState(false);
useEffect(() => {
if (isDriverConnected) return
if (IS_WEB) {
[driver, setDriver] = useState(null as Driver)
} else {
driver = SaxiDriver.connect()
}
setIsDriverConnected(true);
}, [isDriverConnected]);
const [state, dispatch] = useReducer(reducer, initialState);
const [isPlanning, plan, setPlan] = usePlan(state.paths, state.planOptions);
const [isLoadingFile, setIsLoadingFile] = useState(false);
Expand Down Expand Up @@ -1077,7 +1086,7 @@ function Root() {
driver.onplan = (plan: Plan) => {
setPlan(plan);
};
}, [driver])
}, IS_WEB ? [driver] : [])

useEffect(() => {
const ondrop = (e: DragEvent) => {
Expand Down Expand Up @@ -1120,7 +1129,7 @@ function Root() {
document.body.removeEventListener("dragleave", ondragleave);
document.removeEventListener("paste", onpaste);
};
});
}, []);

// Each time new motion is started, save the start time
const currentMotionStartedTime = useMemo(() => {
Expand Down

0 comments on commit fb916c7

Please sign in to comment.