Skip to content

Commit

Permalink
fix(app): fix back to back manual move commands on the desktop app
Browse files Browse the repository at this point in the history
  • Loading branch information
mjhuff committed Dec 17, 2024
1 parent 98afdcf commit de95c3f
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,6 @@ export function MoveLabwareInterventionContent({
<Flex width="50%">
<Box margin="0 auto" width="100%">
<MoveLabwareOnDeck
key={command.id} // important so that back to back move labware commands bust the cache
robotType={robotType}
deckFill={isOnDevice ? COLORS.grey35 : '#e6e6e6'}
initialLabwareLocation={oldLabwareLocation}
Expand Down
34 changes: 34 additions & 0 deletions components/src/hardware-sim/Deck/MoveLabwareOnDeck.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,10 @@ export function MoveLabwareOnDeck(
loadedLabware,
}) ?? offDeckPosition

const shouldReset = usePositionChangeReset(initialPosition, finalPosition)

const springProps = useSpring({
reset: shouldReset,
config: { duration: 1000, easing: easings.easeInOutSine },
from: {
...initialPosition,
Expand Down Expand Up @@ -245,6 +248,37 @@ export function MoveLabwareOnDeck(
)
}

function usePositionChangeReset(
initialPosition: { x: number; y: number },
finalPosition: { x: number; y: number }
): boolean {
const [shouldReset, setShouldReset] = React.useState(false)

React.useLayoutEffect(() => {
if (shouldReset) {
setShouldReset(false)
return
}

const isNewPosition =
previousInitialRef.current?.x !== initialPosition.x ||
previousInitialRef.current?.y !== initialPosition.y ||
previousFinalRef.current?.x !== finalPosition.x ||
previousFinalRef.current?.y !== finalPosition.y

if (isNewPosition) {
setShouldReset(true)
}

previousInitialRef.current = initialPosition
previousFinalRef.current = finalPosition
}, [initialPosition, finalPosition])

const previousInitialRef = React.useRef(initialPosition)
const previousFinalRef = React.useRef(finalPosition)

return shouldReset
}
/**
* These animated components needs to be split out because react-spring and styled-components don't play nice
* @see https://github.com/pmndrs/react-spring/issues/1515 */
Expand Down

0 comments on commit de95c3f

Please sign in to comment.