summaryrefslogtreecommitdiffhomepage
path: root/gui/src/renderer/redux/userinterface
diff options
context:
space:
mode:
authorOskar Nyberg <oskar@mullvad.net>2020-09-28 17:03:05 +0200
committerOskar Nyberg <oskar@mullvad.net>2020-10-13 13:54:21 +0200
commitbecdea43225f6960fd9999b76afdb681fdaf80da (patch)
treeabd6372656743f188dd1d2179aad43896b7d1574 /gui/src/renderer/redux/userinterface
parentba755eba2604ff8dcda0f84272c30a2fdc9b2a51 (diff)
downloadmullvadvpn-becdea43225f6960fd9999b76afdb681fdaf80da.tar.xz
mullvadvpn-becdea43225f6960fd9999b76afdb681fdaf80da.zip
Remember scroll position when navigating back
Diffstat (limited to 'gui/src/renderer/redux/userinterface')
-rw-r--r--gui/src/renderer/redux/userinterface/actions.ts32
-rw-r--r--gui/src/renderer/redux/userinterface/reducers.ts14
2 files changed, 45 insertions, 1 deletions
diff --git a/gui/src/renderer/redux/userinterface/actions.ts b/gui/src/renderer/redux/userinterface/actions.ts
index affd11798d..d0d1378a88 100644
--- a/gui/src/renderer/redux/userinterface/actions.ts
+++ b/gui/src/renderer/redux/userinterface/actions.ts
@@ -24,12 +24,25 @@ export interface ISetWindowFocusedAction {
focused: boolean;
}
+export interface IAddScrollPosition {
+ type: 'ADD_SCROLL_POSITION';
+ path: string;
+ scrollPosition: [number, number];
+}
+
+export interface IRemoveScrollPosition {
+ type: 'REMOVE_SCROLL_POSITION';
+ path: string;
+}
+
export type UserInterfaceAction =
| IUpdateLocaleAction
| IUpdateWindowArrowPositionAction
| IUpdateConnectionInfoOpenAction
| ISetLocationScopeAction
- | ISetWindowFocusedAction;
+ | ISetWindowFocusedAction
+ | IAddScrollPosition
+ | IRemoveScrollPosition;
function updateLocale(locale: string): IUpdateLocaleAction {
return {
@@ -65,10 +78,27 @@ function setWindowFocused(focused: boolean): ISetWindowFocusedAction {
};
}
+function addScrollPosition(path: string, scrollPosition: [number, number]): IAddScrollPosition {
+ return {
+ type: 'ADD_SCROLL_POSITION',
+ path,
+ scrollPosition,
+ };
+}
+
+function removeScrollPosition(path: string): IRemoveScrollPosition {
+ return {
+ type: 'REMOVE_SCROLL_POSITION',
+ path,
+ };
+}
+
export default {
updateLocale,
updateWindowArrowPosition,
toggleConnectionPanel,
setLocationScope,
setWindowFocused,
+ addScrollPosition,
+ removeScrollPosition,
};
diff --git a/gui/src/renderer/redux/userinterface/reducers.ts b/gui/src/renderer/redux/userinterface/reducers.ts
index 4fef8efbfb..05e091797e 100644
--- a/gui/src/renderer/redux/userinterface/reducers.ts
+++ b/gui/src/renderer/redux/userinterface/reducers.ts
@@ -11,6 +11,7 @@ export interface IUserInterfaceReduxState {
connectionPanelVisible: boolean;
locationScope: LocationScope;
windowFocused: boolean;
+ scrollPosition: Record<string, [number, number]>;
}
const initialState: IUserInterfaceReduxState = {
@@ -18,6 +19,7 @@ const initialState: IUserInterfaceReduxState = {
connectionPanelVisible: false,
locationScope: LocationScope.relay,
windowFocused: false,
+ scrollPosition: {},
};
export default function (
@@ -40,6 +42,18 @@ export default function (
case 'SET_WINDOW_FOCUSED':
return { ...state, windowFocused: action.focused };
+ case 'ADD_SCROLL_POSITION':
+ return {
+ ...state,
+ scrollPosition: { ...state.scrollPosition, [action.path]: action.scrollPosition },
+ };
+
+ case 'REMOVE_SCROLL_POSITION': {
+ const scrollPosition = { ...state.scrollPosition };
+ delete scrollPosition[action.path];
+ return { ...state, scrollPosition };
+ }
+
default:
return state;
}