diff options
| author | Oskar Nyberg <oskar@mullvad.net> | 2022-04-14 15:21:55 +0200 |
|---|---|---|
| committer | Oskar Nyberg <oskar@mullvad.net> | 2022-04-20 10:51:21 +0200 |
| commit | e444b24fb616216be896aefbe5ad98e2818b94bf (patch) | |
| tree | 0877f5d12761380c4eb9cec3fe1d78c750e6becf /gui | |
| parent | 5d2aeb51e95e3b56fd2afd3e3ead0d92d4e5ff85 (diff) | |
| download | mullvadvpn-e444b24fb616216be896aefbe5ad98e2818b94bf.tar.xz mullvadvpn-e444b24fb616216be896aefbe5ad98e2818b94bf.zip | |
Remember current scroll position
Diffstat (limited to 'gui')
| -rw-r--r-- | gui/src/renderer/app.tsx | 2 | ||||
| -rw-r--r-- | gui/src/renderer/components/NavigationBar.tsx | 14 |
2 files changed, 15 insertions, 1 deletions
diff --git a/gui/src/renderer/app.tsx b/gui/src/renderer/app.tsx index 97a6f6a310..d4672066f2 100644 --- a/gui/src/renderer/app.tsx +++ b/gui/src/renderer/app.tsx @@ -256,6 +256,8 @@ export default class AppRenderer { this.reduxActions.userInterface.setScrollPositions(initialState.scrollPositions); if (initialState.navigationHistory) { + // Set last action to POP to trigger automatic scrolling to saved coordinates. + initialState.navigationHistory.lastAction = 'POP'; this.history = History.fromSavedHistory(initialState.navigationHistory); } else { const navigationBase = this.getNavigationBase(); diff --git a/gui/src/renderer/components/NavigationBar.tsx b/gui/src/renderer/components/NavigationBar.tsx index 02de9fdb6e..7e231646ce 100644 --- a/gui/src/renderer/components/NavigationBar.tsx +++ b/gui/src/renderer/components/NavigationBar.tsx @@ -123,7 +123,19 @@ export const NavigationScrollbars = React.forwardRef(function NavigationScrollba const { addScrollPosition, removeScrollPosition } = useActions(userInterface); const scrollPositions = useSelector((state) => state.userInterface.scrollPosition); - useEffect(() => setScrollPositions(scrollPositions), [scrollPositions]); + useEffect(() => { + const path = history.location.pathname; + const beforeunload = () => { + if (ref.current) { + const scrollPosition = ref.current.getScrollPosition(); + setScrollPositions({ ...scrollPositions, [path]: scrollPosition }); + } + }; + + window.addEventListener('beforeunload', beforeunload); + + return () => window.removeEventListener('beforeunload', beforeunload); + }, [scrollPositions]); useLayoutEffect(() => { const path = history.location.pathname; |
