diff --git a/src/components/tabbedPosts/services/tabbedPostsFetch.ts b/src/components/tabbedPosts/services/tabbedPostsFetch.ts index 1a11b137fb..6fd397b16f 100644 --- a/src/components/tabbedPosts/services/tabbedPostsFetch.ts +++ b/src/components/tabbedPosts/services/tabbedPostsFetch.ts @@ -2,6 +2,7 @@ import { getAccountPosts, getPost, getRankedPosts } from '../../../providers/hiv import { filterLatestPosts, getUpdatedPosts } from './tabbedPostsHelpers'; import { LoadPostsOptions } from './tabbedPostsModels'; import { getPromotedEntries } from '../../../providers/ecency/ecency'; +import filterNsfwPost from '../../../utils/filterNsfwPost'; const POSTS_FETCH_COUNT = 20; @@ -183,10 +184,12 @@ export const loadPosts = async ({ } }; -export const fetchPromotedEntries = async (username: string) => { +export const fetchPromotedEntries = async (username: string, nsfwFilter:string) => { try { const posts = await getPromotedEntries(username); - return Array.isArray(posts) ? posts : []; + + return Array.isArray(posts) ? filterNsfwPost(posts, nsfwFilter) : []; + } catch (err) { console.warn('Failed to get promoted posts, ', err); } diff --git a/src/components/tabbedPosts/view/tabContent.tsx b/src/components/tabbedPosts/view/tabContent.tsx index 4c3f79903f..33273eff31 100644 --- a/src/components/tabbedPosts/view/tabContent.tsx +++ b/src/components/tabbedPosts/view/tabContent.tsx @@ -219,7 +219,7 @@ const TabContent = ({ if (pageType === 'profile' || pageType === 'ownProfile' || pageType === 'community') { return; } - const pPosts = await fetchPromotedEntries(username); + const pPosts = await fetchPromotedEntries(username, nsfw); if (pPosts) { setPromotedPosts(pPosts); } diff --git a/src/utils/filterNsfwPost.js b/src/utils/filterNsfwPost.js index 990a4b712f..2902f596c6 100644 --- a/src/utils/filterNsfwPost.js +++ b/src/utils/filterNsfwPost.js @@ -2,26 +2,30 @@ import get from 'lodash/get'; /* eslint-disable array-callback-return */ export default (posts, option) => { const updatedPosts = []; - if (option === '1') { - posts.map((post) => { - if (post.parent_permlink === 'nsfw' || get(post, 'json_metadata.tags', []).includes('nsfw')) { - post.nsfw = true; - } - }); - return posts; - } - // removes nsfw post from array ... filter value '2' - if (posts) { - posts.map((post) => { - if ( - post.parent_permlink !== 'nsfw' && - !get(post, 'json_metadata.tags', []).includes('nsfw') - ) { - updatedPosts.push(post); - } - }); - return updatedPosts; + switch (option) { + case '0': + return posts; + + case '1': + posts.map((post) => { + if (post.parent_permlink === 'nsfw' || get(post, 'json_metadata.tags', []).includes('nsfw')) { + post.nsfw = true; + } + }); + return posts; + + default: + posts.map((post) => { + if ( + post.parent_permlink !== 'nsfw' && + !get(post, 'json_metadata.tags', []).includes('nsfw') + ) { + updatedPosts.push(post); + } + }); + return updatedPosts; + } }; /* eslint-enable */