From 9593584dcd16e3b92dff745fa0f34d3102134872 Mon Sep 17 00:00:00 2001 From: srgooglo Date: Wed, 2 Mar 2022 16:08:20 +0100 Subject: [PATCH] fetch methods --- packages/app/src/pages/explore/index.jsx | 48 +++++++++++++++++------ packages/app/src/pages/explore/index.less | 30 +++++++++++--- 2 files changed, 60 insertions(+), 18 deletions(-) diff --git a/packages/app/src/pages/explore/index.jsx b/packages/app/src/pages/explore/index.jsx index f316774e..ab0d8870 100644 --- a/packages/app/src/pages/explore/index.jsx +++ b/packages/app/src/pages/explore/index.jsx @@ -1,12 +1,17 @@ import React from "react" import * as antd from "antd" -import { PostCard } from "components" +import { PostCard, PostCreator } from "components" +import { InfiniteScroll } from "antd-mobile" import "./index.less" +const ContainerHeight = 700; + export default class PostsExplorer extends React.Component { state = { loading: true, + skipStep: 0, + lastLength: 0, posts: [], } @@ -35,7 +40,9 @@ export default class PostsExplorer extends React.Component { } fetchPosts = async () => { - const posts = await this.api.get.feed().catch(error => { + const posts = await this.api.get.feed(undefined, { + feedSkip: this.state.skipStep, + }).catch(error => { console.error(error) antd.message.error(error) @@ -44,25 +51,40 @@ export default class PostsExplorer extends React.Component { if (posts) { console.log(posts) - this.setState({ posts }) + this.setState({ posts: [...posts, ...this.state.posts,], lastLength: posts.length }) } - } - renderPosts = (posts) => { - if (!Array.isArray(posts)) { - antd.message.error("Failed to render posts") - return null - } + hasMore = () => { + return this.state.posts.length < this.state.lastLength + } - return posts.map((post) => { - return - }) + loadMore = async () => { + await this.setState({ skipStep: this.state.skipStep + 1 }) + await this.fetchPosts() } render() { + if (this.state.loading) { + return + } + return
- {this.state.loading ? : this.renderPosts(this.state.posts)} +
+
+ +
+ + { + this.state.posts.map(post => { + return + }) + } + + +
Loading more...
+
+
} } \ No newline at end of file diff --git a/packages/app/src/pages/explore/index.less b/packages/app/src/pages/explore/index.less index 7f08ff6d..5c97c29b 100644 --- a/packages/app/src/pages/explore/index.less +++ b/packages/app/src/pages/explore/index.less @@ -1,11 +1,31 @@ .explore { - display: flex; - flex-direction: column; - align-items: center; + display : flex; + flex-direction : column; + align-items : center; + justify-content: center; width: 100%; - > div { - margin-bottom: 15px; + .wrapper { + display : flex; + flex-direction : column; + align-items : center; + justify-content: center; + + width : 100%; + max-width: 40vw; + + .header { + display : flex; + flex-direction : column; + align-items : center; + justify-content: center; + + width: 100%; + } + + >div { + margin-bottom: 15px; + } } } \ No newline at end of file