enhanced posts view

This commit is contained in:
u-e 2018-12-17 20:14:12 +03:00
parent 146cb7decf
commit 839aeca06f
4 changed files with 49 additions and 44 deletions

View File

@ -48,58 +48,56 @@ class PostsView extends Component {
_loadPosts = (filter = null) => {
const { getFor, tag, currentAccountUsername } = this.props;
const {
posts, startAuthor, startPermlink,
} = this.state;
let options;
if (!filter) {
options = { tag, limit: 3 };
this.setState({ isLoading: true });
if (!filter && tag) {
options = {
tag,
limit: 3,
};
} else {
options = { limit: 3 };
options = {
limit: 3,
};
}
if (startAuthor && startPermlink) {
options.start_author = startAuthor;
options.start_permlink = startPermlink;
}
getPostsSummary(filter || getFor, options, currentAccountUsername)
.then((result) => {
if (result) {
this.setState({
posts: result,
startAuthor: result[result.length - 1] && result[result.length - 1].author,
startPermlink: result[result.length - 1] && result[result.length - 1].permlink,
refreshing: false,
isPostsLoading: false,
});
let _posts = result;
if (_posts.length > 0) {
if (posts.length > 0) {
_posts.shift();
_posts = [...posts, ..._posts];
}
this.setState({
posts: _posts,
startAuthor: result[result.length - 1] && result[result.length - 1].author,
startPermlink: result[result.length - 1] && result[result.length - 1].permlink,
refreshing: false,
isPostsLoading: false,
});
}
}
})
.catch((err) => {
alert(err);
});
};
console.log(err);
_loadMore = () => {
// TODO: merge above function with this func (after alpha).
const { posts, startAuthor, startPermlink } = this.state;
const { getFor, tag, currentAccountUsername } = this.props;
this.setState({ isLoading: true });
getPostsSummary(
getFor,
{
tag,
limit: 3,
start_author: startAuthor,
start_permlink: startPermlink,
},
currentAccountUsername,
).then((result) => {
const _posts = result;
if (_posts.length > 0) {
_posts.shift();
this.setState({
posts: [...posts, ..._posts],
startAuthor: result && result[result.length - 1] && result[result.length - 1].author,
startPermlink: result && result[result.length - 1] && result[result.length - 1].permlink,
isPostsLoading: false,
});
}
});
});
};
_handleOnRefreshPosts = () => {
@ -193,7 +191,7 @@ class PostsView extends Component {
showsVerticalScrollIndicator={false}
renderItem={({ item }) => <PostCard content={item} isHideImage={isHideImage} />}
keyExtractor={(post, index) => index.toString()}
onEndReached={this._loadMore}
onEndReached={() => this._loadPosts()}
removeClippedSubviews
refreshing={refreshing}
onRefresh={() => this._handleOnRefreshPosts()}

View File

@ -257,7 +257,8 @@ export const getActiveVotes = (author, permlink) => client.database.call('get_ac
export const getPostsSummary = async (by, query, currentUserName) => {
try {
let posts = await client.database.getDiscussions(by, query);
console.log(posts);
console.log(by, query, currentUserName);
posts = await parsePosts(posts, currentUserName);
return posts;
} catch (error) {

View File

@ -32,9 +32,10 @@ export const markDown2Html = (input) => {
output = createYoutubeIframe(output);
}
if (dTubeRegex.test(output)) {
output = createDtubeIframe(output);
}
// Has bug
// if (dTubeRegex.test(output)) {
// output = createDtubeIframe(output);
// }
if (vimeoRegex.test(output)) {
output = createVimeoIframe(output);

View File

@ -24,7 +24,12 @@ export const parsePost = (post, currentUserName) => {
const voteRshares = post.active_votes.reduce((a, b) => a + parseFloat(b.rshares), 0);
const ratio = totalPayout / voteRshares;
post.is_voted = isVoted(post.active_votes, currentUserName);
if (currentUserName) {
post.is_voted = isVoted(post.active_votes, currentUserName);
} else {
post.is_voted = false;
}
for (const i in post.active_votes) {
post.vote_perecent = post.active_votes[i].voter === currentUserName ? post.active_votes[i].percent : null;