aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-web/src/main/js/hooks
diff options
context:
space:
mode:
author7PH <benjamin.raymond@sonarsource.com>2023-05-17 11:30:23 +0200
committersonartech <sonartech@sonarsource.com>2023-05-24 20:03:14 +0000
commit31c52cad6e60801c48999cc204c71d123d22c064 (patch)
treeacaba58837dfaca9751785cf77749aff866f79fa /server/sonar-web/src/main/js/hooks
parent56e625210bff28970ce12cf8d7807ebda6c147e1 (diff)
downloadsonarqube-31c52cad6e60801c48999cc204c71d123d22c064.tar.gz
sonarqube-31c52cad6e60801c48999cc204c71d123d22c064.zip
SONAR-19236 Implement correct layout for hotspot page sidebar
Diffstat (limited to 'server/sonar-web/src/main/js/hooks')
-rw-r--r--server/sonar-web/src/main/js/hooks/useFollowScroll.ts42
1 files changed, 42 insertions, 0 deletions
diff --git a/server/sonar-web/src/main/js/hooks/useFollowScroll.ts b/server/sonar-web/src/main/js/hooks/useFollowScroll.ts
new file mode 100644
index 00000000000..0692d5e2ab7
--- /dev/null
+++ b/server/sonar-web/src/main/js/hooks/useFollowScroll.ts
@@ -0,0 +1,42 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2023 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+import { throttle } from 'lodash';
+import { useEffect, useState } from 'react';
+
+const THROTTLE_DELAY = 10;
+
+export default function useFollowScroll() {
+ const [left, setLeft] = useState(0);
+ const [top, setTop] = useState(0);
+
+ useEffect(() => {
+ const followScroll = throttle(() => {
+ if (document.documentElement) {
+ setLeft(document.documentElement.scrollLeft);
+ setTop(document.documentElement.scrollTop);
+ }
+ }, THROTTLE_DELAY);
+
+ document.addEventListener('scroll', followScroll);
+ return () => document.removeEventListener('scroll', followScroll);
+ }, []);
+
+ return { left, top };
+}