save default upvote value for posts and comments separately

This commit is contained in:
Sadaqat Ali 2022-08-08 21:30:14 +05:00
parent 6d6c47d8fd
commit 3d6bfab7ee
9 changed files with 80 additions and 3 deletions

View File

@ -20,6 +20,7 @@ import { useAppSelector } from '../../../hooks';
import { OptionsModal } from '../../atoms';
import { useDispatch } from 'react-redux';
import { showReplyModal } from '../../../redux/actions/uiAction';
import postTypes from '../../../constants/postTypes';
const CommentView = ({
avatarSize,
@ -206,6 +207,7 @@ const CommentView = ({
isShowPayoutValue
content={comment}
handleCacheVoteIncrement={_handleCacheVoteIncrement}
parentType={postTypes.COMMENT}
/>
<TextWithIcon
iconName="heart-outline"

View File

@ -20,6 +20,7 @@ import { Upvote } from '../../upvote';
import styles from './postCardStyles';
import { TextButton } from '../..';
import getWindowDimensions from '../../../utils/getWindowDimensions';
import postTypes from '../../../constants/postTypes';
const dim = getWindowDimensions();
const DEFAULT_IMAGE =
@ -178,6 +179,7 @@ const PostCardView = ({
isShowPayoutValue
content={content}
handleCacheVoteIncrement={_handleCacheVoteIncrement}
parentType={postTypes.POST}
/>
<TouchableOpacity style={styles.commentButton} onPress={_handleOnVotersPress}>
<TextWithIcon

View File

@ -26,6 +26,7 @@ import { QuickReplyModal } from '../..';
import getWindowDimensions from '../../../utils/getWindowDimensions';
import { useAppDispatch } from '../../../hooks';
import { showReplyModal } from '../../../redux/actions/uiAction';
import postTypes from '../../../constants/postTypes';
const HEIGHT = getWindowDimensions().height;
const WIDTH = getWindowDimensions().width;
@ -115,6 +116,7 @@ const PostDisplayView = ({
isShowPayoutValue
content={post}
handleCacheVoteIncrement={_handleCacheVoteIncrement}
parentType={postTypes.POST}
/>
<TextWithIcon
iconName="heart-outline"

View File

@ -6,7 +6,11 @@ import get from 'lodash/get';
import { setUpvotePercent } from '../../../realm/realm';
// Services and Actions
import { setUpvotePercent as upvoteAction } from '../../../redux/actions/applicationActions';
import {
setUpvotePercent as upvoteAction,
setCommentUpvotePercent,
setPostUpvotePercent,
} from '../../../redux/actions/applicationActions';
// Utils
import { getTimeFromNow } from '../../../utils/time';
@ -17,6 +21,7 @@ import parseAsset from '../../../utils/parseAsset';
import UpvoteView from '../view/upvoteView';
import { updateVoteCache } from '../../../redux/actions/cacheActions';
import { useAppSelector } from '../../../hooks';
import postTypes from '../../../constants/postTypes';
/*
* Props Name Description Value
@ -32,11 +37,14 @@ const UpvoteContainer = (props) => {
isShowPayoutValue,
pinCode,
upvotePercent,
postUpvotePercent,
commentUpvotePercent,
globalProps,
dispatch,
activeVotes = [],
handleCacheVoteIncrement,
fetchPost,
parentType,
} = props;
const [isVoted, setIsVoted] = useState(null);
@ -84,6 +92,12 @@ const UpvoteContainer = (props) => {
if (value) {
setUpvotePercent(String(value));
dispatch(upvoteAction(value));
if (parentType === postTypes.POST) {
dispatch(setPostUpvotePercent(value));
}
if (parentType === postTypes.COMMENT) {
dispatch(setCommentUpvotePercent(value));
}
}
};
@ -199,6 +213,9 @@ const UpvoteContainer = (props) => {
totalPayout={totalPayout}
maxPayout={maxPayout}
upvotePercent={upvotePercent}
postUpvotePercent={postUpvotePercent}
commentUpvotePercent={commentUpvotePercent}
parentType={parentType}
beneficiaries={beneficiaries}
warnZeroPayout={warnZeroPayout}
breakdownPayout={breakdownPayout}
@ -215,6 +232,8 @@ const UpvoteContainer = (props) => {
const mapStateToProps = (state) => ({
isLoggedIn: state.application.isLoggedIn,
upvotePercent: state.application.upvotePercent,
postUpvotePercent: state.application.postUpvotePercent,
commentUpvotePercent: state.application.commentUpvotePercent,
pinCode: state.application.pin,
currentAccount: state.account.currentAccount,
globalProps: state.account.globalProps,

View File

@ -21,6 +21,7 @@ import { vote } from '../../../providers/hive/dhive';
// Styles
import styles from './upvoteStyles';
import { useAppSelector } from '../../../hooks';
import postTypes from '../../../constants/postTypes';
interface UpvoteViewProps {
isDeclinedPayout:boolean;
@ -45,6 +46,9 @@ interface UpvoteViewProps {
onVote:(amount:string, downvote:boolean)=>void;
isVoted:boolean;
upvotePercent:number;
postUpvotePercent: number;
commentUpvotePercent: number;
parentType: string;
}
const UpvoteView = ({
@ -68,7 +72,10 @@ const UpvoteView = ({
dispatch,
onVote,
isVoted,
upvotePercent
// upvotePercent,
postUpvotePercent,
commentUpvotePercent,
parentType,
}:UpvoteViewProps) => {
const intl = useIntl();
@ -83,11 +90,20 @@ const UpvoteView = ({
const [upvote, setUpvote] = useState(isVoted || false);
const [downvote, setDownvote] = useState(isDownVoted || false);
const [isShowDetails, setIsShowDetails] = useState(false);
const [upvotePercent, setUpvotePercent] = useState(1);
useEffect(() => {
_calculateEstimatedAmount();
}, [])
useEffect(() => {
if (parentType === postTypes.POST) {
setUpvotePercent(postUpvotePercent);
}
if (parentType === postTypes.COMMENT) {
setUpvotePercent(commentUpvotePercent);
}
},[postUpvotePercent, commentUpvotePercent])
useEffect(() => {
const value = (isVoted || isDownVoted)
@ -252,6 +268,7 @@ const UpvoteView = ({
</View>
);
};
console.log('upvotePercent : ', upvotePercent, '\n parentType : ', parentType);
return (
<PopoverController>

View File

@ -0,0 +1,7 @@
const POST = 'post';
const COMMENT = 'comment';
export default {
POST,
COMMENT,
};

View File

@ -33,7 +33,9 @@ import {
HIDE_POSTS_THUMBNAILS,
SET_TERMS_ACCEPTED,
SET_IS_BIOMETRIC_ENABLED,
SET_ENC_UNLOCK_PIN
SET_ENC_UNLOCK_PIN,
SET_POST_UPVOTE_PERCENT,
SET_COMMENT_UPVOTE_PERCENT
} from '../constants/constants';
export const login = (payload) => ({
@ -79,6 +81,16 @@ export const setUpvotePercent = (payload) => ({
type: SET_UPVOTE_PERCENT,
});
export const setPostUpvotePercent = (payload) => ({
payload,
type: SET_POST_UPVOTE_PERCENT,
});
export const setCommentUpvotePercent = (payload) => ({
payload,
type: SET_COMMENT_UPVOTE_PERCENT,
});
export const changeAllNotificationSettings = (payload) => ({
payload,
type: CHANGE_ALL_NOTIFICATION_SETTINGS,

View File

@ -24,6 +24,8 @@ export const SET_API = 'SET_API';
export const SET_CURRENCY = 'SET_CURRENCY';
export const SET_LANGUAGE = 'SET_LANGUAGE';
export const SET_UPVOTE_PERCENT = 'SET_UPVOTE_PERCENT';
export const SET_POST_UPVOTE_PERCENT = 'SET_POST_UPVOTE_PERCENT';
export const SET_COMMENT_UPVOTE_PERCENT = 'SET_COMMENT_UPVOTE_PERCENT';
export const SET_NSFW = 'SET_NSFW';
export const CHANGE_FOLLOW_NOTIFICATION = 'CHANGE_FOLLOW_NOTIFICATION';
export const CHANGE_VOTE_NOTIFICATION = 'CHANGE_VOTE_NOTIFICATION';

View File

@ -22,6 +22,8 @@ import {
SET_LANGUAGE,
SET_NSFW,
SET_UPVOTE_PERCENT,
SET_POST_UPVOTE_PERCENT,
SET_COMMENT_UPVOTE_PERCENT,
SET_PIN_CODE,
IS_PIN_CODE_OPEN,
IS_RENDER_REQUIRED,
@ -63,6 +65,8 @@ interface State {
voteNotification: boolean,
},
upvotePercent: number;
postUpvotePercent: number;
commentUpvotePercent: number;
nsfw: string;
pin: string|null; //encrypted pin used for encrypting sensitive user data
isPinCodeOpen: boolean;
@ -104,6 +108,8 @@ const initialState:State = {
voteNotification: true,
},
upvotePercent: 1,
postUpvotePercent: 1,
commentUpvotePercent: 1,
nsfw: '1',
pin: null,
isPinCodeOpen: false,
@ -247,6 +253,14 @@ export default function (state = initialState, action):State {
return Object.assign({}, state, {
upvotePercent: action.payload,
});
case SET_POST_UPVOTE_PERCENT:
return Object.assign({}, state, {
postUpvotePercent: action.payload,
});
case SET_COMMENT_UPVOTE_PERCENT:
return Object.assign({}, state, {
commentUpvotePercent: action.payload,
});
case SET_NSFW:
return Object.assign({}, state, {
nsfw: action.payload,