From 3d6bfab7ee15146a4e051817a624f6e5efced4de Mon Sep 17 00:00:00 2001 From: Sadaqat Ali Date: Mon, 8 Aug 2022 21:30:14 +0500 Subject: [PATCH] save default upvote value for posts and comments separately --- src/components/comment/view/commentView.tsx | 2 ++ src/components/postCard/view/postCardView.js | 2 ++ .../postView/view/postDisplayView.js | 2 ++ .../upvote/container/upvoteContainer.js | 21 ++++++++++++++++++- src/components/upvote/view/upvoteView.tsx | 19 ++++++++++++++++- src/constants/postTypes.ts | 7 +++++++ src/redux/actions/applicationActions.ts | 14 ++++++++++++- src/redux/constants/constants.js | 2 ++ src/redux/reducers/applicationReducer.ts | 14 +++++++++++++ 9 files changed, 80 insertions(+), 3 deletions(-) create mode 100644 src/constants/postTypes.ts diff --git a/src/components/comment/view/commentView.tsx b/src/components/comment/view/commentView.tsx index 4eedee7d0..2a99eb706 100644 --- a/src/components/comment/view/commentView.tsx +++ b/src/components/comment/view/commentView.tsx @@ -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} /> { 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, diff --git a/src/components/upvote/view/upvoteView.tsx b/src/components/upvote/view/upvoteView.tsx index ca7252669..15ac5b5d8 100644 --- a/src/components/upvote/view/upvoteView.tsx +++ b/src/components/upvote/view/upvoteView.tsx @@ -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 = ({ ); }; +console.log('upvotePercent : ', upvotePercent, '\n parentType : ', parentType); return ( diff --git a/src/constants/postTypes.ts b/src/constants/postTypes.ts new file mode 100644 index 000000000..cdc06f790 --- /dev/null +++ b/src/constants/postTypes.ts @@ -0,0 +1,7 @@ +const POST = 'post'; +const COMMENT = 'comment'; + +export default { + POST, + COMMENT, +}; diff --git a/src/redux/actions/applicationActions.ts b/src/redux/actions/applicationActions.ts index 3e409f127..be90e410e 100644 --- a/src/redux/actions/applicationActions.ts +++ b/src/redux/actions/applicationActions.ts @@ -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, diff --git a/src/redux/constants/constants.js b/src/redux/constants/constants.js index 9e6263831..16d8ac438 100644 --- a/src/redux/constants/constants.js +++ b/src/redux/constants/constants.js @@ -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'; diff --git a/src/redux/reducers/applicationReducer.ts b/src/redux/reducers/applicationReducer.ts index 6cd6c460a..35c1c5985 100644 --- a/src/redux/reducers/applicationReducer.ts +++ b/src/redux/reducers/applicationReducer.ts @@ -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,