diff options
| author | crupest <crupest@outlook.com> | 2021-05-08 09:56:03 +0800 | 
|---|---|---|
| committer | crupest <crupest@outlook.com> | 2021-05-08 09:56:03 +0800 | 
| commit | c381b56b4a74c7febf82d9b6de9e26ddd59f6605 (patch) | |
| tree | a09f9b2d61183922688c037215197233c7ac79c8 /FrontEnd/src/app/views/timeline-common | |
| parent | e61c41a592b3844ab66f52fb3c9de97a03884f69 (diff) | |
| download | timeline-c381b56b4a74c7febf82d9b6de9e26ddd59f6605.tar.gz timeline-c381b56b4a74c7febf82d9b6de9e26ddd59f6605.tar.bz2 timeline-c381b56b4a74c7febf82d9b6de9e26ddd59f6605.zip | |
fix: Try to fix scroll to top problem.
Diffstat (limited to 'FrontEnd/src/app/views/timeline-common')
| -rw-r--r-- | FrontEnd/src/app/views/timeline-common/TimelinePagedPostListView.tsx | 44 | 
1 files changed, 20 insertions, 24 deletions
| diff --git a/FrontEnd/src/app/views/timeline-common/TimelinePagedPostListView.tsx b/FrontEnd/src/app/views/timeline-common/TimelinePagedPostListView.tsx index ee52f4c0..9c43434d 100644 --- a/FrontEnd/src/app/views/timeline-common/TimelinePagedPostListView.tsx +++ b/FrontEnd/src/app/views/timeline-common/TimelinePagedPostListView.tsx @@ -1,11 +1,14 @@  import React from "react";  import { fromEvent } from "rxjs"; -import { filter, throttleTime } from "rxjs/operators";  import { HttpTimelinePostInfo } from "@/http/timeline"; +import { +  getReverseScrollPosition, +  scrollToReverseScrollPosition, +} from "@/utilities/useReverseScrollPositionRemember"; +  import TimelinePostListView from "./TimelinePostListView"; -import { setRecordDisabled } from "@/utilities/useReverseScrollPositionRemember";  export interface TimelinePagedPostListViewProps {    className?: string; @@ -27,31 +30,24 @@ const TimelinePagedPostListView: React.FC<TimelinePagedPostListViewProps> = (        : posts.slice(-lastViewCount);    }, [posts, lastViewCount]); -  const scrollTopHandler = React.useRef<() => void>(); +  const lastScrollPosition = React.useRef<number | null>(null);    React.useEffect(() => { -    scrollTopHandler.current = () => { -      if (lastViewCount < posts.length) { -        setRecordDisabled(true); -        setLastViewCount(lastViewCount + 10); -        setTimeout(() => { -          setRecordDisabled(false); -        }, 500); -      } -    }; -  }, [lastViewCount, posts]); - -  React.useEffect(() => { -    const subscription = fromEvent(window, "scroll") -      .pipe( -        filter(() => window.scrollY === 0), -        throttleTime(800) -      ) -      .subscribe(() => { -        scrollTopHandler.current?.(); +    if (lastScrollPosition.current != null) { +      scrollToReverseScrollPosition(lastScrollPosition.current); +      lastScrollPosition.current = null; +    } + +    if (lastViewCount < posts.length) { +      const subscription = fromEvent(window, "scroll").subscribe(() => { +        if (window.scrollY === 0) { +          lastScrollPosition.current = getReverseScrollPosition(); +          setLastViewCount(lastViewCount + 10); +        }        }); -    return () => subscription.unsubscribe(); -  }, []); +      return () => subscription.unsubscribe(); +    } +  }, [lastViewCount, posts]);    return (      <TimelinePostListView | 
