blob: 37f02a82abc02cb14c38fb920dbc363c0fba6751 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
  | 
import React from "react";
import { HttpTimelinePostInfo } from "@/http/timeline";
import useScrollToTop from "@/utilities/useScrollToTop";
import TimelinePostListView from "./TimelinePostListView";
export interface TimelinePagedPostListViewProps {
  className?: string;
  style?: React.CSSProperties;
  posts: HttpTimelinePostInfo[];
  onReload: () => void;
}
const TimelinePagedPostListView: React.FC<TimelinePagedPostListViewProps> = (
  props
) => {
  const { className, style, posts, onReload } = props;
  const [lastViewCount, setLastViewCount] = React.useState<number>(10);
  const viewingPosts = React.useMemo(() => {
    return lastViewCount >= posts.length
      ? posts.slice()
      : posts.slice(-lastViewCount);
  }, [posts, lastViewCount]);
  useScrollToTop(() => {
    setLastViewCount(lastViewCount + 10);
  }, lastViewCount < posts.length);
  return (
    <TimelinePostListView
      className={className}
      style={style}
      posts={viewingPosts}
      onReload={onReload}
    />
  );
};
export default TimelinePagedPostListView;
 
  |