fixed promote bugs added routing from dropdown

This commit is contained in:
u-e 2019-07-20 01:29:10 +03:00
parent 82d176f99a
commit 3b6dfba2f3
7 changed files with 118 additions and 84 deletions

View File

@ -4,6 +4,7 @@ import { withNavigation } from 'react-navigation';
import { Share } from 'react-native'; import { Share } from 'react-native';
import ActionSheet from 'react-native-actionsheet'; import ActionSheet from 'react-native-actionsheet';
import { injectIntl } from 'react-intl'; import { injectIntl } from 'react-intl';
import get from 'lodash/get';
// Services and Actions // Services and Actions
import { reblog } from '../../../providers/steem/dsteem'; import { reblog } from '../../../providers/steem/dsteem';
@ -57,7 +58,7 @@ class PostDropdownContainer extends PureComponent {
switch (item) { switch (item) {
case 'COPY LINK': case 'COPY LINK':
await writeToClipboard(getPostUrl(content.url)); await writeToClipboard(getPostUrl(get(content, 'url')));
this.alertTimer = setTimeout(() => { this.alertTimer = setTimeout(() => {
dispatch( dispatch(
toastNotification( toastNotification(
@ -78,8 +79,9 @@ class PostDropdownContainer extends PureComponent {
break; break;
case 'REPLY': case 'REPLY':
this._replyNavigation(); this._redirectToReply();
break; break;
case 'SHARE': case 'SHARE':
this.shareTimer = setTimeout(() => { this.shareTimer = setTimeout(() => {
this._share(); this._share();
@ -91,6 +93,10 @@ class PostDropdownContainer extends PureComponent {
this._addToBookmarks(); this._addToBookmarks();
break; break;
case 'PROMOTE':
this._redirectToPromote();
break;
default: default:
break; break;
} }
@ -98,7 +104,7 @@ class PostDropdownContainer extends PureComponent {
_share = () => { _share = () => {
const { content } = this.props; const { content } = this.props;
const postUrl = getPostUrl(content.url); const postUrl = getPostUrl(get(content, 'url'));
Share.share({ Share.share({
message: `${content.title} ${postUrl}`, message: `${content.title} ${postUrl}`,
@ -107,6 +113,7 @@ class PostDropdownContainer extends PureComponent {
_addToBookmarks = () => { _addToBookmarks = () => {
const { content, currentAccount, dispatch, intl } = this.props; const { content, currentAccount, dispatch, intl } = this.props;
addBookmark(currentAccount.name, content.author, content.permlink) addBookmark(currentAccount.name, content.author, content.permlink)
.then(() => { .then(() => {
dispatch( dispatch(
@ -157,7 +164,7 @@ class PostDropdownContainer extends PureComponent {
} }
}; };
_replyNavigation = () => { _redirectToReply = () => {
const { content, fetchPost, isLoggedIn, navigation } = this.props; const { content, fetchPost, isLoggedIn, navigation } = this.props;
if (isLoggedIn) { 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() { render() {
const { intl, currentAccount, content, isHideReblogOption } = this.props; const { intl, currentAccount, content, isHideReblogOption } = this.props;
let _OPTIONS = OPTIONS; let _OPTIONS = OPTIONS;

View File

@ -12,7 +12,7 @@ export default EStyleSheet.create({
textAlignVertical: 'center', textAlignVertical: 'center',
textAlign: 'center', textAlign: 'center',
fontWeight: 'normal', fontWeight: 'normal',
color: '$primaryLightBackground', color: '$primaryDarkGray',
}, },
line: { line: {
width: 14, width: 14,

View File

@ -260,7 +260,8 @@
"reblog": "reblog", "reblog": "reblog",
"reply": "reply", "reply": "reply",
"share": "share", "share": "share",
"bookmarks": "add to bookmarks" "bookmarks": "add to bookmarks",
"promote": "promote"
}, },
"deep_link": { "deep_link": {
"no_existing_user": "No existing user", "no_existing_user": "No existing user",

View File

@ -7,6 +7,7 @@ const search = axios.create({
Authorization: Config.SEARCH_API_TOKEN, Authorization: Config.SEARCH_API_TOKEN,
'Content-Type': 'application/json', 'Content-Type': 'application/json',
}, },
// timeout: 500,
}); });
export default search; export default search;

View File

@ -1 +1 @@
export default ['copy', 'reblog', 'reply', 'share', 'bookmarks']; export default ['copy', 'reblog', 'reply', 'share', 'bookmarks', 'promote'];

View File

@ -1,22 +1,22 @@
import React, { Component } from "react"; import { Component } from 'react';
import { Alert } from "react-native"; import { Alert } from 'react-native';
import { connect } from "react-redux"; import { connect } from 'react-redux';
import get from "lodash/get"; import get from 'lodash/get';
import { injectIntl } from "react-intl"; import { injectIntl } from 'react-intl';
import { withNavigation } from "react-navigation"; import { withNavigation } from 'react-navigation';
// Services and Actions // Services and Actions
import { getUser, getUserPoints, claim } from "../providers/esteem/ePoint"; import { getUser, getUserPoints, claim } from '../providers/esteem/ePoint';
import { openPinCodeModal } from "../redux/actions/applicationActions"; import { openPinCodeModal } from '../redux/actions/applicationActions';
import { promote, getAccount } from "../providers/steem/dsteem"; import { promote, getAccount } from '../providers/steem/dsteem';
import { getUserDataWithUsername } from "../realm/realm"; import { getUserDataWithUsername } from '../realm/realm';
import { toastNotification } from "../redux/actions/uiAction"; import { toastNotification } from '../redux/actions/uiAction';
// Constant // Constant
import POINTS from "../constants/options/points"; import POINTS from '../constants/options/points';
// Constants // Constants
import ROUTES from "../constants/routeNames"; import ROUTES from '../constants/routeNames';
/* /*
* Props Name Description Value * Props Name Description Value
@ -32,33 +32,37 @@ class PointsContainer extends Component {
userActivities: null, userActivities: null,
refreshing: false, refreshing: false,
isClaiming: false, isClaiming: false,
isLoading: true isLoading: true,
navigationParams: {},
}; };
} }
// Component Life Cycle Functions // Component Life Cycle Functions
componentDidMount() { componentDidMount() {
const { username, isConnected } = this.props; const { username, isConnected, navigation } = this.props;
if (isConnected) { if (isConnected) {
this._fetchuserPointActivities(username); this._fetchuserPointActivities(username);
this.fetchInterval = setInterval( this.fetchInterval = setInterval(this._fetchuserPointActivities, 6 * 60 * 1000);
this._fetchuserPointActivities, }
6 * 60 * 1000
); if (get(navigation, 'state.params', null)) {
const navigationParams = get(navigation, 'state.params');
this.setState({ navigationParams });
} }
} }
componentWillReceiveProps(nextProps) { componentWillReceiveProps(nextProps) {
const { username } = this.props; const { username } = this.props;
const _username = get(nextProps, 'username');
if ( if (
nextProps.isConnected && nextProps.isConnected &&
((nextProps.activeBottomTab === ROUTES.TABBAR.POINTS && ((nextProps.activeBottomTab === ROUTES.TABBAR.POINTS && _username) ||
nextProps.username) || (_username !== username && _username))
(nextProps.username !== username && nextProps.username))
) { ) {
this._fetchuserPointActivities(nextProps.username); this._fetchuserPointActivities(_username);
} }
} }
@ -78,16 +82,16 @@ class PointsContainer extends Component {
case 0: case 0:
navigateTo = ROUTES.SCREENS.TRANSFER; navigateTo = ROUTES.SCREENS.TRANSFER;
navigateParams = { navigateParams = {
transferType: "points", transferType: 'points',
fundType: "POINT", fundType: 'POINT',
balance balance,
}; };
break; break;
case 1: case 1:
navigateTo = ROUTES.SCREENS.PROMOTE; navigateTo = ROUTES.SCREENS.PROMOTE;
navigateParams = { navigateParams = {
balance balance,
}; };
break; break;
@ -98,17 +102,17 @@ class PointsContainer extends Component {
dispatch( dispatch(
openPinCodeModal({ openPinCodeModal({
navigateTo, navigateTo,
navigateParams navigateParams,
}) }),
); );
}; };
_groomUserActivities = userActivities => _groomUserActivities = userActivities =>
userActivities.map(item => ({ userActivities.map(item => ({
...item, ...item,
icon: get(POINTS[get(item, "type")], "icon"), icon: get(POINTS[get(item, 'type')], 'icon'),
iconType: get(POINTS[get(item, "type")], "iconType"), iconType: get(POINTS[get(item, 'type')], 'iconType'),
textKey: get(POINTS[get(item, "type")], "textKey") textKey: get(POINTS[get(item, 'type')], 'textKey'),
})); }));
_fetchuserPointActivities = async username => { _fetchuserPointActivities = async username => {
@ -117,7 +121,7 @@ class PointsContainer extends Component {
await getUser(username) await getUser(username)
.then(userPoints => { .then(userPoints => {
const balance = Math.round(get(userPoints, "points") * 1000) / 1000; const balance = Math.round(get(userPoints, 'points') * 1000) / 1000;
this.setState({ userPoints, balance }); this.setState({ userPoints, balance });
}) })
.catch(err => { .catch(err => {
@ -128,7 +132,7 @@ class PointsContainer extends Component {
.then(userActivities => { .then(userActivities => {
if (Object.entries(userActivities).length !== 0) { if (Object.entries(userActivities).length !== 0) {
this.setState({ this.setState({
userActivities: this._groomUserActivities(userActivities) userActivities: this._groomUserActivities(userActivities),
}); });
} }
}) })
@ -138,14 +142,14 @@ class PointsContainer extends Component {
this.setState({ this.setState({
refreshing: false, refreshing: false,
isLoading: false isLoading: false,
}); });
}; };
_getUserBalance = async username => { _getUserBalance = async username => {
await getUser(username) await getUser(username)
.then(userPoints => { .then(userPoints => {
const balance = Math.round(get(userPoints, "points") * 1000) / 1000; const balance = Math.round(get(userPoints, 'points') * 1000) / 1000;
return balance; return balance;
}) })
.catch(err => { .catch(err => {
@ -166,8 +170,8 @@ class PointsContainer extends Component {
Alert.alert( Alert.alert(
`Fetching data from server failed, please try again or notify us at info@esteem.app \n${error.message.substr( `Fetching data from server failed, please try again or notify us at info@esteem.app \n${error.message.substr(
0, 0,
20 20,
)}` )}`,
); );
}); });
@ -181,30 +185,29 @@ class PointsContainer extends Component {
await promote(user || currentAccount, pinCode, duration, permlink, author) await promote(user || currentAccount, pinCode, duration, permlink, author)
.then(() => { .then(() => {
this.setState({ isLoading: false }); this.setState({ isLoading: false });
dispatch(
toastNotification(intl.formatMessage({ id: "alert.successful" }))
);
navigation.goBack(); navigation.goBack();
dispatch(toastNotification(intl.formatMessage({ id: 'alert.successful' })));
}) })
.catch(error => { .catch(error => {
Alert.alert( Alert.alert(
`Fetching data from server failed, please try again or notify us at info@esteem.app \n${error.message.substr( `Fetching data from server failed, please try again or notify us at info@esteem.app \n${error.message.substr(
0, 0,
20 20,
)}` )}`,
); );
}); });
}; };
render() { render() {
const { const {
balance,
isClaiming, isClaiming,
isDarkTheme, isDarkTheme,
isLoading, isLoading,
navigationParams,
refreshing, refreshing,
userActivities, userActivities,
userPoints, userPoints,
balance
} = this.state; } = this.state;
const { children, accounts, currentAccount } = this.props; const { children, accounts, currentAccount } = this.props;
@ -212,22 +215,23 @@ class PointsContainer extends Component {
children && children &&
children({ children({
accounts, accounts,
balance,
claimPoints: this._claimPoints,
currentAccount, currentAccount,
currentAccountName: currentAccount.name, currentAccountName: currentAccount.name,
claimPoints: this._claimPoints,
fetchUserActivity: this._fetchuserPointActivities, fetchUserActivity: this._fetchuserPointActivities,
getAccount,
getUserBalance: this._getUserBalance,
getUserDataWithUsername,
handleOnPressTransfer: this._handleOnPressTransfer,
isClaiming, isClaiming,
isDarkTheme, isDarkTheme,
isLoading, isLoading,
navigationParams,
promote: this._promote,
refreshing, refreshing,
userActivities, userActivities,
userPoints, userPoints,
handleOnPressTransfer: this._handleOnPressTransfer,
balance,
getUserBalance: this._getUserBalance,
promote: this._promote,
getAccount,
getUserDataWithUsername
}) })
); );
} }
@ -240,9 +244,7 @@ const mapStateToProps = state => ({
isConnected: state.application.isConnected, isConnected: state.application.isConnected,
accounts: state.account.otherAccounts, accounts: state.account.otherAccounts,
currentAccount: state.account.currentAccount, currentAccount: state.account.currentAccount,
pinCode: state.account.pin pinCode: state.application.pin,
}); });
export default withNavigation( export default withNavigation(connect(mapStateToProps)(injectIntl(PointsContainer)));
connect(mapStateToProps)(injectIntl(PointsContainer))
);

View File

@ -42,6 +42,7 @@ class PointsScreen extends PureComponent {
isSCModalOpen: false, isSCModalOpen: false,
SCPath: '', SCPath: '',
permlinkSuggestions: [], permlinkSuggestions: [],
isValid: false,
}; };
this.startActionSheet = React.createRef(); this.startActionSheet = React.createRef();
@ -52,13 +53,17 @@ class PointsScreen extends PureComponent {
// Component Functions // Component Functions
_handleOnPermlinkChange = async text => { _handleOnPermlinkChange = async text => {
searchPath(text).then(res => { if (text && text.length > 0) {
this.setState({ permlinkSuggestions: res && res.length > 10 ? res.slice(0, 7) : res }); 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>; _renderDescription = text => <Text style={styles.description}>{text}</Text>;
@ -74,8 +79,9 @@ class PointsScreen extends PureComponent {
defaultText={currentAccountName} defaultText={currentAccountName}
selectedOptionIndex={accounts.findIndex(item => item.username === currentAccountName)} selectedOptionIndex={accounts.findIndex(item => item.username === currentAccountName)}
onSelect={(index, value) => { onSelect={(index, value) => {
this.setState({ selectedUser: value }); this.setState({ selectedUser: value }, () => {
this._getUserBalance(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; const { day, permlink, selectedUser } = this.state;
let _author;
let _permlink;
const seperatedPermlink = permlink.split('/'); const seperatedPermlink = permlink ? permlink.split('/') : get(navigationParams, 'permlink');
if (seperatedPermlink && seperatedPermlink.length > 0) { const _author = get(seperatedPermlink, '[0]');
_author = seperatedPermlink[0]; const _permlink = get(seperatedPermlink, '[1]');
_permlink = seperatedPermlink[1];
}
if (get(currentAccount, 'local.authType') === 'steemConnect') { if (get(currentAccount, 'local.authType') === 'steemConnect') {
// const user = selectedUser; // const user = selectedUser;
@ -148,6 +150,7 @@ class PointsScreen extends PureComponent {
isSCModalOpen, isSCModalOpen,
permlinkSuggestions, permlinkSuggestions,
permlink, permlink,
isValid,
} = this.state; } = this.state;
return ( return (
@ -160,6 +163,7 @@ class PointsScreen extends PureComponent {
promote, promote,
currentAccount, currentAccount,
getUserDataWithUsername, getUserDataWithUsername,
navigationParams,
}) => ( }) => (
<Fragment> <Fragment>
<BasicHeader title={intl.formatMessage({ id: 'promote.title' })} /> <BasicHeader title={intl.formatMessage({ id: 'promote.title' })} />
@ -195,7 +199,7 @@ class PointsScreen extends PureComponent {
<TextInput <TextInput
style={styles.input} style={styles.input}
onChangeText={text => this._handleOnPermlinkChange(text)} onChangeText={text => this._handleOnPermlinkChange(text)}
value={permlink} value={permlink || get(navigationParams, 'permlink', '')}
placeholder={intl.formatMessage({ id: 'promote.permlink' })} placeholder={intl.formatMessage({ id: 'promote.permlink' })}
placeholderTextColor="#c1c5c7" placeholderTextColor="#c1c5c7"
autoCapitalize="none" autoCapitalize="none"
@ -205,7 +209,11 @@ class PointsScreen extends PureComponent {
<TouchableOpacity <TouchableOpacity
key={item} key={item}
onPress={() => onPress={() =>
this.setState({ permlink: item, permlinkSuggestions: [] }) this.setState({
permlink: item,
isValid: true,
permlinkSuggestions: [],
})
} }
> >
<Text style={styles.autocomplateItemText}>{item}</Text> <Text style={styles.autocomplateItemText}>{item}</Text>
@ -230,14 +238,17 @@ class PointsScreen extends PureComponent {
values={[1, 2, 3, 7, 14]} values={[1, 2, 3, 7, 14]}
LRpadding={50} LRpadding={50}
activeValue={day} activeValue={day}
handleOnValueChange={day => this.setState({ day })} handleOnValueChange={_day => this.setState({ day: _day })}
single single
/> />
</View> </View>
<View style={styles.bottomContent}> <View style={styles.bottomContent}>
<MainButton <MainButton
style={styles.button} style={styles.button}
isDisable={isLoading} isDisable={
(!permlink ? !get(navigationParams, 'permlink') : permlink) &&
(isLoading || !isValid)
}
onPress={() => this.startActionSheet.current.show()} onPress={() => this.startActionSheet.current.show()}
isLoading={isLoading} isLoading={isLoading}
> >
@ -258,9 +269,8 @@ class PointsScreen extends PureComponent {
cancelButtonIndex={1} cancelButtonIndex={1}
destructiveButtonIndex={0} destructiveButtonIndex={0}
onPress={index => { onPress={index => {
index === 0 index === 0 &&
? this._promote(promote, currentAccount, getUserDataWithUsername) this._promote(promote, currentAccount, getUserDataWithUsername, navigationParams);
: null;
}} }}
/> />
<Modal <Modal