hiding post card content of muted author

This commit is contained in:
noumantahir 2021-09-21 00:43:40 +05:00
parent cfe0216df1
commit 505fccd458
4 changed files with 43 additions and 7 deletions

View File

@ -1,4 +1,4 @@
import React, { useState, useEffect } from 'react'; import React, { useState, useEffect, useMemo } from 'react';
import { withNavigation } from 'react-navigation'; import { withNavigation } from 'react-navigation';
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import get from 'lodash/get'; import get from 'lodash/get';
@ -35,6 +35,9 @@ const PostCardContainer = ({
const [_content, setContent] = useState(content); const [_content, setContent] = useState(content);
const [reblogs, setReblogs] = useState([]); const [reblogs, setReblogs] = useState([]);
const activeVotes = get(_content, 'active_votes', []); const activeVotes = get(_content, 'active_votes', []);
const [isMuted, setIsMuted] = useState(
currentAccount.mutes && currentAccount.mutes.indexOf(content.author) > -1,
);
useEffect(() => { useEffect(() => {
let isCancelled = false; let isCancelled = false;
@ -117,12 +120,17 @@ const PostCardContainer = ({
}); });
}; };
const _handleOnUnmutePress = () => {
setIsMuted(false);
};
return ( return (
<PostCardView <PostCardView
handleOnUserPress={_handleOnUserPress} handleOnUserPress={_handleOnUserPress}
handleOnContentPress={_handleOnContentPress} handleOnContentPress={_handleOnContentPress}
handleOnVotersPress={_handleOnVotersPress} handleOnVotersPress={_handleOnVotersPress}
handleOnReblogsPress={_handleOnReblogsPress} handleOnReblogsPress={_handleOnReblogsPress}
handleOnUnmutePress={_handleOnUnmutePress}
content={_content} content={_content}
isHideImage={isHideImage} isHideImage={isHideImage}
nsfw={nsfw || '1'} nsfw={nsfw || '1'}
@ -130,6 +138,7 @@ const PostCardContainer = ({
activeVotes={activeVotes} activeVotes={activeVotes}
imageHeight={imageHeight} imageHeight={imageHeight}
setImageHeight={setImageHeight} setImageHeight={setImageHeight}
isMuted={isMuted}
fetchPost={_fetchPost} fetchPost={_fetchPost}
/> />
); );

View File

@ -91,4 +91,18 @@ export default EStyleSheet.create({
color: '$primaryDarkGray', color: '$primaryDarkGray',
marginLeft: 2, marginLeft: 2,
}, },
revealButton: {
backgroundColor: '$primaryGrayBackground',
height: 56,
justifyContent: 'center',
alignItems: 'center',
borderRadius: 12,
marginTop: 8,
marginHorizontal: 0,
},
revealText: {
color: '$primaryDarkText',
textAlign: 'center',
fontSize: 18,
},
}); });

View File

@ -18,6 +18,7 @@ import { TextWithIcon } from '../../basicUIElements';
import { Upvote } from '../../upvote'; import { Upvote } from '../../upvote';
// Styles // Styles
import styles from './postCardStyles'; import styles from './postCardStyles';
import { TextButton } from '../..';
const dim = Dimensions.get('window'); const dim = Dimensions.get('window');
const DEFAULT_IMAGE = const DEFAULT_IMAGE =
@ -30,6 +31,7 @@ const PostCardView = ({
handleOnContentPress, handleOnContentPress,
handleOnVotersPress, handleOnVotersPress,
handleOnReblogsPress, handleOnReblogsPress,
handleOnUnmutePress,
content, content,
reblogs, reblogs,
isHideImage, isHideImage,
@ -39,6 +41,7 @@ const PostCardView = ({
activeVotes, activeVotes,
imageHeight, imageHeight,
setImageHeight, setImageHeight,
isMuted,
}) => { }) => {
//local state to manage fake upvote if available //local state to manage fake upvote if available
const [activeVotesCount, setActiveVotesCount] = useState(0); const [activeVotesCount, setActiveVotesCount] = useState(0);
@ -78,7 +81,7 @@ const PostCardView = ({
var images = { image: DEFAULT_IMAGE, thumbnail: DEFAULT_IMAGE }; var images = { image: DEFAULT_IMAGE, thumbnail: DEFAULT_IMAGE };
if (content.thumbnail) { if (content.thumbnail) {
if (nsfw !== '0' && content.nsfw) { if (isMuted || (nsfw !== '0' && content.nsfw)) {
images = { image: NSFW_IMAGE, thumbnail: NSFW_IMAGE }; images = { image: NSFW_IMAGE, thumbnail: NSFW_IMAGE };
} else { } else {
images = { image: content.image, thumbnail: content.thumbnail }; images = { image: content.image, thumbnail: content.thumbnail };
@ -149,10 +152,19 @@ const PostCardView = ({
}} }}
/> />
)} )}
{!isMuted ? (
<View style={[styles.postDescripton]}> <View style={[styles.postDescripton]}>
<Text style={styles.title}>{content.title}</Text> <Text style={styles.title}>{content.title}</Text>
<Text style={styles.summary}>{content.summary}</Text> <Text style={styles.summary}>{content.summary}</Text>
</View> </View>
) : (
<TextButton
style={styles.revealButton}
textStyle={styles.revealText}
onPress={() => handleOnUnmutePress()}
text={intl.formatMessage({ id: 'post.reveal_muted' })}
/>
)}
</TouchableOpacity> </TouchableOpacity>
</View> </View>
<View style={styles.bodyFooter}> <View style={styles.bodyFooter}>

View File

@ -441,7 +441,8 @@
"image_saved": "Image saved to Photo Gallery", "image_saved": "Image saved to Photo Gallery",
"image_saved_error": "Error Saving Image", "image_saved_error": "Error Saving Image",
"wrong_link": "Wrong link", "wrong_link": "Wrong link",
"in": "in" "in": "in",
"reveal_muted":"MUTED\nTap to reveal content"
}, },
"drafts": { "drafts": {
"title": "Drafts", "title": "Drafts",