client/src/sagas/index.js
author ymh <ymh.work@gmail.com>
Mon, 19 Jun 2017 17:30:03 +0200
changeset 54 fad489be9c77
parent 53 d8588379529e
child 55 a2761c5be551
permissions -rw-r--r--
add some config values
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
29
4cfeabef7d5e Store data in PouchDB.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
     1
import PouchDB from 'pouchdb'
44
3b20e2b584fe Introduce authentication through API.
Alexandre Segura <mex.zktk@gmail.com>
parents: 40
diff changeset
     2
import { put, take, takeLatest, all } from 'redux-saga/effects'
29
4cfeabef7d5e Store data in PouchDB.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
     3
import * as types from '../constants/actionTypes';
4cfeabef7d5e Store data in PouchDB.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
     4
import PouchDBFind from 'pouchdb-find';
4cfeabef7d5e Store data in PouchDB.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
     5
import Immutable from 'immutable';
44
3b20e2b584fe Introduce authentication through API.
Alexandre Segura <mex.zktk@gmail.com>
parents: 40
diff changeset
     6
import APIClient from '../APIClient';
54
fad489be9c77 add some config values
ymh <ymh.work@gmail.com>
parents: 53
diff changeset
     7
import config from '../config';
29
4cfeabef7d5e Store data in PouchDB.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
     8
4cfeabef7d5e Store data in PouchDB.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
     9
PouchDB.debug.disable();
4cfeabef7d5e Store data in PouchDB.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    10
PouchDB.plugin(PouchDBFind);
4cfeabef7d5e Store data in PouchDB.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    11
4cfeabef7d5e Store data in PouchDB.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    12
const sessionsDB = new PouchDB('sessions');
4cfeabef7d5e Store data in PouchDB.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    13
const notesDB = new PouchDB('notes');
4cfeabef7d5e Store data in PouchDB.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    14
notesDB.createIndex({
4cfeabef7d5e Store data in PouchDB.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    15
  index: { fields: ['session'] }
4cfeabef7d5e Store data in PouchDB.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    16
});
4cfeabef7d5e Store data in PouchDB.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    17
54
fad489be9c77 add some config values
ymh <ymh.work@gmail.com>
parents: 53
diff changeset
    18
const client = new APIClient(config.apiRootUrl);
44
3b20e2b584fe Introduce authentication through API.
Alexandre Segura <mex.zktk@gmail.com>
parents: 40
diff changeset
    19
29
4cfeabef7d5e Store data in PouchDB.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    20
// ---
4cfeabef7d5e Store data in PouchDB.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    21
4cfeabef7d5e Store data in PouchDB.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    22
export function* loadSessions() {
4cfeabef7d5e Store data in PouchDB.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    23
  const response = yield sessionsDB.allDocs({ include_docs: true })
4cfeabef7d5e Store data in PouchDB.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    24
  const sessions = response.rows.map(row => row.doc)
4cfeabef7d5e Store data in PouchDB.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    25
  yield put({ type: types.LOAD_SESSIONS, sessions: Immutable.List(sessions) })
4cfeabef7d5e Store data in PouchDB.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    26
}
4cfeabef7d5e Store data in PouchDB.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    27
4cfeabef7d5e Store data in PouchDB.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    28
export function* watchLoadSessions() {
4cfeabef7d5e Store data in PouchDB.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    29
  yield takeLatest(types.LOAD_SESSIONS_ASYNC, loadSessions)
4cfeabef7d5e Store data in PouchDB.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    30
}
4cfeabef7d5e Store data in PouchDB.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    31
4cfeabef7d5e Store data in PouchDB.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    32
// ---
4cfeabef7d5e Store data in PouchDB.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    33
4cfeabef7d5e Store data in PouchDB.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    34
export function* createSession(action) {
4cfeabef7d5e Store data in PouchDB.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    35
  const response = yield sessionsDB.put(action.session);
4cfeabef7d5e Store data in PouchDB.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    36
  // TODO Error control
4cfeabef7d5e Store data in PouchDB.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    37
  const session = Object.assign({}, action.session, { rev: response.rev });
4cfeabef7d5e Store data in PouchDB.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    38
  yield put({ type: types.CREATE_SESSION, session: session })
4cfeabef7d5e Store data in PouchDB.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    39
}
4cfeabef7d5e Store data in PouchDB.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    40
4cfeabef7d5e Store data in PouchDB.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    41
export function* watchCreateSession() {
4cfeabef7d5e Store data in PouchDB.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    42
  yield takeLatest(types.CREATE_SESSION_ASYNC, createSession)
4cfeabef7d5e Store data in PouchDB.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    43
}
4cfeabef7d5e Store data in PouchDB.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    44
4cfeabef7d5e Store data in PouchDB.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    45
// ---
4cfeabef7d5e Store data in PouchDB.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    46
30
4d93f4ed95bc Update session in PouchDB.
Alexandre Segura <mex.zktk@gmail.com>
parents: 29
diff changeset
    47
