aboutsummaryrefslogtreecommitdiff
path: root/FrontEnd/src/views/timeline/TimelinePagedPostListView.tsx
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2022-04-10 16:04:03 +0800
committercrupest <crupest@outlook.com>2022-04-10 16:04:03 +0800
commit928ba0ce419bacba113951095278a5138ead34cf (patch)
treead4bc6b985c21e751199a25a77f36da7163a47c5 /FrontEnd/src/views/timeline/TimelinePagedPostListView.tsx
parent86160e4a5697615452a7e06dc78f8be4c8b2515f (diff)
downloadtimeline-928ba0ce419bacba113951095278a5138ead34cf.tar.gz
timeline-928ba0ce419bacba113951095278a5138ead34cf.tar.bz2
timeline-928ba0ce419bacba113951095278a5138ead34cf.zip
...
Diffstat (limited to 'FrontEnd/src/views/timeline/TimelinePagedPostListView.tsx')
-rw-r--r--FrontEnd/src/views/timeline/TimelinePagedPostListView.tsx34
1 files changed, 34 insertions, 0 deletions
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;