mirror of
https://github.com/ecency/ecency-mobile.git
synced 2024-12-26 06:42:15 +03:00
Integrated filter nsfw feature with posts screens
This commit is contained in:
parent
17a2af1611
commit
91edd79b67
@ -59,6 +59,7 @@ const mapStateToProps = state => ({
|
||||
isLoggedIn: state.application.isLoggedIn,
|
||||
isLoginDone: state.application.isLoginDone,
|
||||
isCollapsePostButtonOpen: state.ui.isCollapsePostButton,
|
||||
nsfw: state.application.nsfw,
|
||||
});
|
||||
|
||||
export default connect(mapStateToProps)(PostsContainer);
|
||||
|
@ -81,7 +81,7 @@ class PostsView extends Component {
|
||||
|
||||
_loadPosts = () => {
|
||||
const {
|
||||
getFor, tag, currentAccountUsername, pageType,
|
||||
getFor, tag, currentAccountUsername, pageType, nsfw,
|
||||
} = this.props;
|
||||
const {
|
||||
posts, startAuthor, startPermlink, refreshing, selectedFilterIndex,
|
||||
@ -114,7 +114,7 @@ class PostsView extends Component {
|
||||
options.start_permlink = startPermlink;
|
||||
}
|
||||
|
||||
getPostsSummary(filter, options, currentAccountUsername)
|
||||
getPostsSummary(filter, options, currentAccountUsername, nsfw)
|
||||
.then((result) => {
|
||||
if (result.length > 0) {
|
||||
let _posts = result;
|
||||
@ -160,7 +160,7 @@ class PostsView extends Component {
|
||||
this.setState({ isNoPost: true });
|
||||
}
|
||||
})
|
||||
.catch((err) => {
|
||||
.catch(() => {
|
||||
this.setState({
|
||||
refreshing: false,
|
||||
isPostsLoading: false,
|
||||
|
@ -11,6 +11,7 @@ import { parsePosts, parsePost, parseComments } from '../../utils/postParser';
|
||||
import { getName, getAvatar } from '../../utils/user';
|
||||
import { getReputation } from '../../utils/reputation';
|
||||
import parseToken from '../../utils/parseToken';
|
||||
import filterNsfwPost from '../../utils/filterNsfwPost';
|
||||
|
||||
// Constant
|
||||
import AUTH_TYPE from '../../constants/authType';
|
||||
@ -274,12 +275,17 @@ export const getPosts = async (by, query, user) => {
|
||||
|
||||
export const getActiveVotes = (author, permlink) => client.database.call('get_active_votes', [author, permlink]);
|
||||
|
||||
export const getPostsSummary = async (by, query, currentUserName) => {
|
||||
export const getPostsSummary = async (by, query, currentUserName, filterNsfw) => {
|
||||
try {
|
||||
let posts = await client.database.getDiscussions(by, query);
|
||||
|
||||
if (posts) {
|
||||
posts = await parsePosts(posts, currentUserName, true);
|
||||
|
||||
if (filterNsfw !== '0') {
|
||||
const updatedPosts = filterNsfwPost(posts, filterNsfw);
|
||||
return updatedPosts;
|
||||
}
|
||||
}
|
||||
return posts;
|
||||
} catch (error) {
|
||||
|
17
src/utils/filterNsfwPost.js
Normal file
17
src/utils/filterNsfwPost.js
Normal file
@ -0,0 +1,17 @@
|
||||
export default (posts, option) => {
|
||||
const updatedPosts = [];
|
||||
if (option === '1') {
|
||||
posts.map((post) => {
|
||||
if (post.parent_permlink === 'nsfw' || post.json_metadata.tags.includes('nsfw')) {
|
||||
post.image = 'https://steemitimages.com/p/Zskj9C56UonWToSX7uRkL8H89BqdWqSPnzP84oDpA65G4PfbZk688V2cRYbWszK7zoMMj35CfbJfcXuJSSwTvasK4pPKfHMy2xjGJSkmqs8gLQnoddR8?format=match&mode=fit&width=600&height=600';
|
||||
}
|
||||
});
|
||||
return posts;
|
||||
}
|
||||
posts.map((post) => {
|
||||
if (post.parent_permlink !== 'nsfw' && !post.json_metadata.tags.includes('nsfw')) {
|
||||
updatedPosts.push(post);
|
||||
}
|
||||
});
|
||||
return updatedPosts;
|
||||
};
|
Loading…
Reference in New Issue
Block a user