From 5f9f27fd7001df347ab65e0cba849e583db31dc8 Mon Sep 17 00:00:00 2001 From: crupest Date: Wed, 10 Jun 2020 00:40:32 +0800 Subject: Finally one. --- .../src/timeline/TimelinePageTemplateUI.tsx | 28 +++++++++++++--------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/Timeline/ClientApp/src/timeline/TimelinePageTemplateUI.tsx b/Timeline/ClientApp/src/timeline/TimelinePageTemplateUI.tsx index 8fc3815b..1cd772c2 100644 --- a/Timeline/ClientApp/src/timeline/TimelinePageTemplateUI.tsx +++ b/Timeline/ClientApp/src/timeline/TimelinePageTemplateUI.tsx @@ -1,7 +1,7 @@ import React from 'react'; import { Spinner } from 'reactstrap'; import { useTranslation } from 'react-i18next'; -import { Subject } from 'rxjs'; +import { Subject, fromEvent } from 'rxjs'; import { getAlertHost } from '../common/alert-service'; @@ -74,17 +74,23 @@ export default function TimelinePageTemplateUI< }, [resizeSubject]); React.useEffect(() => { - let jumpToBottom = true; - const timerTag = window.setTimeout(() => { - jumpToBottom = false; - }, 1000); - const subscription = resizeSubject.subscribe(() => { - if (jumpToBottom) - window.scrollTo(0, document.body.getBoundingClientRect().height); - }); + let scrollToBottom = true; + const disableScrollToBottom = (): void => { + scrollToBottom = false; + }; + + const subscriptions = [ + fromEvent(window, 'wheel').subscribe(disableScrollToBottom), + fromEvent(window, 'pointerdown').subscribe(disableScrollToBottom), + resizeSubject.subscribe(() => { + if (scrollToBottom) { + window.scrollTo(0, document.body.scrollHeight); + } + }), + ]; + return () => { - clearTimeout(timerTag); - subscription.unsubscribe(); + subscriptions.forEach((s) => s.unsubscribe()); }; }, [resizeSubject, timeline, props.posts]); -- cgit v1.2.3