export function* updateSession(action) {
4d93f4ed95bc Update session in PouchDB.
Alexandre Segura <mex.zktk@gmail.com>
parents: 29
diff changeset
    48
4d93f4ed95bc Update session in PouchDB.
Alexandre Segura <mex.zktk@gmail.com>
parents: 29
diff changeset
    49
  const { _id } = action.session;
4d93f4ed95bc Update session in PouchDB.
Alexandre Segura <mex.zktk@gmail.com>
parents: 29
diff changeset
    50
  let session;
4d93f4ed95bc Update session in PouchDB.
Alexandre Segura <mex.zktk@gmail.com>
parents: 29
diff changeset
    51
40
7f940dbb60a6 Use yields instead of promises
ymh <ymh.work@gmail.com>
parents: 30
diff changeset
    52
  const doc = yield sessionsDB.get(_id);
7f940dbb60a6 Use yields instead of promises
ymh <ymh.work@gmail.com>
parents: 30
diff changeset
    53
  session = Object.assign({}, doc, action.values);
7f940dbb60a6 Use yields instead of promises
ymh <ymh.work@gmail.com>
parents: 30
diff changeset
    54
  const response = yield sessionsDB.put(session);
30
4d93f4ed95bc Update session in PouchDB.
Alexandre Segura <mex.zktk@gmail.com>
parents: 29
diff changeset
    55
4d93f4ed95bc Update session in PouchDB.
Alexandre Segura <mex.zktk@gmail.com>
parents: 29
diff changeset
    56
  yield put({
4d93f4ed95bc Update session in PouchDB.
Alexandre Segura <mex.zktk@gmail.com>
parents: 29
diff changeset
    57
    type: types.UPDATE_SESSION,
4d93f4ed95bc Update session in PouchDB.
Alexandre Segura <mex.zktk@gmail.com>
parents: 29
diff changeset
    58
    session: Object.assign({}, session, { rev: response.rev })
4d93f4ed95bc Update session in PouchDB.
Alexandre Segura <mex.zktk@gmail.com>
parents: 29
diff changeset
    59
  })
4d93f4ed95bc Update session in PouchDB.
Alexandre Segura <mex.zktk@gmail.com>
parents: 29
diff changeset
    60
}
4d93f4ed95bc Update session in PouchDB.
Alexandre Segura <mex.zktk@gmail.com>
parents: 29
diff changeset
    61
4d93f4ed95bc Update session in PouchDB.
Alexandre Segura <mex.zktk@gmail.com>
parents: 29
diff changeset
    62
export function* watchUpdateSession() {
4d93f4ed95bc Update session in PouchDB.
Alexandre Segura <mex.zktk@gmail.com>
parents: 29
diff changeset
    63
  yield takeLatest(types.UPDATE_SESSION_ASYNC, updateSession)
4d93f4ed95bc Update session in PouchDB.
Alexandre Segura <mex.zktk@gmail.com>
parents: 29
diff changeset
    64
}
4d93f4ed95bc Update session in PouchDB.
Alexandre Segura <mex.zktk@gmail.com>
parents: 29
diff changeset
    65
4d93f4ed95bc Update session in PouchDB.
Alexandre Segura <mex.zktk@gmail.com>
parents: 29
diff changeset
    66
// ---
4d93f4ed95bc Update session in PouchDB.
Alexandre Segura <mex.zktk@gmail.com>
parents: 29
diff changeset
    67
