Skip to content

Commit

Permalink
fix: DiffScene back/forward browser button behaviour
Browse files Browse the repository at this point in the history
DiffScene did not handle changes in route when back or forward button
pressed. This change has the react router driving the changes to state.
If diff changes, history is updated. History updates state. When back/forward
button pressed, history is update and again history updates state.
  • Loading branch information
bryans99 committed Feb 12, 2022
1 parent 42c7879 commit fc8ab5b
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions packages/api-explorer/src/scenes/DiffScene/DiffScene.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,23 +104,33 @@ export const DiffScene: FC<DiffSceneProps> = ({ specs, toggleNavigation }) => {
)
const [toggles, setToggles] = useState<string[]>(standardDiffToggles)

useEffect(() => {
if (r !== rightKey) {
setRightKey(r)
}
}, [r, rightKey])

useEffect(() => {
if (l !== leftKey) {
setLeftKey(l)
}
}, [l, leftKey])

useEffect(() => {
toggleNavigation(false)
}, [])

const [delta, setDelta] = useState<DiffRow[]>([])

const handleLeftChange = (newLeft: string) => {
setLeftKey(newLeft)
history.push(`/${diffPath}/${newLeft}/${rightKey}`)
}
const handleRightChange = (newRight: string) => {
setRightKey(newRight)
history.push(`/${diffPath}/${leftKey}/${newRight}`)
}

const handleSwitch = () => {
const currLeftKey = leftKey
setLeftKey(rightKey)
setRightKey(currLeftKey)
history.push(`/${diffPath}/${rightKey}/${leftKey}`)
}

useEffect(() => {
Expand All @@ -144,10 +154,6 @@ export const DiffScene: FC<DiffSceneProps> = ({ specs, toggleNavigation }) => {
setToggles(newToggles)
}

useEffect(() => {
history.push(`/${diffPath}/${leftKey}/${rightKey}`)
}, [leftKey, rightKey])

return (
<ApixSection>
<Box>
Expand Down

0 comments on commit fc8ab5b

Please sign in to comment.