From 9f31e2606e7310d4bc88cf36b8cc8c625d96d892 Mon Sep 17 00:00:00 2001 From: Rodrigo Nascimento Date: Wed, 9 Aug 2017 13:19:17 -0300 Subject: [PATCH] Improve app view flow --- .eslintignore | 1 + app/components/KeyboardView.js | 5 +- app/lib/meteor.js | 35 +++++++++--- app/lib/realm.js | 4 +- app/navigation.js | 61 +++++++++++++------- app/views/login.js | 17 ++---- app/views/roomsList.js | 87 ++++++++++++++++++++++++---- app/views/serverList.js | 101 +++++++++++++++------------------ 8 files changed, 203 insertions(+), 108 deletions(-) diff --git a/.eslintignore b/.eslintignore index c912533dd..29156ca82 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1 +1,2 @@ __tests__ +node_modules diff --git a/app/components/KeyboardView.js b/app/components/KeyboardView.js index 4e86fca66..ba1e50ea0 100644 --- a/app/components/KeyboardView.js +++ b/app/components/KeyboardView.js @@ -6,7 +6,10 @@ export default class KeyboardView extends React.PureComponent { static propTypes = { style: KeyboardAvoidingView.propTypes.style, keyboardVerticalOffset: PropTypes.number, - children: PropTypes.array.isRequired + children: PropTypes.oneOfType([ + PropTypes.arrayOf(PropTypes.node), + PropTypes.node + ]) } render() { diff --git a/app/lib/meteor.js b/app/lib/meteor.js index af0ac3e0d..917af4099 100644 --- a/app/lib/meteor.js +++ b/app/lib/meteor.js @@ -20,6 +20,27 @@ const RocketChat = { export default RocketChat; +Meteor.Accounts.onLogin(() => { + Meteor.call('subscriptions/get', (err, data) => { + if (err) { + console.error(err); + } + + realm.write(() => { + data.forEach((subscription) => { + // const subscription = { + // _id: item._id + // }; + // if (typeof item.value === 'string') { + // subscription.value = item.value; + // } + subscription._server = { id: RocketChat.currentServer }; + realm.create('subscriptions', subscription, true); + }); + }); + }); +}); + export function connect(cb) { const url = `${ RocketChat.currentServer }/websocket`; @@ -52,14 +73,12 @@ export function connect(cb) { Meteor.ddp.on('changed', (ddbMessage) => { console.log('changed', ddbMessage); if (ddbMessage.collection === 'stream-room-messages') { - setTimeout(() => { - realm.write(() => { - const message = ddbMessage.fields.args[0]; - message.temp = false; - message._server = { id: RocketChat.currentServer }; - realm.create('messages', message, true); - }); - }, 1000); + realm.write(() => { + const message = ddbMessage.fields.args[0]; + message.temp = false; + message._server = { id: RocketChat.currentServer }; + realm.create('messages', message, true); + }); } }); }); diff --git a/app/lib/realm.js b/app/lib/realm.js index a6c68ea2b..3ba3a6f6b 100644 --- a/app/lib/realm.js +++ b/app/lib/realm.js @@ -84,6 +84,6 @@ realm.write(() => { const allSettins = realm.objects('settings'); realm.delete(allSettins); - // realm.create('servers', {id: 'https://demo.rocket.chat', current: false}, true); - // realm.create('servers', {id: 'http://localhost:3000', current: false}, true); + // realm.create('servers', { id: 'https://demo.rocket.chat', current: false }, true); + // realm.create('servers', { id: 'http://localhost:3000', current: false }, true); }); diff --git a/app/navigation.js b/app/navigation.js index ab99e4f71..2913302ab 100644 --- a/app/navigation.js +++ b/app/navigation.js @@ -1,3 +1,5 @@ +import React from 'react'; +import { Button } from 'react-native'; import { StackNavigator } from 'react-navigation'; import LoginView from './views/login'; import NewServerView from './views/serverNew'; @@ -5,26 +7,14 @@ import ListServerView from './views/serverList'; import RoomsListView from './views/roomsList'; import RoomView from './views/room'; -const navigationOptions = { - // headerStyle: { - // backgroundColor: '#c1272d' - // }, - // headerTitleStyle: { - // color: '#fff' - // } -}; -export default new StackNavigator({ - ListServer: { - screen: ListServerView, - navigationOptions +const MainCardNavigator = StackNavigator({ + Rooms: { + screen: RoomsListView, + navigationOptions: ({ navigation }) => ({ + headerLeft: