mirror of
https://github.com/ecency/ecency-mobile.git
synced 2024-12-22 12:51:42 +03:00
enhanced routes to post screen
This commit is contained in:
parent
ea8977067a
commit
625c72456e
@ -1,28 +1,34 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { View, Text, TouchableOpacity } from 'react-native';
|
import { View, Text, TouchableOpacity } from 'react-native';
|
||||||
import { withNavigation } from 'react-navigation';
|
import { withNavigation } from 'react-navigation';
|
||||||
|
import get from 'lodash/get';
|
||||||
import { default as ROUTES } from '../../../constants/routeNames';
|
import { default as ROUTES } from '../../../constants/routeNames';
|
||||||
|
|
||||||
|
|
||||||
import styles from './parentPostStyles';
|
import styles from './parentPostStyles';
|
||||||
|
|
||||||
const ParentPost = ({ post, navigation }) => (
|
const ParentPost = (props) => {
|
||||||
<View style={styles.container}>
|
const { navigation, post } = props;
|
||||||
<TouchableOpacity
|
|
||||||
onPress={() => (navigation && navigation.navigate
|
return (
|
||||||
? navigation.navigate({
|
<View style={styles.container}>
|
||||||
routeName: ROUTES.SCREENS.POST,
|
<TouchableOpacity
|
||||||
params: {
|
onPress={() => (get(navigation, 'navigate')
|
||||||
content: post,
|
? navigation.navigate({
|
||||||
},
|
routeName: ROUTES.SCREENS.POST,
|
||||||
key: post.permlink,
|
params: {
|
||||||
})
|
content: post,
|
||||||
: null)
|
},
|
||||||
|
key: post.permlink,
|
||||||
|
})
|
||||||
|
: null)
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
<Text style={styles.title}>{post.title}</Text>
|
<Text style={styles.title}>{get(post, 'title')}</Text>
|
||||||
<Text style={styles.description}>{post.summary}</Text>
|
<Text style={styles.description}>{get(post, 'summary')}</Text>
|
||||||
</TouchableOpacity>
|
</TouchableOpacity>
|
||||||
</View>
|
</View>
|
||||||
);
|
);
|
||||||
|
};
|
||||||
|
|
||||||
export default withNavigation(ParentPost);
|
export default withNavigation(ParentPost);
|
||||||
|
@ -7,7 +7,7 @@ import HTML from 'react-native-html-renderer';
|
|||||||
import { getParentsTagsRecursively } from 'react-native-html-renderer/src/HTMLUtils';
|
import { getParentsTagsRecursively } from 'react-native-html-renderer/src/HTMLUtils';
|
||||||
|
|
||||||
// Utils
|
// Utils
|
||||||
import { validateUsername } from '../../../../utils/user';
|
import { validateUsername } from '../../../../utils/user';
|
||||||
|
|
||||||
// Styles
|
// Styles
|
||||||
import styles from './postBodyStyles';
|
import styles from './postBodyStyles';
|
||||||
@ -94,14 +94,16 @@ class PostBody extends PureComponent {
|
|||||||
_handleOnPostPress = (permlink, author) => {
|
_handleOnPostPress = (permlink, author) => {
|
||||||
const { navigation } = this.props;
|
const { navigation } = this.props;
|
||||||
|
|
||||||
navigation.navigate({
|
if (permlink) {
|
||||||
routeName: ROUTES.SCREENS.POST,
|
navigation.navigate({
|
||||||
params: {
|
routeName: ROUTES.SCREENS.POST,
|
||||||
author,
|
params: {
|
||||||
permlink,
|
author,
|
||||||
},
|
permlink,
|
||||||
key: permlink,
|
},
|
||||||
});
|
key: permlink,
|
||||||
|
});
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
_handleOnUserPress = (username) => {
|
_handleOnUserPress = (username) => {
|
||||||
|
@ -117,13 +117,15 @@ class DraftsContainer extends Component {
|
|||||||
_handleOnBookarkPress = (permlink, author) => {
|
_handleOnBookarkPress = (permlink, author) => {
|
||||||
const { navigation } = this.props;
|
const { navigation } = this.props;
|
||||||
|
|
||||||
navigation.navigate({
|
if (permlink && author) {
|
||||||
routeName: ROUTES.SCREENS.POST,
|
navigation.navigate({
|
||||||
params: {
|
routeName: ROUTES.SCREENS.POST,
|
||||||
permlink,
|
params: {
|
||||||
author,
|
permlink,
|
||||||
},
|
author,
|
||||||
});
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
_sortData = data => data.sort((a, b) => {
|
_sortData = data => data.sort((a, b) => {
|
||||||
|
@ -359,7 +359,7 @@ class EditorContainer extends Component {
|
|||||||
navigation.navigate({
|
navigation.navigate({
|
||||||
routeName: ROUTES.SCREENS.POST,
|
routeName: ROUTES.SCREENS.POST,
|
||||||
params: {
|
params: {
|
||||||
author: currentAccount.name,
|
author: get(currentAccount, 'name'),
|
||||||
permlink,
|
permlink,
|
||||||
isNewPost: true,
|
isNewPost: true,
|
||||||
},
|
},
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import React, { Component } from 'react';
|
import React, { Component } from 'react';
|
||||||
import { connect } from 'react-redux';
|
import { connect } from 'react-redux';
|
||||||
|
import get from 'lodash/get';
|
||||||
|
|
||||||
// Actions and Services
|
// Actions and Services
|
||||||
import { getActivities, markActivityAsRead } from '../../../providers/esteem/esteem';
|
import { getActivities, markActivityAsRead } from '../../../providers/esteem/esteem';
|
||||||
@ -61,6 +62,9 @@ class NotificationContainer extends Component {
|
|||||||
|
|
||||||
_navigateToNotificationRoute = (data) => {
|
_navigateToNotificationRoute = (data) => {
|
||||||
const { navigation, username, dispatch } = this.props;
|
const { navigation, username, dispatch } = this.props;
|
||||||
|
const type = get(data, 'type');
|
||||||
|
const permlink = get(data, 'permlink');
|
||||||
|
const author = get(data, 'author');
|
||||||
let routeName;
|
let routeName;
|
||||||
let params;
|
let params;
|
||||||
let key;
|
let key;
|
||||||
@ -68,30 +72,32 @@ class NotificationContainer extends Component {
|
|||||||
dispatch(updateUnreadActivityCount(result.unread));
|
dispatch(updateUnreadActivityCount(result.unread));
|
||||||
});
|
});
|
||||||
|
|
||||||
if (data.permlink) {
|
if (permlink) {
|
||||||
routeName = ROUTES.SCREENS.POST;
|
routeName = ROUTES.SCREENS.POST;
|
||||||
key = data.permlink;
|
key = permlink;
|
||||||
params = {
|
params = {
|
||||||
author: data.author,
|
author,
|
||||||
permlink: data.permlink,
|
permlink,
|
||||||
isHasParentPost: data.parent_author && data.parent_permlink,
|
isHasParentPost: get(data, 'parent_permlink'),
|
||||||
};
|
};
|
||||||
} else if (data.type === 'follow') {
|
} else if (type === 'follow') {
|
||||||
routeName = ROUTES.SCREENS.PROFILE;
|
routeName = ROUTES.SCREENS.PROFILE;
|
||||||
key = data.follower;
|
key = get(data, 'follower');
|
||||||
params = {
|
params = {
|
||||||
username: data.follower,
|
username: get(data, 'follower'),
|
||||||
};
|
};
|
||||||
} else if (data.type === 'transfer') {
|
} else if (type === 'transfer') {
|
||||||
routeName = ROUTES.TABBAR.PROFILE;
|
routeName = ROUTES.TABBAR.PROFILE;
|
||||||
params = { activePage: 2 };
|
params = { activePage: 2 };
|
||||||
}
|
}
|
||||||
|
|
||||||
navigation.navigate({
|
if (routeName) {
|
||||||
routeName,
|
navigation.navigate({
|
||||||
params,
|
routeName,
|
||||||
key,
|
params,
|
||||||
});
|
key,
|
||||||
|
});
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
_readAllNotification = () => {
|
_readAllNotification = () => {
|
||||||
|
@ -5,6 +5,7 @@ import {
|
|||||||
import { connect } from 'react-redux';
|
import { connect } from 'react-redux';
|
||||||
import Push from 'appcenter-push';
|
import Push from 'appcenter-push';
|
||||||
import { injectIntl } from 'react-intl';
|
import { injectIntl } from 'react-intl';
|
||||||
|
import get from 'lodash/get';
|
||||||
|
|
||||||
// Actions & Services
|
// Actions & Services
|
||||||
import { openPinCodeModal } from '../../../redux/actions/applicationActions';
|
import { openPinCodeModal } from '../../../redux/actions/applicationActions';
|
||||||
@ -72,13 +73,15 @@ const RootContainer = () => (WrappedComponent) => {
|
|||||||
const routeParams = url.indexOf('/') > -1 ? url.split('/') : [url];
|
const routeParams = url.indexOf('/') > -1 ? url.split('/') : [url];
|
||||||
|
|
||||||
[, permlink] = routeParams;
|
[, permlink] = routeParams;
|
||||||
author = routeParams[0].indexOf('@') > -1 ? routeParams[0].replace('@', '') : routeParams[0];
|
author = routeParams && routeParams.length > 0
|
||||||
|
&& routeParams[0].indexOf('@') > -1
|
||||||
|
? routeParams[0].replace('@', '') : routeParams[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (author && permlink) {
|
if (author && permlink) {
|
||||||
await getPost(author, permlink, currentAccountUsername)
|
await getPost(author, permlink, currentAccountUsername)
|
||||||
.then((result) => {
|
.then((result) => {
|
||||||
if (result && result.title) {
|
if (get(result, 'title')) {
|
||||||
content = result;
|
content = result;
|
||||||
} else {
|
} else {
|
||||||
this._handleAlert(
|
this._handleAlert(
|
||||||
@ -111,10 +114,10 @@ const RootContainer = () => (WrappedComponent) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
routeName = ROUTES.SCREENS.PROFILE;
|
routeName = ROUTES.SCREENS.PROFILE;
|
||||||
params = { username: profile.name, reputation: profile.reputation };
|
params = { username: get(profile, 'name'), reputation: get(profile, 'reputation') };
|
||||||
}
|
}
|
||||||
|
|
||||||
if (profile || content) {
|
if (routeName && (profile || content)) {
|
||||||
this.navigationTimeout = setTimeout(() => {
|
this.navigationTimeout = setTimeout(() => {
|
||||||
clearTimeout(this.navigationTimeout);
|
clearTimeout(this.navigationTimeout);
|
||||||
navigation.navigate({
|
navigation.navigate({
|
||||||
@ -168,18 +171,27 @@ const RootContainer = () => (WrappedComponent) => {
|
|||||||
|
|
||||||
Push.setListener({
|
Push.setListener({
|
||||||
onPushNotificationReceived(pushNotification) {
|
onPushNotificationReceived(pushNotification) {
|
||||||
const push = pushNotification.customProperties;
|
const push = get(pushNotification, 'customProperties');
|
||||||
|
const permlink1 = get(push, 'permlink1');
|
||||||
|
const permlink2 = get(push, 'permlink2');
|
||||||
|
const permlink3 = get(push, 'permlink3');
|
||||||
|
const parentPermlink1 = get(push, 'parent_permlink1');
|
||||||
|
const parentPermlink2 = get(push, 'parent_permlink2');
|
||||||
|
const parentPermlink3 = get(push, 'parent_permlink3');
|
||||||
|
|
||||||
|
if (parentPermlink1 || permlink1) {
|
||||||
|
const fullParentPermlink = `${parentPermlink1}${parentPermlink2}${parentPermlink3}`;
|
||||||
|
const fullPermlink = `${permlink1}${permlink2}${permlink3}`;
|
||||||
|
|
||||||
if (push.parent_permlink1 || push.permlink1) {
|
|
||||||
params = {
|
params = {
|
||||||
author: push.parent_permlink1 ? push.parent_author : push.target,
|
author: parentPermlink1 ? get(push, 'parent_author') : get(push, 'target'),
|
||||||
permlink: push.parent_permlink1
|
permlink: parentPermlink1
|
||||||
? `${push.parent_permlink1}${push.parent_permlink2}${push.parent_permlink3}`
|
? fullParentPermlink
|
||||||
: `${push.permlink1}${push.permlink2}${push.permlink3}`,
|
: fullPermlink,
|
||||||
};
|
};
|
||||||
key = push.parent_permlink1
|
key = parentPermlink1
|
||||||
? `${push.parent_permlink1}${push.parent_permlink2}${push.parent_permlink3}`
|
? fullParentPermlink
|
||||||
: `${push.permlink1}${push.permlink2}${push.permlink3}`;
|
: fullPermlink;
|
||||||
routeName = ROUTES.SCREENS.POST;
|
routeName = ROUTES.SCREENS.POST;
|
||||||
} else {
|
} else {
|
||||||
params = {
|
params = {
|
||||||
@ -189,7 +201,8 @@ const RootContainer = () => (WrappedComponent) => {
|
|||||||
routeName = ROUTES.SCREENS.PROFILE;
|
routeName = ROUTES.SCREENS.PROFILE;
|
||||||
}
|
}
|
||||||
|
|
||||||
setTimeout(() => {
|
this.pushNavigationTimeout = setTimeout(() => {
|
||||||
|
clearTimeout(this.pushNavigationTimeout);
|
||||||
navigation.navigate({ routeName, params, key });
|
navigation.navigate({ routeName, params, key });
|
||||||
}, 4000);
|
}, 4000);
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user