29
4cfeabef7d5e Store data in PouchDB.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    68
export function* addNote(action) {
4cfeabef7d5e Store data in PouchDB.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    69
  const response = yield notesDB.put(action.note);
4cfeabef7d5e Store data in PouchDB.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    70
  // TODO Error control
4cfeabef7d5e Store data in PouchDB.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    71
  const note = Object.assign({}, action.note, { rev: response.rev });
4cfeabef7d5e Store data in PouchDB.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    72
  yield put({ type: types.ADD_NOTE, note: note })
4cfeabef7d5e Store data in PouchDB.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    73
}
4cfeabef7d5e Store data in PouchDB.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    74
4cfeabef7d5e Store data in PouchDB.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    75
export function* watchAddNote() {
4cfeabef7d5e Store data in PouchDB.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    76
  yield takeLatest(types.ADD_NOTE_ASYNC, addNote)
4cfeabef7d5e Store data in PouchDB.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    77
}
4cfeabef7d5e Store data in PouchDB.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    78
4cfeabef7d5e Store data in PouchDB.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    79
// ---
4cfeabef7d5e Store data in PouchDB.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    80
4cfeabef7d5e Store data in PouchDB.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    81
export function* loadNotesBySession(action) {
4cfeabef7d5e Store data in PouchDB.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    82
  const result = yield notesDB.find({
4cfeabef7d5e Store data in PouchDB.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    83
    selector: { session: action.session._id },
4cfeabef7d5e Store data in PouchDB.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    84
    // sort: ['name']
4cfeabef7d5e Store data in PouchDB.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    85
  });
4cfeabef7d5e Store data in PouchDB.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    86
  yield put({ type: types.LOAD_NOTES_BY_SESSION, notes: Immutable.List(result.docs) })
4cfeabef7d5e Store data in PouchDB.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    87
}
4cfeabef7d5e Store data in PouchDB.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    88
4cfeabef7d5e Store data in PouchDB.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    89
export function* watchLoadNotesBySession() {
4cfeabef7d5e Store data in PouchDB.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    90
  yield takeLatest(types.LOAD_NOTES_BY_SESSION_ASYNC, loadNotesBySession)
4cfeabef7d5e Store data in PouchDB.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    91
}
4cfeabef7d5e Store data in PouchDB.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    92
4cfeabef7d5e Store data in PouchDB.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    93
// ---
4cfeabef7d5e Store data in PouchDB.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    94
44
3b20e2b584fe Introduce authentication through API.
Alexandre Segura <mex.zktk@gmail.com>
parents: 40
diff changeset
    95
export function* watchLoginSubmit() {
3b20e2b584fe Introduce authentication through API.
Alexandre Segura <mex.zktk@gmail.com>
parents: 40
diff changeset
    96
  while (true) {
3b20e2b584fe Introduce authentication through API.
Alexandre Segura <mex.zktk@gmail.com>
parents: 40
diff changeset
    97
    const { username, password } = yield take(types.AUTH_LOGIN_SUBMIT);
3b20e2b584fe Introduce authentication through API.
Alexandre Segura <mex.zktk@gmail.com>
parents: 40
diff changeset
    98
    yield put({ type: types.AUTH_LOGIN_REQUEST, username, password });
3b20e2b584fe Introduce authentication through API.
Alexandre Segura <mex.zktk@gmail.com>
parents: 40
diff changeset
    99
  }
3b20e2b584fe Introduce authentication through API.
Alexandre Segura <mex.zktk@gmail.com>
parents: 40
diff changeset
   100
}
3b20e2b584fe Introduce authentication through API.
Alexandre Segura <mex.zktk@gmail.com>
parents: 40
diff changeset
   101
3b20e2b584fe Introduce authentication through API.
Alexandre Segura <mex.zktk@gmail.com>
parents: 40
diff changeset
   102
function* watchLoginRequest() {
3b20e2b584fe Introduce authentication through API.
Alexandre Segura <mex.zktk@gmail.com>
parents: 40
diff changeset
   103
  while (true) {
3b20e2b584fe Introduce authentication through API.
Alexandre Segura <mex.zktk@gmail.com>
parents: 40
diff changeset
   104
    try {
47
64428c7ebc19 Store token & user.
Alexandre Segura <mex.zktk@gmail.com>
parents: 44
diff changeset
   105
44
3b20e2b584fe Introduce authentication through API.
Alexandre Segura <mex.zktk@gmail.com>
parents: 40
diff changeset
   106
        const { username, password } = yield take(types.AUTH_LOGIN_REQUEST);
3b20e2b584fe Introduce authentication through API.
Alexandre Segura <mex.zktk@gmail.com>
parents: 40
diff changeset
   107
        const response = yield client.post('/api/auth/login/', { username, password });
47
64428c7ebc19 Store token & user.
Alexandre Segura <mex.zktk@gmail.com>
parents: 44
diff changeset
   108
64428c7ebc19 Store token & user.
Alexandre Segura <mex.zktk@gmail.com>
parents: 44
diff changeset
   109
        localStorage.setItem('currentUser', JSON.stringify(response.user));
64428c7ebc19 Store token & user.
Alexandre Segura <mex.zktk@gmail.com>
parents: 44
diff changeset
   110
        localStorage.setItem('token', response.token);
64428c7ebc19 Store token & user.
Alexandre Segura <mex.zktk@gmail.com>
parents: 44
diff changeset
   111
64428c7ebc19 Store token & user.
Alexandre Segura <mex.zktk@gmail.com>
parents: 44
diff changeset
   112
        const actions = [{
44
3b20e2b584fe Introduce authentication through API.
Alexandre Segura <mex.zktk@gmail.com>
parents: 40
diff changeset
   113
          type: types.AUTH_LOGIN_SUCCESS,
3b20e2b584fe Introduce authentication through API.
Alexandre Segura <mex.zktk@gmail.com>
parents: 40
diff changeset
   114
          user: response.user,
3b20e2b584fe Introduce authentication through API.
Alexandre Segura <mex.zktk@gmail.com>
parents: 40
diff changeset
   115
          token: response.token,
3b20e2b584fe Introduce authentication through API.
Alexandre Segura <mex.zktk@gmail.com>
parents: 40
diff changeset
   116
          meta: {
3b20e2b584fe Introduce authentication through API.
Alexandre Segura <mex.zktk@gmail.com>
parents: 40
diff changeset
   117
            transition: (prevState, nextState, action) => ({
3b20e2b584fe Introduce authentication through API.
Alexandre Segura <mex.zktk@gmail.com>
parents: 40
diff changeset
   118
              pathname: '/sessions',
3b20e2b584fe Introduce authentication through API.
Alexandre Segura <mex.zktk@gmail.com>
parents: 40
diff changeset
   119
            }),
3b20e2b584fe Introduce authentication through API.
Alexandre Segura <mex.zktk@gmail.com>
parents: 40
diff changeset
   120
          },
47
64428c7ebc19 Store token & user.
Alexandre Segura <mex.zktk@gmail.com>
parents: 44
diff changeset
   121
        }, {
64428c7ebc19 Store token & user.
Alexandre Segura <mex.zktk@gmail.com>
parents: 44
diff changeset
   122
          type: types.AUTH_STORE_TOKEN_ASYNC,
64428c7ebc19 Store token & user.
Alexandre Segura <mex.zktk@gmail.com>
parents: 44
diff changeset
   123
          token: response.token,
64428c7ebc19 Store token & user.
Alexandre Segura <mex.zktk@gmail.com>
parents: 44
diff changeset
   124
        }];
64428c7ebc19 Store token & user.
Alexandre Segura <mex.zktk@gmail.com>
parents: 44
diff changeset
   125
64428c7ebc19 Store token & user.
Alexandre Segura <mex.zktk@gmail.com>
parents: 44
diff changeset
   126
        yield actions.map(action => put(action))
64428c7ebc19 Store token & user.
Alexandre Segura <mex.zktk@gmail.com>
parents: 44
diff changeset
   127
44
3b20e2b584fe Introduce authentication through API.
Alexandre Segura <mex.zktk@gmail.com>
parents: 40
diff changeset
   128
    } catch(e) {
3b20e2b584fe Introduce authentication through API.
Alexandre Segura <mex.zktk@gmail.com>
parents: 40
diff changeset
   129
        yield put({ type: types.AUTH_LOGIN_ERROR, error: e });
3b20e2b584fe Introduce authentication through API.
Alexandre Segura <mex.zktk@gmail.com>
parents: 40
diff changeset
   130
    }
3b20e2b584fe Introduce authentication through API.
Alexandre Segura <mex.zktk@gmail.com>
parents: 40
diff changeset
   131
  }
3b20e2b584fe Introduce authentication through API.
Alexandre Segura <mex.zktk@gmail.com>
parents: 40
diff changeset
   132
}
3b20e2b584fe Introduce authentication through API.
Alexandre Segura <mex.zktk@gmail.com>
parents: 40
diff changeset
   133
47
64428c7ebc19 Store token & user.
Alexandre Segura <mex.zktk@gmail.com>
parents: 44
diff changeset
   134
function* watchStoreToken() {
64428c7ebc19 Store token & user.
Alexandre Segura <mex.zktk@gmail.com>
parents: 44
diff changeset
   135
  while (true) {
64428c7ebc19 Store token & user.
Alexandre Segura <mex.zktk@gmail.com>
parents: 44
diff changeset
   136
    const { token } = yield take(types.AUTH_STORE_TOKEN_ASYNC);
64428c7ebc19 Store token & user.
Alexandre Segura <mex.zktk@gmail.com>
parents: 44
diff changeset
   137
    yield put({ type: types.AUTH_STORE_TOKEN, token });
64428c7ebc19 Store token & user.
Alexandre Segura <mex.zktk@gmail.com>
parents: 44
diff changeset
   138
  }
64428c7ebc19 Store token & user.
Alexandre Segura <mex.zktk@gmail.com>
parents: 44
diff changeset
   139
}
64428c7ebc19 Store token & user.
Alexandre Segura <mex.zktk@gmail.com>
parents: 44
diff changeset
   140
