summaryrefslogtreecommitdiffhomepage
path: root/gui/src/renderer/components
diff options
context:
space:
mode:
authorOskar Nyberg <oskar@mullvad.net>2022-04-14 14:42:20 +0200
committerOskar Nyberg <oskar@mullvad.net>2022-04-20 10:51:21 +0200
commit5d2aeb51e95e3b56fd2afd3e3ead0d92d4e5ff85 (patch)
treed1041feeb034a35ce0c91d2d61c7e25d811eb8b0 /gui/src/renderer/components
parenteffad880de8f52f9d956a5cccb486504f617f5d8 (diff)
downloadmullvadvpn-5d2aeb51e95e3b56fd2afd3e3ead0d92d4e5ff85.tar.xz
mullvadvpn-5d2aeb51e95e3b56fd2afd3e3ead0d92d4e5ff85.zip
Remember scroll position on refresh
Diffstat (limited to 'gui/src/renderer/components')
-rw-r--r--gui/src/renderer/components/NavigationBar.tsx11
1 files changed, 7 insertions, 4 deletions
diff --git a/gui/src/renderer/components/NavigationBar.tsx b/gui/src/renderer/components/NavigationBar.tsx
index 2628f484eb..02de9fdb6e 100644
--- a/gui/src/renderer/components/NavigationBar.tsx
+++ b/gui/src/renderer/components/NavigationBar.tsx
@@ -1,7 +1,8 @@
-import React, { useCallback, useContext, useLayoutEffect, useRef } from 'react';
+import React, { useCallback, useContext, useEffect, useLayoutEffect, useRef } from 'react';
import { colors } from '../../config.json';
import { messages } from '../../shared/gettext';
+import { useAppContext } from '../context';
import useActions from '../lib/actionsHook';
import { useHistory } from '../lib/history';
import { useCombinedRefs } from '../lib/utilityHooks';
@@ -114,18 +115,20 @@ export const NavigationScrollbars = React.forwardRef(function NavigationScrollba
) {
const history = useHistory();
const { onScroll } = useContext(NavigationScrollContext);
+ const { setScrollPositions } = useAppContext();
const ref = useRef<CustomScrollbarsRef>();
const combinedRefs = useCombinedRefs(forwardedRef, ref);
const { addScrollPosition, removeScrollPosition } = useActions(userInterface);
- const scrollPosition = useSelector(
- (state) => state.userInterface.scrollPosition[history.location.pathname],
- );
+ const scrollPositions = useSelector((state) => state.userInterface.scrollPosition);
+
+ useEffect(() => setScrollPositions(scrollPositions), [scrollPositions]);
useLayoutEffect(() => {
const path = history.location.pathname;
+ const scrollPosition = scrollPositions[history.location.pathname];
if (history.action === 'POP' && scrollPosition) {
ref.current?.scrollTo(...scrollPosition);
removeScrollPosition(path);