mirror of
https://github.com/ecency/ecency-mobile.git
synced 2024-12-22 04:41:43 +03:00
fixed promote bugs added routing from dropdown
This commit is contained in:
parent
82d176f99a
commit
3b6dfba2f3
@ -4,6 +4,7 @@ import { withNavigation } from 'react-navigation';
|
||||
import { Share } from 'react-native';
|
||||
import ActionSheet from 'react-native-actionsheet';
|
||||
import { injectIntl } from 'react-intl';
|
||||
import get from 'lodash/get';
|
||||
|
||||
// Services and Actions
|
||||
import { reblog } from '../../../providers/steem/dsteem';
|
||||
@ -57,7 +58,7 @@ class PostDropdownContainer extends PureComponent {
|
||||
|
||||
switch (item) {
|
||||
case 'COPY LINK':
|
||||
await writeToClipboard(getPostUrl(content.url));
|
||||
await writeToClipboard(getPostUrl(get(content, 'url')));
|
||||
this.alertTimer = setTimeout(() => {
|
||||
dispatch(
|
||||
toastNotification(
|
||||
@ -78,8 +79,9 @@ class PostDropdownContainer extends PureComponent {
|
||||
break;
|
||||
|
||||
case 'REPLY':
|
||||
this._replyNavigation();
|
||||
this._redirectToReply();
|
||||
break;
|
||||
|
||||
case 'SHARE':
|
||||
this.shareTimer = setTimeout(() => {
|
||||
this._share();
|
||||
@ -91,6 +93,10 @@ class PostDropdownContainer extends PureComponent {
|
||||
this._addToBookmarks();
|
||||
break;
|
||||
|
||||
case 'PROMOTE':
|
||||
this._redirectToPromote();
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@ -98,7 +104,7 @@ class PostDropdownContainer extends PureComponent {
|
||||
|
||||
_share = () => {
|
||||
const { content } = this.props;
|
||||
const postUrl = getPostUrl(content.url);
|
||||
const postUrl = getPostUrl(get(content, 'url'));
|
||||
|
||||
Share.share({
|
||||
message: `${content.title} ${postUrl}`,
|
||||
@ -107,6 +113,7 @@ class PostDropdownContainer extends PureComponent {
|
||||
|
||||
_addToBookmarks = () => {
|
||||
const { content, currentAccount, dispatch, intl } = this.props;
|
||||
|
||||
addBookmark(currentAccount.name, content.author, content.permlink)
|
||||
.then(() => {
|
||||
dispatch(
|
||||
@ -157,7 +164,7 @@ class PostDropdownContainer extends PureComponent {
|
||||
}
|
||||
};
|
||||
|
||||
_replyNavigation = () => {
|
||||
_redirectToReply = () => {
|
||||
const { content, fetchPost, isLoggedIn, navigation } = this.props;
|
||||
|
||||
if (isLoggedIn) {
|
||||
@ -172,6 +179,19 @@ class PostDropdownContainer extends PureComponent {
|
||||
}
|
||||
};
|
||||
|
||||
_redirectToPromote = () => {
|
||||
const { content, isLoggedIn, navigation } = this.props;
|
||||
|
||||
if (isLoggedIn) {
|
||||
navigation.navigate({
|
||||
routeName: ROUTES.SCREENS.PROMOTE,
|
||||
params: {
|
||||
permlink: `${get(content, 'author')}/${get(content, 'permlink')}`,
|
||||
},
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
render() {
|
||||
const { intl, currentAccount, content, isHideReblogOption } = this.props;
|
||||
let _OPTIONS = OPTIONS;
|
||||
|
@ -12,7 +12,7 @@ export default EStyleSheet.create({
|
||||
textAlignVertical: 'center',
|
||||
textAlign: 'center',
|
||||
fontWeight: 'normal',
|
||||
color: '$primaryLightBackground',
|
||||
color: '$primaryDarkGray',
|
||||
},
|
||||
line: {
|
||||
width: 14,
|
||||
|
@ -260,7 +260,8 @@
|
||||
"reblog": "reblog",
|
||||
"reply": "reply",
|
||||
"share": "share",
|
||||
"bookmarks": "add to bookmarks"
|
||||
"bookmarks": "add to bookmarks",
|
||||
"promote": "promote"
|
||||
},
|
||||
"deep_link": {
|
||||
"no_existing_user": "No existing user",
|
||||
|
@ -7,6 +7,7 @@ const search = axios.create({
|
||||
Authorization: Config.SEARCH_API_TOKEN,
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
// timeout: 500,
|
||||
});
|
||||
|
||||
export default search;
|
||||
|
@ -1 +1 @@
|
||||
export default ['copy', 'reblog', 'reply', 'share', 'bookmarks'];
|
||||
export default ['copy', 'reblog', 'reply', 'share', 'bookmarks', 'promote'];
|
||||
|
@ -1,22 +1,22 @@
|
||||
import React, { Component } from "react";
|
||||
import { Alert } from "react-native";
|
||||
import { connect } from "react-redux";
|
||||
import get from "lodash/get";
|
||||
import { injectIntl } from "react-intl";
|
||||
import { withNavigation } from "react-navigation";
|
||||
import { Component } from 'react';
|
||||
import { Alert } from 'react-native';
|
||||
import { connect } from 'react-redux';
|
||||
import get from 'lodash/get';
|
||||
import { injectIntl } from 'react-intl';
|
||||
import { withNavigation } from 'react-navigation';
|
||||
|
||||
// Services and Actions
|
||||
import { getUser, getUserPoints, claim } from "../providers/esteem/ePoint";
|
||||
import { openPinCodeModal } from "../redux/actions/applicationActions";
|
||||
import { promote, getAccount } from "../providers/steem/dsteem";
|
||||
import { getUserDataWithUsername } from "../realm/realm";
|
||||
import { toastNotification } from "../redux/actions/uiAction";
|
||||
import { getUser, getUserPoints, claim } from '../providers/esteem/ePoint';
|
||||
import { openPinCodeModal } from '../redux/actions/applicationActions';
|
||||
import { promote, getAccount } from '../providers/steem/dsteem';
|
||||
import { getUserDataWithUsername } from '../realm/realm';
|
||||
import { toastNotification } from '../redux/actions/uiAction';
|
||||
|
||||
// Constant
|
||||
import POINTS from "../constants/options/points";
|
||||
import POINTS from '../constants/options/points';
|
||||
|
||||
// Constants
|
||||
import ROUTES from "../constants/routeNames";
|
||||
import ROUTES from '../constants/routeNames';
|
||||
|
||||
/*
|
||||
* Props Name Description Value
|
||||
@ -32,33 +32,37 @@ class PointsContainer extends Component {
|
||||
userActivities: null,
|
||||
refreshing: false,
|
||||
isClaiming: false,
|
||||
isLoading: true
|
||||
isLoading: true,
|
||||
navigationParams: {},
|
||||
};
|
||||
}
|
||||
|
||||
// Component Life Cycle Functions
|
||||
componentDidMount() {
|
||||
const { username, isConnected } = this.props;
|
||||
const { username, isConnected, navigation } = this.props;
|
||||
|
||||
if (isConnected) {
|
||||
this._fetchuserPointActivities(username);
|
||||
this.fetchInterval = setInterval(
|
||||
this._fetchuserPointActivities,
|
||||
6 * 60 * 1000
|
||||
);
|
||||
this.fetchInterval = setInterval(this._fetchuserPointActivities, 6 * 60 * 1000);
|
||||
}
|
||||
|
||||
if (get(navigation, 'state.params', null)) {
|
||||
const navigationParams = get(navigation, 'state.params');
|
||||
|
||||
this.setState({ navigationParams });
|
||||
}
|
||||
}
|
||||
|
||||
componentWillReceiveProps(nextProps) {
|
||||
const { username } = this.props;
|
||||
const _username = get(nextProps, 'username');
|
||||
|
||||
if (
|
||||
nextProps.isConnected &&
|
||||
((nextProps.activeBottomTab === ROUTES.TABBAR.POINTS &&
|
||||
nextProps.username) ||
|
||||
(nextProps.username !== username && nextProps.username))
|
||||
((nextProps.activeBottomTab === ROUTES.TABBAR.POINTS && _username) ||
|
||||
(_username !== username && _username))
|
||||
) {
|
||||
this._fetchuserPointActivities(nextProps.username);
|
||||
this._fetchuserPointActivities(_username);
|
||||
}
|
||||
}
|
||||
|
||||
@ -78,16 +82,16 @@ class PointsContainer extends Component {
|
||||
case 0:
|
||||
navigateTo = ROUTES.SCREENS.TRANSFER;
|
||||
navigateParams = {
|
||||
transferType: "points",
|
||||
fundType: "POINT",
|
||||
balance
|
||||
transferType: 'points',
|
||||
fundType: 'POINT',
|
||||
balance,
|
||||
};
|
||||
break;
|
||||
|
||||
case 1:
|
||||
navigateTo = ROUTES.SCREENS.PROMOTE;
|
||||
navigateParams = {
|
||||
balance
|
||||
balance,
|
||||
};
|
||||
break;
|
||||
|
||||
@ -98,17 +102,17 @@ class PointsContainer extends Component {
|
||||
dispatch(
|
||||
openPinCodeModal({
|
||||
navigateTo,
|
||||
navigateParams
|
||||
})
|
||||
navigateParams,
|
||||
}),
|
||||
);
|
||||
};
|
||||
|
||||
_groomUserActivities = userActivities =>
|
||||
userActivities.map(item => ({
|
||||
...item,
|
||||
icon: get(POINTS[get(item, "type")], "icon"),
|
||||
iconType: get(POINTS[get(item, "type")], "iconType"),
|
||||
textKey: get(POINTS[get(item, "type")], "textKey")
|
||||
icon: get(POINTS[get(item, 'type')], 'icon'),
|
||||
iconType: get(POINTS[get(item, 'type')], 'iconType'),
|
||||
textKey: get(POINTS[get(item, 'type')], 'textKey'),
|
||||
}));
|
||||
|
||||
_fetchuserPointActivities = async username => {
|
||||
@ -117,7 +121,7 @@ class PointsContainer extends Component {
|
||||
|
||||
await getUser(username)
|
||||
.then(userPoints => {
|
||||
const balance = Math.round(get(userPoints, "points") * 1000) / 1000;
|
||||
const balance = Math.round(get(userPoints, 'points') * 1000) / 1000;
|
||||
this.setState({ userPoints, balance });
|
||||
})
|
||||
.catch(err => {
|
||||
@ -128,7 +132,7 @@ class PointsContainer extends Component {
|
||||
.then(userActivities => {
|
||||
if (Object.entries(userActivities).length !== 0) {
|
||||
this.setState({
|
||||
userActivities: this._groomUserActivities(userActivities)
|
||||
userActivities: this._groomUserActivities(userActivities),
|
||||
});
|
||||
}
|
||||
})
|
||||
@ -138,14 +142,14 @@ class PointsContainer extends Component {
|
||||
|
||||
this.setState({
|
||||
refreshing: false,
|
||||
isLoading: false
|
||||
isLoading: false,
|
||||
});
|
||||
};
|
||||
|
||||
_getUserBalance = async username => {
|
||||
await getUser(username)
|
||||
.then(userPoints => {
|
||||
const balance = Math.round(get(userPoints, "points") * 1000) / 1000;
|
||||
const balance = Math.round(get(userPoints, 'points') * 1000) / 1000;
|
||||
return balance;
|
||||
})
|
||||
.catch(err => {
|
||||
@ -166,8 +170,8 @@ class PointsContainer extends Component {
|
||||
Alert.alert(
|
||||
`Fetching data from server failed, please try again or notify us at info@esteem.app \n${error.message.substr(
|
||||
0,
|
||||
20
|
||||
)}`
|
||||
20,
|
||||
)}`,
|
||||
);
|
||||
});
|
||||
|
||||
@ -181,30 +185,29 @@ class PointsContainer extends Component {
|
||||
await promote(user || currentAccount, pinCode, duration, permlink, author)
|
||||
.then(() => {
|
||||
this.setState({ isLoading: false });
|
||||
dispatch(
|
||||
toastNotification(intl.formatMessage({ id: "alert.successful" }))
|
||||
);
|
||||
navigation.goBack();
|
||||
dispatch(toastNotification(intl.formatMessage({ id: 'alert.successful' })));
|
||||
})
|
||||
.catch(error => {
|
||||
Alert.alert(
|
||||
`Fetching data from server failed, please try again or notify us at info@esteem.app \n${error.message.substr(
|
||||
0,
|
||||
20
|
||||
)}`
|
||||
20,
|
||||
)}`,
|
||||
);
|
||||
});
|
||||
};
|
||||
|
||||
render() {
|
||||
const {
|
||||
balance,
|
||||
isClaiming,
|
||||
isDarkTheme,
|
||||
isLoading,
|
||||
navigationParams,
|
||||
refreshing,
|
||||
userActivities,
|
||||
userPoints,
|
||||
balance
|
||||
} = this.state;
|
||||
const { children, accounts, currentAccount } = this.props;
|
||||
|
||||
@ -212,22 +215,23 @@ class PointsContainer extends Component {
|
||||
children &&
|
||||
children({
|
||||
accounts,
|
||||
balance,
|
||||
claimPoints: this._claimPoints,
|
||||
currentAccount,
|
||||
currentAccountName: currentAccount.name,
|
||||
claimPoints: this._claimPoints,
|
||||
fetchUserActivity: this._fetchuserPointActivities,
|
||||
getAccount,
|
||||
getUserBalance: this._getUserBalance,
|
||||
getUserDataWithUsername,
|
||||
handleOnPressTransfer: this._handleOnPressTransfer,
|
||||
isClaiming,
|
||||
isDarkTheme,
|
||||
isLoading,
|
||||
navigationParams,
|
||||
promote: this._promote,
|
||||
refreshing,
|
||||
userActivities,
|
||||
userPoints,
|
||||
handleOnPressTransfer: this._handleOnPressTransfer,
|
||||
balance,
|
||||
getUserBalance: this._getUserBalance,
|
||||
promote: this._promote,
|
||||
getAccount,
|
||||
getUserDataWithUsername
|
||||
})
|
||||
);
|
||||
}
|
||||
@ -240,9 +244,7 @@ const mapStateToProps = state => ({
|
||||
isConnected: state.application.isConnected,
|
||||
accounts: state.account.otherAccounts,
|
||||
currentAccount: state.account.currentAccount,
|
||||
pinCode: state.account.pin
|
||||
pinCode: state.application.pin,
|
||||
});
|
||||
|
||||
export default withNavigation(
|
||||
connect(mapStateToProps)(injectIntl(PointsContainer))
|
||||
);
|
||||
export default withNavigation(connect(mapStateToProps)(injectIntl(PointsContainer)));
|
||||
|
@ -42,6 +42,7 @@ class PointsScreen extends PureComponent {
|
||||
isSCModalOpen: false,
|
||||
SCPath: '',
|
||||
permlinkSuggestions: [],
|
||||
isValid: false,
|
||||
};
|
||||
|
||||
this.startActionSheet = React.createRef();
|
||||
@ -52,13 +53,17 @@ class PointsScreen extends PureComponent {
|
||||
// Component Functions
|
||||
|
||||
_handleOnPermlinkChange = async text => {
|
||||
searchPath(text).then(res => {
|
||||
this.setState({ permlinkSuggestions: res && res.length > 10 ? res.slice(0, 7) : res });
|
||||
});
|
||||
if (text && text.length > 0) {
|
||||
searchPath(text).then(res => {
|
||||
this.setState({ permlinkSuggestions: res && res.length > 10 ? res.slice(0, 7) : res });
|
||||
});
|
||||
} else {
|
||||
await this.setState({ permlinkSuggestions: [], isValid: false });
|
||||
}
|
||||
|
||||
if (!text || (text && text.length < 1)) this.setState({ permlinkSuggestions: [] });
|
||||
// if (!text || (text && text.length < 1))
|
||||
|
||||
this.setState({ permlink: text });
|
||||
this.setState({ permlink: text, isValid: false });
|
||||
};
|
||||
|
||||
_renderDescription = text => <Text style={styles.description}>{text}</Text>;
|
||||
@ -74,8 +79,9 @@ class PointsScreen extends PureComponent {
|
||||
defaultText={currentAccountName}
|
||||
selectedOptionIndex={accounts.findIndex(item => item.username === currentAccountName)}
|
||||
onSelect={(index, value) => {
|
||||
this.setState({ selectedUser: value });
|
||||
this._getUserBalance(value);
|
||||
this.setState({ selectedUser: value }, () => {
|
||||
this._getUserBalance(value);
|
||||
});
|
||||
}}
|
||||
/>
|
||||
);
|
||||
@ -91,16 +97,12 @@ class PointsScreen extends PureComponent {
|
||||
});
|
||||
};
|
||||
|
||||
_promote = async (promote, currentAccount, getUserDataWithUsername) => {
|
||||
_promote = async (promote, currentAccount, getUserDataWithUsername, navigationParams) => {
|
||||
const { day, permlink, selectedUser } = this.state;
|
||||
let _author;
|
||||
let _permlink;
|
||||
|
||||
const seperatedPermlink = permlink.split('/');
|
||||
if (seperatedPermlink && seperatedPermlink.length > 0) {
|
||||
_author = seperatedPermlink[0];
|
||||
_permlink = seperatedPermlink[1];
|
||||
}
|
||||
const seperatedPermlink = permlink ? permlink.split('/') : get(navigationParams, 'permlink');
|
||||
const _author = get(seperatedPermlink, '[0]');
|
||||
const _permlink = get(seperatedPermlink, '[1]');
|
||||
|
||||
if (get(currentAccount, 'local.authType') === 'steemConnect') {
|
||||
// const user = selectedUser;
|
||||
@ -148,6 +150,7 @@ class PointsScreen extends PureComponent {
|
||||
isSCModalOpen,
|
||||
permlinkSuggestions,
|
||||
permlink,
|
||||
isValid,
|
||||
} = this.state;
|
||||
|
||||
return (
|
||||
@ -160,6 +163,7 @@ class PointsScreen extends PureComponent {
|
||||
promote,
|
||||
currentAccount,
|
||||
getUserDataWithUsername,
|
||||
navigationParams,
|
||||
}) => (
|
||||
<Fragment>
|
||||
<BasicHeader title={intl.formatMessage({ id: 'promote.title' })} />
|
||||
@ -195,7 +199,7 @@ class PointsScreen extends PureComponent {
|
||||
<TextInput
|
||||
style={styles.input}
|
||||
onChangeText={text => this._handleOnPermlinkChange(text)}
|
||||
value={permlink}
|
||||
value={permlink || get(navigationParams, 'permlink', '')}
|
||||
placeholder={intl.formatMessage({ id: 'promote.permlink' })}
|
||||
placeholderTextColor="#c1c5c7"
|
||||
autoCapitalize="none"
|
||||
@ -205,7 +209,11 @@ class PointsScreen extends PureComponent {
|
||||
<TouchableOpacity
|
||||
key={item}
|
||||
onPress={() =>
|
||||
this.setState({ permlink: item, permlinkSuggestions: [] })
|
||||
this.setState({
|
||||
permlink: item,
|
||||
isValid: true,
|
||||
permlinkSuggestions: [],
|
||||
})
|
||||
}
|
||||
>
|
||||
<Text style={styles.autocomplateItemText}>{item}</Text>
|
||||
@ -230,14 +238,17 @@ class PointsScreen extends PureComponent {
|
||||
values={[1, 2, 3, 7, 14]}
|
||||
LRpadding={50}
|
||||
activeValue={day}
|
||||
handleOnValueChange={day => this.setState({ day })}
|
||||
handleOnValueChange={_day => this.setState({ day: _day })}
|
||||
single
|
||||
/>
|
||||
</View>
|
||||
<View style={styles.bottomContent}>
|
||||
<MainButton
|
||||
style={styles.button}
|
||||
isDisable={isLoading}
|
||||
isDisable={
|
||||
(!permlink ? !get(navigationParams, 'permlink') : permlink) &&
|
||||
(isLoading || !isValid)
|
||||
}
|
||||
onPress={() => this.startActionSheet.current.show()}
|
||||
isLoading={isLoading}
|
||||
>
|
||||
@ -258,9 +269,8 @@ class PointsScreen extends PureComponent {
|
||||
cancelButtonIndex={1}
|
||||
destructiveButtonIndex={0}
|
||||
onPress={index => {
|
||||
index === 0
|
||||
? this._promote(promote, currentAccount, getUserDataWithUsername)
|
||||
: null;
|
||||
index === 0 &&
|
||||
this._promote(promote, currentAccount, getUserDataWithUsername, navigationParams);
|
||||
}}
|
||||
/>
|
||||
<Modal
|
||||
|
Loading…
Reference in New Issue
Block a user