53
d8588379529e Add settings page.
Alexandre Segura <mex.zktk@gmail.com>
parents: 47
diff changeset
   141
function* watchUpdateSettings() {
d8588379529e Add settings page.
Alexandre Segura <mex.zktk@gmail.com>
parents: 47
diff changeset
   142
  while (true) {
d8588379529e Add settings page.
Alexandre Segura <mex.zktk@gmail.com>
parents: 47
diff changeset
   143
    const { username, firstname, lastname } = yield take(types.USER_UPDATE_SETTINGS_ASYNC);
d8588379529e Add settings page.
Alexandre Segura <mex.zktk@gmail.com>
parents: 47
diff changeset
   144
    try {
d8588379529e Add settings page.
Alexandre Segura <mex.zktk@gmail.com>
parents: 47
diff changeset
   145
      yield client.put('/api/auth/user/', {
d8588379529e Add settings page.
Alexandre Segura <mex.zktk@gmail.com>
parents: 47
diff changeset
   146
        username,
d8588379529e Add settings page.
Alexandre Segura <mex.zktk@gmail.com>
parents: 47
diff changeset
   147
        first_name: firstname,
d8588379529e Add settings page.
Alexandre Segura <mex.zktk@gmail.com>
parents: 47
diff changeset
   148
        last_name: lastname
d8588379529e Add settings page.
Alexandre Segura <mex.zktk@gmail.com>
parents: 47
diff changeset
   149
      });
d8588379529e Add settings page.
Alexandre Segura <mex.zktk@gmail.com>
parents: 47
diff changeset
   150
      yield put({ type: types.USER_UPDATE_SETTINGS, firstname, lastname });
d8588379529e Add settings page.
Alexandre Segura <mex.zktk@gmail.com>
parents: 47
diff changeset
   151
    } catch (e) {
d8588379529e Add settings page.
Alexandre Segura <mex.zktk@gmail.com>
parents: 47
diff changeset
   152
d8588379529e Add settings page.
Alexandre Segura <mex.zktk@gmail.com>
parents: 47
diff changeset
   153
    }
d8588379529e Add settings page.
Alexandre Segura <mex.zktk@gmail.com>
parents: 47
diff changeset
   154
  }
d8588379529e Add settings page.
Alexandre Segura <mex.zktk@gmail.com>
parents: 47
diff changeset
   155
}
d8588379529e Add settings page.
Alexandre Segura <mex.zktk@gmail.com>
parents: 47
diff changeset
   156
44
3b20e2b584fe Introduce authentication through API.
Alexandre Segura <mex.zktk@gmail.com>
parents: 40
diff changeset
   157
// ---
3b20e2b584fe Introduce authentication through API.
Alexandre Segura <mex.zktk@gmail.com>
parents: 40
diff changeset
   158
29
4cfeabef7d5e Store data in PouchDB.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   159
export default function* rootSaga() {
4cfeabef7d5e Store data in PouchDB.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   160
  yield all([
4cfeabef7d5e Store data in PouchDB.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   161
    watchLoadSessions(),
4cfeabef7d5e Store data in PouchDB.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   162
    watchLoadNotesBySession(),
4cfeabef7d5e Store data in PouchDB.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   163
    watchAddNote(),
4cfeabef7d5e Store data in PouchDB.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   164
    watchCreateSession(),
30
4d93f4ed95bc Update session in PouchDB.
Alexandre Segura <mex.zktk@gmail.com>
parents: 29
diff changeset
   165
    watchUpdateSession(),
44
3b20e2b584fe Introduce authentication through API.
Alexandre Segura <mex.zktk@gmail.com>
parents: 40
diff changeset
   166
    watchLoginSubmit(),
3b20e2b584fe Introduce authentication through API.
Alexandre Segura <mex.zktk@gmail.com>
parents: 40
diff changeset
   167
    watchLoginRequest(),
47
64428c7ebc19 Store token & user.
Alexandre Segura <mex.zktk@gmail.com>
parents: 44
diff changeset
   168
    watchStoreToken(),
53
d8588379529e Add settings page.
Alexandre Segura <mex.zktk@gmail.com>
parents: 47
diff changeset
   169
    watchUpdateSettings(),
29
4cfeabef7d5e Store data in PouchDB.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   170
  ])
4cfeabef7d5e Store data in PouchDB.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
   171
}