Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Don't connect mulitple times
Browse files Browse the repository at this point in the history
alexrudd2 committed Oct 14, 2023

Unverified

This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
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
@@ -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);
@@ -1077,7 +1086,7 @@ function Root() {
driver.onplan = (plan: Plan) => {
setPlan(plan);
};
}, [driver])
}, IS_WEB ? [driver] : [])

useEffect(() => {
const ondrop = (e: DragEvent) => {
@@ -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(() => {

0 comments on commit fb916c7

Please sign in to comment.