From 928ba0ce419bacba113951095278a5138ead34cf Mon Sep 17 00:00:00 2001
From: crupest <crupest@outlook.com>
Date: Sun, 10 Apr 2022 16:04:03 +0800
Subject: ...

---
 .../views/timeline/TimelinePagedPostListView.tsx   | 34 ++++++++++++++++++++++
 1 file changed, 34 insertions(+)
 create mode 100644 FrontEnd/src/views/timeline/TimelinePagedPostListView.tsx

(limited to 'FrontEnd/src/views/timeline/TimelinePagedPostListView.tsx')

diff --git a/FrontEnd/src/views/timeline/TimelinePagedPostListView.tsx b/FrontEnd/src/views/timeline/TimelinePagedPostListView.tsx
new file mode 100644
index 00000000..69a5607c
--- /dev/null
+++ b/FrontEnd/src/views/timeline/TimelinePagedPostListView.tsx
@@ -0,0 +1,34 @@
+import React from "react";
+
+import { HttpTimelinePostInfo } from "@/http/timeline";
+
+import useScrollToTop from "@/utilities/useScrollToTop";
+
+import TimelinePostListView from "./TimelinePostListView";
+
+export interface TimelinePagedPostListViewProps {
+  posts: HttpTimelinePostInfo[];
+  onReload: () => void;
+}
+
+const TimelinePagedPostListView: React.FC<TimelinePagedPostListViewProps> = (
+  props
+) => {
+  const { 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 posts={viewingPosts} onReload={onReload} />;
+};
+
+export default TimelinePagedPostListView;
-- 
cgit v1.2.3

