mirror of
https://github.com/ecency/ecency-mobile.git
synced 2025-01-05 21:06:21 +03:00
enhanced posts view
This commit is contained in:
parent
146cb7decf
commit
839aeca06f
@ -48,58 +48,56 @@ class PostsView extends Component {
|
|||||||
|
|
||||||
_loadPosts = (filter = null) => {
|
_loadPosts = (filter = null) => {
|
||||||
const { getFor, tag, currentAccountUsername } = this.props;
|
const { getFor, tag, currentAccountUsername } = this.props;
|
||||||
|
const {
|
||||||
|
posts, startAuthor, startPermlink,
|
||||||
|
} = this.state;
|
||||||
let options;
|
let options;
|
||||||
|
|
||||||
if (!filter) {
|
this.setState({ isLoading: true });
|
||||||
options = { tag, limit: 3 };
|
|
||||||
|
if (!filter && tag) {
|
||||||
|
options = {
|
||||||
|
tag,
|
||||||
|
limit: 3,
|
||||||
|
};
|
||||||
} else {
|
} else {
|
||||||
options = { limit: 3 };
|
options = {
|
||||||
|
limit: 3,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (startAuthor && startPermlink) {
|
||||||
|
options.start_author = startAuthor;
|
||||||
|
options.start_permlink = startPermlink;
|
||||||
}
|
}
|
||||||
|
|
||||||
getPostsSummary(filter || getFor, options, currentAccountUsername)
|
getPostsSummary(filter || getFor, options, currentAccountUsername)
|
||||||
.then((result) => {
|
.then((result) => {
|
||||||
if (result) {
|
if (result) {
|
||||||
this.setState({
|
let _posts = result;
|
||||||
posts: result,
|
|
||||||
startAuthor: result[result.length - 1] && result[result.length - 1].author,
|
if (_posts.length > 0) {
|
||||||
startPermlink: result[result.length - 1] && result[result.length - 1].permlink,
|
if (posts.length > 0) {
|
||||||
refreshing: false,
|
_posts.shift();
|
||||||
isPostsLoading: false,
|
_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) => {
|
.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({
|
this.setState({
|
||||||
posts: [...posts, ..._posts],
|
isPostsLoading: false,
|
||||||
startAuthor: result && result[result.length - 1] && result[result.length - 1].author,
|
|
||||||
startPermlink: result && result[result.length - 1] && result[result.length - 1].permlink,
|
|
||||||
});
|
});
|
||||||
}
|
});
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
_handleOnRefreshPosts = () => {
|
_handleOnRefreshPosts = () => {
|
||||||
@ -193,7 +191,7 @@ class PostsView extends Component {
|
|||||||
showsVerticalScrollIndicator={false}
|
showsVerticalScrollIndicator={false}
|
||||||
renderItem={({ item }) => <PostCard content={item} isHideImage={isHideImage} />}
|
renderItem={({ item }) => <PostCard content={item} isHideImage={isHideImage} />}
|
||||||
keyExtractor={(post, index) => index.toString()}
|
keyExtractor={(post, index) => index.toString()}
|
||||||
onEndReached={this._loadMore}
|
onEndReached={() => this._loadPosts()}
|
||||||
removeClippedSubviews
|
removeClippedSubviews
|
||||||
refreshing={refreshing}
|
refreshing={refreshing}
|
||||||
onRefresh={() => this._handleOnRefreshPosts()}
|
onRefresh={() => this._handleOnRefreshPosts()}
|
||||||
|
@ -257,7 +257,8 @@ export const getActiveVotes = (author, permlink) => client.database.call('get_ac
|
|||||||
export const getPostsSummary = async (by, query, currentUserName) => {
|
export const getPostsSummary = async (by, query, currentUserName) => {
|
||||||
try {
|
try {
|
||||||
let posts = await client.database.getDiscussions(by, query);
|
let posts = await client.database.getDiscussions(by, query);
|
||||||
|
console.log(posts);
|
||||||
|
console.log(by, query, currentUserName);
|
||||||
posts = await parsePosts(posts, currentUserName);
|
posts = await parsePosts(posts, currentUserName);
|
||||||
return posts;
|
return posts;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
@ -32,9 +32,10 @@ export const markDown2Html = (input) => {
|
|||||||
output = createYoutubeIframe(output);
|
output = createYoutubeIframe(output);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dTubeRegex.test(output)) {
|
// Has bug
|
||||||
output = createDtubeIframe(output);
|
// if (dTubeRegex.test(output)) {
|
||||||
}
|
// output = createDtubeIframe(output);
|
||||||
|
// }
|
||||||
|
|
||||||
if (vimeoRegex.test(output)) {
|
if (vimeoRegex.test(output)) {
|
||||||
output = createVimeoIframe(output);
|
output = createVimeoIframe(output);
|
||||||
|
@ -24,7 +24,12 @@ export const parsePost = (post, currentUserName) => {
|
|||||||
|
|
||||||
const voteRshares = post.active_votes.reduce((a, b) => a + parseFloat(b.rshares), 0);
|
const voteRshares = post.active_votes.reduce((a, b) => a + parseFloat(b.rshares), 0);
|
||||||
const ratio = totalPayout / voteRshares;
|
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) {
|
for (const i in post.active_votes) {
|
||||||
post.vote_perecent = post.active_votes[i].voter === currentUserName ? post.active_votes[i].percent : null;
|
post.vote_perecent = post.active_votes[i].voter === currentUserName ? post.active_votes[i].percent : null;
|
||||||
|
Loading…
Reference in New Issue
Block a user