Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(app): fix back to back manual move commands on desktop app #17129

Merged
merged 1 commit into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading