meteor connect saga

This commit is contained in:
Guilherme Gazzo 2017-08-16 22:09:44 -03:00
commit 4300b87035
No known key found for this signature in database
GPG Key ID: 1F85C9AD922D0829
7 changed files with 17 additions and 17 deletions

View File

@ -3,7 +3,7 @@ import * as types from './actionsTypes';
export function loginRequest(credentials) { export function loginRequest(credentials) {
return { return {
type: types.LOGIN.REQUEST, type: types.LOGIN.REQUEST,
credentials ...credentials
}; };
} }

View File

@ -154,7 +154,7 @@ const messagesSchema = {
// } // }
}; };
Realm.clearTestState(); // Realm.clearTestState();
const realm = new Realm({ const realm = new Realm({
schema: [settingsSchema, serversSchema, subscriptionSchema, messagesSchema, usersSchema, attachment] schema: [settingsSchema, serversSchema, subscriptionSchema, messagesSchema, usersSchema, attachment]

View File

@ -106,10 +106,11 @@ const RocketChat = {
}); });
}, },
login(params, callback) { async login(params, callback) {
return new Promise((resolve, reject) => { await new Promise((resolve, reject) => {
Meteor._startLoggingIn(); Meteor._startLoggingIn();
Meteor.call('login', params, (err, result) => { console.log('meteor login', params);
return Meteor.call('login', params, (err, result) => {
Meteor._endLoggingIn(); Meteor._endLoggingIn();
Meteor._handleLoginCallback(err, result); Meteor._handleLoginCallback(err, result);
err ? reject(err) : resolve(result); err ? reject(err) : resolve(result);
@ -121,7 +122,6 @@ const RocketChat = {
}, },
loginWithPassword({ username, password, code }, callback) { loginWithPassword({ username, password, code }, callback) {
console.log('AQQQQQ');
let params = {}; let params = {};
const state = reduxStore.getState(); const state = reduxStore.getState();
@ -146,12 +146,10 @@ const RocketChat = {
} }
}; };
if (typeof username === 'string') { if (typeof username === 'string' && username.indexOf('@') !== -1) {
if (username.indexOf('@') !== -1) {
params.user = { email: username }; params.user = { email: username };
} }
} }
}
if (code) { if (code) {
params = { params = {

View File

@ -11,6 +11,7 @@ function connect(...args) {
const watchConnect = function* watchConnect() { const watchConnect = function* watchConnect() {
while (true) { while (true) {
yield take(METEOR.REQUEST); yield take(METEOR.REQUEST);
console.log('\n\n[METEOR CONNECTED]\n\n');
try { try {
const response = yield call(connect); const response = yield call(connect);
yield put(connectSuccess(response)); yield put(connectSuccess(response));

View File

@ -4,17 +4,20 @@ import * as types from '../actions/actionsTypes';
import { loginSuccess, loginFailure } from '../actions/login'; import { loginSuccess, loginFailure } from '../actions/login';
import RocketChat from '../lib/rocketchat'; import RocketChat from '../lib/rocketchat';
function loginCall(...args) { function loginCall(args) {
return RocketChat.loginWithPassword(...args); console.log(args);
return RocketChat.loginWithPassword(args);
} }
const watchLoginRequest = function* watchLoginRequest() { const watchLoginRequest = function* watchLoginRequest() {
while (true) { while (true) {
yield take(types.METEOR.SUCCESS); yield take(types.METEOR.SUCCESS);
console.log('\n\n[LOGIN METEOR CONNECTED]\n\n');
const payload = yield take(types.LOGIN.REQUEST); const payload = yield take(types.LOGIN.REQUEST);
try { try {
const response = yield call(loginCall, payload); const response = yield call(loginCall, payload);
yield put(loginSuccess(response)); yield put(loginSuccess(response));
console.log('\n\n[LOGIN SUCCESS]\n\n');
} catch (err) { } catch (err) {
yield put(loginFailure(err.status)); yield put(loginFailure(err.status));
} }

View File

@ -66,7 +66,6 @@ class LoginView extends React.Component {
submit = () => { submit = () => {
const { username, password, code } = this.state; const { username, password, code } = this.state;
this.props.loginRequest({ username, password, code }); this.props.loginRequest({ username, password, code });
console.log(this.props.loginRequest.toString());
// //
// //
// this.setState({ // this.setState({
@ -111,7 +110,7 @@ class LoginView extends React.Component {
render() { render() {
return ( return (
<KeyboardView style={styles.view} keyboardVerticalOffset={64}> <KeyboardView style={styles.view} keyboardVerticalOffset={64}>
{this.props.login.isFetching && <Text> INDO</Text>} {this.props.login.isFetching && <Text> LOGANDO</Text>}
<TextInput <TextInput
style={styles.input} style={styles.input}
onChangeText={username => this.setState({ username })} onChangeText={username => this.setState({ username })}

View File

@ -229,11 +229,11 @@ export default class RoomsListView extends React.Component {
} }
setInitialData = (props = this.props) => { setInitialData = (props = this.props) => {
// console.log(this.props);
this.props.connect();
props.navigator.setSubTitle({ props.navigator.setSubTitle({
subtitle: props.server subtitle: props.server
}); });
this.props.connect();
RocketChat.getUserToken().then((token) => { RocketChat.getUserToken().then((token) => {
if (!token) { if (!token) {
Navigation.showModal({ Navigation.showModal({
@ -242,7 +242,6 @@ export default class RoomsListView extends React.Component {
}); });
} }
// this.props.actions.connect();
const data = realm.objects('subscriptions').filtered('_server.id = $0', props.server).sorted('_updatedAt', true); const data = realm.objects('subscriptions').filtered('_server.id = $0', props.server).sorted('_updatedAt', true);