mirror of
https://github.com/ecency/ecency-mobile.git
synced 2024-12-22 21:01:31 +03:00
enhanced routes to post screen
This commit is contained in:
parent
ea8977067a
commit
625c72456e
@ -1,14 +1,19 @@
|
|||||||
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) => {
|
||||||
|
const { navigation, post } = props;
|
||||||
|
|
||||||
|
return (
|
||||||
<View style={styles.container}>
|
<View style={styles.container}>
|
||||||
<TouchableOpacity
|
<TouchableOpacity
|
||||||
onPress={() => (navigation && navigation.navigate
|
onPress={() => (get(navigation, 'navigate')
|
||||||
? navigation.navigate({
|
? navigation.navigate({
|
||||||
routeName: ROUTES.SCREENS.POST,
|
routeName: ROUTES.SCREENS.POST,
|
||||||
params: {
|
params: {
|
||||||
@ -19,10 +24,11 @@ const ParentPost = ({ post, navigation }) => (
|
|||||||
: null)
|
: 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);
|
||||||
|
@ -94,6 +94,7 @@ class PostBody extends PureComponent {
|
|||||||
_handleOnPostPress = (permlink, author) => {
|
_handleOnPostPress = (permlink, author) => {
|
||||||
const { navigation } = this.props;
|
const { navigation } = this.props;
|
||||||
|
|
||||||
|
if (permlink) {
|
||||||
navigation.navigate({
|
navigation.navigate({
|
||||||
routeName: ROUTES.SCREENS.POST,
|
routeName: ROUTES.SCREENS.POST,
|
||||||
params: {
|
params: {
|
||||||
@ -102,6 +103,7 @@ class PostBody extends PureComponent {
|
|||||||
},
|
},
|
||||||
key: permlink,
|
key: permlink,
|
||||||
});
|
});
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
_handleOnUserPress = (username) => {
|
_handleOnUserPress = (username) => {
|
||||||
|
@ -117,6 +117,7 @@ class DraftsContainer extends Component {
|
|||||||
_handleOnBookarkPress = (permlink, author) => {
|
_handleOnBookarkPress = (permlink, author) => {
|
||||||
const { navigation } = this.props;
|
const { navigation } = this.props;
|
||||||
|
|
||||||
|
if (permlink && author) {
|
||||||
navigation.navigate({
|
navigation.navigate({
|
||||||
routeName: ROUTES.SCREENS.POST,
|
routeName: ROUTES.SCREENS.POST,
|
||||||
params: {
|
params: {
|
||||||
@ -124,6 +125,7 @@ class DraftsContainer extends Component {
|
|||||||
author,
|
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 };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (routeName) {
|
||||||
navigation.navigate({
|
navigation.navigate({
|
||||||
routeName,
|
routeName,
|
||||||
params,
|
params,
|
||||||
key,
|
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