From 388746301a62ddff9a9d629334137aa57c4244a9 Mon Sep 17 00:00:00 2001 From: Kailash Bhalaki Date: Fri, 26 Jul 2019 17:19:15 +0530 Subject: [PATCH 1/5] Add Webviews for Articles. --- app/index.js | 11 ++++++++- app/lib/rocketchat.js | 8 +++++++ app/views/ArticlesView/index.js | 41 +++++++++++++++++++++++++++++++++ app/views/ProfileView/index.js | 28 ++++++++++++++++++---- app/views/RoomInfoView/index.js | 34 ++++++++++++++++++++++++++- 5 files changed, 116 insertions(+), 6 deletions(-) create mode 100644 app/views/ArticlesView/index.js diff --git a/app/index.js b/app/index.js index 7b30aa8be8..9d923030d7 100644 --- a/app/index.js +++ b/app/index.js @@ -171,6 +171,14 @@ const AdminPanelStack = createStackNavigator({ defaultNavigationOptions: defaultHeader }); +const ArticlesStack = createStackNavigator({ + ArticlesView: { + getScreen: () => require('./views/ArticlesView').default + } +}, { + defaultNavigationOptions: defaultHeader +}); + SettingsStack.navigationOptions = ({ navigation }) => { let drawerLockMode = 'unlocked'; if (navigation.state.index > 0) { @@ -185,7 +193,8 @@ const ChatsDrawer = createDrawerNavigator({ ChatsStack, ProfileStack, SettingsStack, - AdminPanelStack + AdminPanelStack, + ArticlesStack }, { contentComponent: Sidebar }); diff --git a/app/lib/rocketchat.js b/app/lib/rocketchat.js index 7b3e75ae55..bc3b8f0551 100644 --- a/app/lib/rocketchat.js +++ b/app/lib/rocketchat.js @@ -718,6 +718,14 @@ const RocketChat = { // RC 0.55.0 return this.sdk.post('users.resetAvatar', { userId }); }, + redirectToUserArticles(userId) { + // Method added in https://github.com/WideChat/Rocket.Chat/pull/65 + return this.sdk.methodCall('redirectToUsersArticles', userId); + }, + redirectUserToArticles(token) { + // Method added in https://github.com/WideChat/Rocket.Chat/pull/63 + return this.sdk.methodCall('redirectUserToArticles', token); + }, setAvatarFromService({ data, contentType = '', service = null }) { // RC 0.51.0 return this.sdk.methodCall('setAvatarFromService', data, contentType, service); diff --git a/app/views/ArticlesView/index.js b/app/views/ArticlesView/index.js new file mode 100644 index 0000000000..f7446837f8 --- /dev/null +++ b/app/views/ArticlesView/index.js @@ -0,0 +1,41 @@ +import React from 'react'; +import PropTypes from 'prop-types'; +import { WebView } from 'react-native-webview'; +import { SafeAreaView } from 'react-navigation'; +import { connect } from 'react-redux'; +import styles from '../Styles'; + +// import I18n from '../../i18n'; +import StatusBar from '../../containers/StatusBar'; +import { DrawerButton } from '../../containers/HeaderButton'; + +@connect(state => ({ + authToken: state.login.user && state.login.user.token +})) +export default class AdminPanelView extends React.Component { + static navigationOptions = ({ navigation }) => ({ + headerLeft: , + title: 'Articles' + }); + + static propTypes = { + navigation: PropTypes.object + } + + render() { + const { navigation } = this.props; + this.articlesLink = navigation.getParam('articlesLink'); + if (!this.articlesLink) { + return null; + } + return ( + + + + + ); + } +} diff --git a/app/views/ProfileView/index.js b/app/views/ProfileView/index.js index 12cae6503c..a69b00efa3 100644 --- a/app/views/ProfileView/index.js +++ b/app/views/ProfileView/index.js @@ -50,6 +50,7 @@ export default class ProfileView extends React.Component { }) static propTypes = { + navigation: PropTypes.object, baseUrl: PropTypes.string, user: PropTypes.object, Accounts_CustomFields: PropTypes.string, @@ -67,7 +68,8 @@ export default class ProfileView extends React.Component { avatarUrl: null, avatar: {}, avatarSuggestions: {}, - customFields: {} + customFields: {}, + articlesLink: '' } async componentDidMount() { @@ -102,11 +104,12 @@ export default class ProfileView extends React.Component { this.setState({ avatar }); } - init = (user) => { + init = async(user) => { const { user: userProps } = this.props; const { - name, username, emails, customFields + name, username, emails, customFields, token } = user || userProps; + const result = await RocketChat.redirectUserToArticles(token); this.setState({ name, @@ -116,7 +119,8 @@ export default class ProfileView extends React.Component { currentPassword: null, avatarUrl: null, avatar: {}, - customFields: customFields || {} + customFields: customFields || {}, + articlesLink: result ? result.link : '' }); } @@ -280,6 +284,14 @@ export default class ProfileView extends React.Component { ) + renderArticlesWebView = () => { + const { navigation } = this.props; + const { articlesLink } = this.state; + console.warn('link is', articlesLink); + navigation.navigate('ArticlesView', { articlesLink }); + } + + renderAvatarButtons = () => { const { avatarUrl, avatarSuggestions } = this.state; const { user, baseUrl } = this.props; @@ -404,6 +416,14 @@ export default class ProfileView extends React.Component { token={user.token} /> + +