mirror of
https://github.com/ecency/ecency-mobile.git
synced 2024-12-30 00:52:42 +03:00
save default upvote value for posts and comments separately
This commit is contained in:
parent
6d6c47d8fd
commit
3d6bfab7ee
@ -20,6 +20,7 @@ import { useAppSelector } from '../../../hooks';
|
|||||||
import { OptionsModal } from '../../atoms';
|
import { OptionsModal } from '../../atoms';
|
||||||
import { useDispatch } from 'react-redux';
|
import { useDispatch } from 'react-redux';
|
||||||
import { showReplyModal } from '../../../redux/actions/uiAction';
|
import { showReplyModal } from '../../../redux/actions/uiAction';
|
||||||
|
import postTypes from '../../../constants/postTypes';
|
||||||
|
|
||||||
const CommentView = ({
|
const CommentView = ({
|
||||||
avatarSize,
|
avatarSize,
|
||||||
@ -206,6 +207,7 @@ const CommentView = ({
|
|||||||
isShowPayoutValue
|
isShowPayoutValue
|
||||||
content={comment}
|
content={comment}
|
||||||
handleCacheVoteIncrement={_handleCacheVoteIncrement}
|
handleCacheVoteIncrement={_handleCacheVoteIncrement}
|
||||||
|
parentType={postTypes.COMMENT}
|
||||||
/>
|
/>
|
||||||
<TextWithIcon
|
<TextWithIcon
|
||||||
iconName="heart-outline"
|
iconName="heart-outline"
|
||||||
|
@ -20,6 +20,7 @@ import { Upvote } from '../../upvote';
|
|||||||
import styles from './postCardStyles';
|
import styles from './postCardStyles';
|
||||||
import { TextButton } from '../..';
|
import { TextButton } from '../..';
|
||||||
import getWindowDimensions from '../../../utils/getWindowDimensions';
|
import getWindowDimensions from '../../../utils/getWindowDimensions';
|
||||||
|
import postTypes from '../../../constants/postTypes';
|
||||||
|
|
||||||
const dim = getWindowDimensions();
|
const dim = getWindowDimensions();
|
||||||
const DEFAULT_IMAGE =
|
const DEFAULT_IMAGE =
|
||||||
@ -178,6 +179,7 @@ const PostCardView = ({
|
|||||||
isShowPayoutValue
|
isShowPayoutValue
|
||||||
content={content}
|
content={content}
|
||||||
handleCacheVoteIncrement={_handleCacheVoteIncrement}
|
handleCacheVoteIncrement={_handleCacheVoteIncrement}
|
||||||
|
parentType={postTypes.POST}
|
||||||
/>
|
/>
|
||||||
<TouchableOpacity style={styles.commentButton} onPress={_handleOnVotersPress}>
|
<TouchableOpacity style={styles.commentButton} onPress={_handleOnVotersPress}>
|
||||||
<TextWithIcon
|
<TextWithIcon
|
||||||
|
@ -26,6 +26,7 @@ import { QuickReplyModal } from '../..';
|
|||||||
import getWindowDimensions from '../../../utils/getWindowDimensions';
|
import getWindowDimensions from '../../../utils/getWindowDimensions';
|
||||||
import { useAppDispatch } from '../../../hooks';
|
import { useAppDispatch } from '../../../hooks';
|
||||||
import { showReplyModal } from '../../../redux/actions/uiAction';
|
import { showReplyModal } from '../../../redux/actions/uiAction';
|
||||||
|
import postTypes from '../../../constants/postTypes';
|
||||||
|
|
||||||
const HEIGHT = getWindowDimensions().height;
|
const HEIGHT = getWindowDimensions().height;
|
||||||
const WIDTH = getWindowDimensions().width;
|
const WIDTH = getWindowDimensions().width;
|
||||||
@ -115,6 +116,7 @@ const PostDisplayView = ({
|
|||||||
isShowPayoutValue
|
isShowPayoutValue
|
||||||
content={post}
|
content={post}
|
||||||
handleCacheVoteIncrement={_handleCacheVoteIncrement}
|
handleCacheVoteIncrement={_handleCacheVoteIncrement}
|
||||||
|
parentType={postTypes.POST}
|
||||||
/>
|
/>
|
||||||
<TextWithIcon
|
<TextWithIcon
|
||||||
iconName="heart-outline"
|
iconName="heart-outline"
|
||||||
|
@ -6,7 +6,11 @@ import get from 'lodash/get';
|
|||||||
import { setUpvotePercent } from '../../../realm/realm';
|
import { setUpvotePercent } from '../../../realm/realm';
|
||||||
|
|
||||||
// Services and Actions
|
// Services and Actions
|
||||||
import { setUpvotePercent as upvoteAction } from '../../../redux/actions/applicationActions';
|
import {
|
||||||
|
setUpvotePercent as upvoteAction,
|
||||||
|
setCommentUpvotePercent,
|
||||||
|
setPostUpvotePercent,
|
||||||
|
} from '../../../redux/actions/applicationActions';
|
||||||
|
|
||||||
// Utils
|
// Utils
|
||||||
import { getTimeFromNow } from '../../../utils/time';
|
import { getTimeFromNow } from '../../../utils/time';
|
||||||
@ -17,6 +21,7 @@ import parseAsset from '../../../utils/parseAsset';
|
|||||||
import UpvoteView from '../view/upvoteView';
|
import UpvoteView from '../view/upvoteView';
|
||||||
import { updateVoteCache } from '../../../redux/actions/cacheActions';
|
import { updateVoteCache } from '../../../redux/actions/cacheActions';
|
||||||
import { useAppSelector } from '../../../hooks';
|
import { useAppSelector } from '../../../hooks';
|
||||||
|
import postTypes from '../../../constants/postTypes';
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Props Name Description Value
|
* Props Name Description Value
|
||||||
@ -32,11 +37,14 @@ const UpvoteContainer = (props) => {
|
|||||||
isShowPayoutValue,
|
isShowPayoutValue,
|
||||||
pinCode,
|
pinCode,
|
||||||
upvotePercent,
|
upvotePercent,
|
||||||
|
postUpvotePercent,
|
||||||
|
commentUpvotePercent,
|
||||||
globalProps,
|
globalProps,
|
||||||
dispatch,
|
dispatch,
|
||||||
activeVotes = [],
|
activeVotes = [],
|
||||||
handleCacheVoteIncrement,
|
handleCacheVoteIncrement,
|
||||||
fetchPost,
|
fetchPost,
|
||||||
|
parentType,
|
||||||
} = props;
|
} = props;
|
||||||
|
|
||||||
const [isVoted, setIsVoted] = useState(null);
|
const [isVoted, setIsVoted] = useState(null);
|
||||||
@ -84,6 +92,12 @@ const UpvoteContainer = (props) => {
|
|||||||
if (value) {
|
if (value) {
|
||||||
setUpvotePercent(String(value));
|
setUpvotePercent(String(value));
|
||||||
dispatch(upvoteAction(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}
|
totalPayout={totalPayout}
|
||||||
maxPayout={maxPayout}
|
maxPayout={maxPayout}
|
||||||
upvotePercent={upvotePercent}
|
upvotePercent={upvotePercent}
|
||||||
|
postUpvotePercent={postUpvotePercent}
|
||||||
|
commentUpvotePercent={commentUpvotePercent}
|
||||||
|
parentType={parentType}
|
||||||
beneficiaries={beneficiaries}
|
beneficiaries={beneficiaries}
|
||||||
warnZeroPayout={warnZeroPayout}
|
warnZeroPayout={warnZeroPayout}
|
||||||
breakdownPayout={breakdownPayout}
|
breakdownPayout={breakdownPayout}
|
||||||
@ -215,6 +232,8 @@ const UpvoteContainer = (props) => {
|
|||||||
const mapStateToProps = (state) => ({
|
const mapStateToProps = (state) => ({
|
||||||
isLoggedIn: state.application.isLoggedIn,
|
isLoggedIn: state.application.isLoggedIn,
|
||||||
upvotePercent: state.application.upvotePercent,
|
upvotePercent: state.application.upvotePercent,
|
||||||
|
postUpvotePercent: state.application.postUpvotePercent,
|
||||||
|
commentUpvotePercent: state.application.commentUpvotePercent,
|
||||||
pinCode: state.application.pin,
|
pinCode: state.application.pin,
|
||||||
currentAccount: state.account.currentAccount,
|
currentAccount: state.account.currentAccount,
|
||||||
globalProps: state.account.globalProps,
|
globalProps: state.account.globalProps,
|
||||||
|
@ -21,6 +21,7 @@ import { vote } from '../../../providers/hive/dhive';
|
|||||||
// Styles
|
// Styles
|
||||||
import styles from './upvoteStyles';
|
import styles from './upvoteStyles';
|
||||||
import { useAppSelector } from '../../../hooks';
|
import { useAppSelector } from '../../../hooks';
|
||||||
|
import postTypes from '../../../constants/postTypes';
|
||||||
|
|
||||||
interface UpvoteViewProps {
|
interface UpvoteViewProps {
|
||||||
isDeclinedPayout:boolean;
|
isDeclinedPayout:boolean;
|
||||||
@ -45,6 +46,9 @@ interface UpvoteViewProps {
|
|||||||
onVote:(amount:string, downvote:boolean)=>void;
|
onVote:(amount:string, downvote:boolean)=>void;
|
||||||
isVoted:boolean;
|
isVoted:boolean;
|
||||||
upvotePercent:number;
|
upvotePercent:number;
|
||||||
|
postUpvotePercent: number;
|
||||||
|
commentUpvotePercent: number;
|
||||||
|
parentType: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
const UpvoteView = ({
|
const UpvoteView = ({
|
||||||
@ -68,7 +72,10 @@ const UpvoteView = ({
|
|||||||
dispatch,
|
dispatch,
|
||||||
onVote,
|
onVote,
|
||||||
isVoted,
|
isVoted,
|
||||||
upvotePercent
|
// upvotePercent,
|
||||||
|
postUpvotePercent,
|
||||||
|
commentUpvotePercent,
|
||||||
|
parentType,
|
||||||
}:UpvoteViewProps) => {
|
}:UpvoteViewProps) => {
|
||||||
const intl = useIntl();
|
const intl = useIntl();
|
||||||
|
|
||||||
@ -83,11 +90,20 @@ const UpvoteView = ({
|
|||||||
const [upvote, setUpvote] = useState(isVoted || false);
|
const [upvote, setUpvote] = useState(isVoted || false);
|
||||||
const [downvote, setDownvote] = useState(isDownVoted || false);
|
const [downvote, setDownvote] = useState(isDownVoted || false);
|
||||||
const [isShowDetails, setIsShowDetails] = useState(false);
|
const [isShowDetails, setIsShowDetails] = useState(false);
|
||||||
|
const [upvotePercent, setUpvotePercent] = useState(1);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
_calculateEstimatedAmount();
|
_calculateEstimatedAmount();
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (parentType === postTypes.POST) {
|
||||||
|
setUpvotePercent(postUpvotePercent);
|
||||||
|
}
|
||||||
|
if (parentType === postTypes.COMMENT) {
|
||||||
|
setUpvotePercent(commentUpvotePercent);
|
||||||
|
}
|
||||||
|
},[postUpvotePercent, commentUpvotePercent])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const value = (isVoted || isDownVoted)
|
const value = (isVoted || isDownVoted)
|
||||||
@ -252,6 +268,7 @@ const UpvoteView = ({
|
|||||||
</View>
|
</View>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
console.log('upvotePercent : ', upvotePercent, '\n parentType : ', parentType);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<PopoverController>
|
<PopoverController>
|
||||||
|
7
src/constants/postTypes.ts
Normal file
7
src/constants/postTypes.ts
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
const POST = 'post';
|
||||||
|
const COMMENT = 'comment';
|
||||||
|
|
||||||
|
export default {
|
||||||
|
POST,
|
||||||
|
COMMENT,
|
||||||
|
};
|
@ -33,7 +33,9 @@ import {
|
|||||||
HIDE_POSTS_THUMBNAILS,
|
HIDE_POSTS_THUMBNAILS,
|
||||||
SET_TERMS_ACCEPTED,
|
SET_TERMS_ACCEPTED,
|
||||||
SET_IS_BIOMETRIC_ENABLED,
|
SET_IS_BIOMETRIC_ENABLED,
|
||||||
SET_ENC_UNLOCK_PIN
|
SET_ENC_UNLOCK_PIN,
|
||||||
|
SET_POST_UPVOTE_PERCENT,
|
||||||
|
SET_COMMENT_UPVOTE_PERCENT
|
||||||
} from '../constants/constants';
|
} from '../constants/constants';
|
||||||
|
|
||||||
export const login = (payload) => ({
|
export const login = (payload) => ({
|
||||||
@ -79,6 +81,16 @@ export const setUpvotePercent = (payload) => ({
|
|||||||
type: SET_UPVOTE_PERCENT,
|
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) => ({
|
export const changeAllNotificationSettings = (payload) => ({
|
||||||
payload,
|
payload,
|
||||||
type: CHANGE_ALL_NOTIFICATION_SETTINGS,
|
type: CHANGE_ALL_NOTIFICATION_SETTINGS,
|
||||||
|
@ -24,6 +24,8 @@ export const SET_API = 'SET_API';
|
|||||||
export const SET_CURRENCY = 'SET_CURRENCY';
|
export const SET_CURRENCY = 'SET_CURRENCY';
|
||||||
export const SET_LANGUAGE = 'SET_LANGUAGE';
|
export const SET_LANGUAGE = 'SET_LANGUAGE';
|
||||||
export const SET_UPVOTE_PERCENT = 'SET_UPVOTE_PERCENT';
|
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 SET_NSFW = 'SET_NSFW';
|
||||||
export const CHANGE_FOLLOW_NOTIFICATION = 'CHANGE_FOLLOW_NOTIFICATION';
|
export const CHANGE_FOLLOW_NOTIFICATION = 'CHANGE_FOLLOW_NOTIFICATION';
|
||||||
export const CHANGE_VOTE_NOTIFICATION = 'CHANGE_VOTE_NOTIFICATION';
|
export const CHANGE_VOTE_NOTIFICATION = 'CHANGE_VOTE_NOTIFICATION';
|
||||||
|
@ -22,6 +22,8 @@ import {
|
|||||||
SET_LANGUAGE,
|
SET_LANGUAGE,
|
||||||
SET_NSFW,
|
SET_NSFW,
|
||||||
SET_UPVOTE_PERCENT,
|
SET_UPVOTE_PERCENT,
|
||||||
|
SET_POST_UPVOTE_PERCENT,
|
||||||
|
SET_COMMENT_UPVOTE_PERCENT,
|
||||||
SET_PIN_CODE,
|
SET_PIN_CODE,
|
||||||
IS_PIN_CODE_OPEN,
|
IS_PIN_CODE_OPEN,
|
||||||
IS_RENDER_REQUIRED,
|
IS_RENDER_REQUIRED,
|
||||||
@ -63,6 +65,8 @@ interface State {
|
|||||||
voteNotification: boolean,
|
voteNotification: boolean,
|
||||||
},
|
},
|
||||||
upvotePercent: number;
|
upvotePercent: number;
|
||||||
|
postUpvotePercent: number;
|
||||||
|
commentUpvotePercent: number;
|
||||||
nsfw: string;
|
nsfw: string;
|
||||||
pin: string|null; //encrypted pin used for encrypting sensitive user data
|
pin: string|null; //encrypted pin used for encrypting sensitive user data
|
||||||
isPinCodeOpen: boolean;
|
isPinCodeOpen: boolean;
|
||||||
@ -104,6 +108,8 @@ const initialState:State = {
|
|||||||
voteNotification: true,
|
voteNotification: true,
|
||||||
},
|
},
|
||||||
upvotePercent: 1,
|
upvotePercent: 1,
|
||||||
|
postUpvotePercent: 1,
|
||||||
|
commentUpvotePercent: 1,
|
||||||
nsfw: '1',
|
nsfw: '1',
|
||||||
pin: null,
|
pin: null,
|
||||||
isPinCodeOpen: false,
|
isPinCodeOpen: false,
|
||||||
@ -247,6 +253,14 @@ export default function (state = initialState, action):State {
|
|||||||
return Object.assign({}, state, {
|
return Object.assign({}, state, {
|
||||||
upvotePercent: action.payload,
|
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:
|
case SET_NSFW:
|
||||||
return Object.assign({}, state, {
|
return Object.assign({}, state, {
|
||||||
nsfw: action.payload,
|
nsfw: action.payload,
|
||||||
|
Loading…
Reference in New Issue
Block a user