From 78a1f60e370cd509e9c5f16a1496e86f264f9cf0 Mon Sep 17 00:00:00 2001 From: srgooglo <38926803+srgooglo@users.noreply.github.com> Date: Wed, 11 Mar 2020 17:29:31 +0100 Subject: [PATCH] mainfeed | fix 01 --- config/app.settings.js | 2 +- package.json | 2 +- src/components/MainFeed/index.js | 210 +++++++++++++++---------------- src/components/PostCard/index.js | 12 +- 4 files changed, 110 insertions(+), 116 deletions(-) diff --git a/config/app.settings.js b/config/app.settings.js index 115d6469..6b442c3d 100755 --- a/config/app.settings.js +++ b/config/app.settings.js @@ -22,5 +22,5 @@ export var DevOptions = { CurrentBundle: 'light_ng', // In KB MaximunAPIPayload: '101376', - limit_post_catch: ReturnDevOption('limit_post_catch') + limit_post_catch: '20' } \ No newline at end of file diff --git a/package.json b/package.json index e62f4d6a..575b4239 100755 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "comty-development", "title": "Comty™", "DevBuild": true, - "version": "0.2.10", + "version": "0.2.11", "description": "", "main": "index.js", "author": "RageStudio", diff --git a/src/components/MainFeed/index.js b/src/components/MainFeed/index.js index 7296774b..4c84932f 100755 --- a/src/components/MainFeed/index.js +++ b/src/components/MainFeed/index.js @@ -2,12 +2,11 @@ import React from 'react' import * as antd from 'antd' import * as ycore from 'ycore' -import InfiniteScroll from 'react-infinite-scroller'; - import {PostCard} from 'components' var userData = ycore.SDCP() + export function RefreshFeed(){ ycore.yconsole.log('Refreshing Feed...') window.MainFeedComponent.handleRefreshList(); @@ -18,132 +17,127 @@ class MainFeed extends React.Component { super(props) window.MainFeedComponent = this; this.state = { - feedRaw: [], - loading: true, - hasMore: true, + loading: false, + data: [], + fkey: 0 } } + handleRefreshList(){ + this.GetPostsData.first() + } toogleLoader(){ this.setState({ loading: !this.state.loading }) } - - GetPostsData(fkey){ - const { get, uid, filters } = this.props; - if (!get) { - ycore.yconsole.error('Please, fill params with an catch type...') - return - } - if (!fkey) { - ycore.yconsole.warn('Please, provide a fkey for offset the feed, default using => 0'); - - } - this.toogleLoader() - ycore.GetPosts(uid, get, (fkey || '0'), (err, result) => { - this.setState({ feedRaw: result, loading: false }) - }) + last (array, n) { + if (array == null) + return void 0; + if (n == null) + return array[array.length - 1]; + return array.slice(Math.max(array.length - n, 0)); + }; + FirstGet(fkey) { + try{ + const { get, uid, filters } = this.props; + if (!get) { + ycore.yconsole.error('Please, fill params with an catch type...') + return + } + + this.toogleLoader() + ycore.GetPosts(uid, get, '0', (err, result) => { + this.setState({ data: JSON.parse(result)['data'], loading: false }) + }) + }catch(err){ + ycore.notifyError('err') + } } + GetMore(fkey){ + try{ + const { get, uid, filters } = this.props; + if (!get) { + ycore.yconsole.error('Please, fill params with an catch type...') + return + } + if (!fkey) { + ycore.yconsole.warn('Please, provide a fkey for offset the feed, default using => 0'); + } + this.toogleLoader() + const getLastPost = this.last(this.state.data) + ycore.yconsole.log('LAST POST ID =>', getLastPost.id) + ycore.GetPosts(uid, get, getLastPost.id, (err, res) => { + if (err){return false} + + const oldData = this.state.data + const parsed = JSON.parse(res)['data'] + const mix = oldData.concat(parsed) + + this.setState({ data: mix, loading: false }) + window.dispatchEvent(new Event('resize')); + return true + + }) + + + }catch(err){ + ycore.notifyError(err) + } + + } + + componentDidMount(){ - this.GetPostsData() - + this.FirstGet() } - renderFeedPosts = (e) =>{ - const {feedRaw} = this.state - const { get, filters } = this.props + + renderFeedPosts = () =>{ + const {data, loading} = this.state + const loadMore = + !loading ? ( +
+ this.GetMore()}>More +
+ ) : null; try { - const feedParsed = JSON.parse(feedRaw)['data'] - ycore.yconsole.log(feedParsed) + + ycore.yconsole.log(data) return ( - feedParsed.map(item=> { - const {id, postText, post_time, publisher, postFile, postFileName, is_liked, is_post_saved, is_post_reported, is_post_boosted, is_post_pinned, post_likes} = item - const paylodd = { - id: id, - user: publisher.username, - ago: post_time, - avatar: publisher.avatar, - content: postText, - file: postFile, - postFileName: postFileName, - publisher: publisher, - post_likes: post_likes, - is_liked: is_liked, - is_post_saved: is_post_saved, - is_post_reported: is_post_reported, - is_post_boosted: is_post_boosted, - is_post_pinned: is_post_pinned, - } - return - }) + ()} + /> + ) } catch (err) { - ycore.notifyError(err) - const paylodd = {user: '', ago: '', avatar: '', content: '', publisher: '' } - return + return false } } - handleInfiniteOnLoad = () => { - const { get, uid, filters } = this.props; - let { feedRaw } = this.state; - this.setState({ - loading: true, - }); - if (feedRaw.length > 300) { - antd.message.warning('Infinite List loaded all'); - this.setState({ - hasMore: false, - loading: false, - }); - return; - } - console.log('LENGTHT', feedRaw.length) - ycore.GetPostsData(uid, get, feedRaw.length, (err, res) => { - feedRaw = feedRaw.concat(res.results); - this.setState({ - feedRaw, - loading: false, - }); - }); - }; - - - render(){ - const { loading, feedRaw } = this.state; - const loaderCard = ( - - ) - + const { loading } = this.state; + return ( -
- - ( - - - } - title={{item.name.last}} - description={item.email} - /> -
Content
-
- )} - > - {this.state.loading && this.state.hasMore && (loaderCard)} -
-
- +
+ { loading? + + + + : this.renderFeedPosts() + } +
) } diff --git a/src/components/PostCard/index.js b/src/components/PostCard/index.js index c714d9fb..fb52eaa5 100755 --- a/src/components/PostCard/index.js +++ b/src/components/PostCard/index.js @@ -61,7 +61,7 @@ class PostCard extends React.PureComponent{ render(){ const { payload, customActions } = this.props const ActShowMode = ycore.DevOptions.force_show_postactions - const { id, user, ago, avatar, content, file, postFileName, publisher, post_likes, is_post_pinned, is_liked } = payload || emptyPayload; + const { id, post_time, postText, postFile, postFileName, publisher, post_likes, is_post_pinned, is_liked } = payload || emptyPayload; const defaultActions = [
, , @@ -88,13 +88,13 @@ class PostCard extends React.PureComponent{
} - title={

ycore.crouter.native(`@${user}`)} className={styles.titleUser}>@{user} {ycore.booleanFix(publisher.verified)? : null}{ycore.booleanFix(publisher.nsfw_flag)? NSFW : null}

{ycore.booleanFix(is_post_pinned)? ( ): null }
} - description={{ago}} + avatar={
} + title={

ycore.crouter.native(`@${publisher.username}`)} className={styles.titleUser}>@{publisher.username} {ycore.booleanFix(publisher.verified)? : null}{ycore.booleanFix(publisher.nsfw_flag)? NSFW : null}

{ycore.booleanFix(is_post_pinned)? ( ): null }
} + description={{post_time}} bordered="false" /> - {content?

: null} - {file?
{this.renderPostPlayer(file)}
: null } + {postText?

: null} + {postFile?
{this.renderPostPlayer(postFile)}
: null }