--- a/client/src/sagas/index.js Tue Jun 20 12:11:57 2017 +0200
+++ b/client/src/sagas/index.js Tue Jun 20 14:13:15 2017 +0200
@@ -1,90 +1,5 @@
-import PouchDB from 'pouchdb'
-import { put, take, takeLatest, all } from 'redux-saga/effects'
+import { put, take, all } from 'redux-saga/effects'
import * as types from '../constants/actionTypes';
-import PouchDBFind from 'pouchdb-find';
-import Immutable from 'immutable';
-
-PouchDB.debug.disable();
-PouchDB.plugin(PouchDBFind);
-
-const sessionsDB = new PouchDB('sessions');
-const notesDB = new PouchDB('notes');
-notesDB.createIndex({
- index: { fields: ['session'] }
-});
-
-// ---
-
-export function* loadSessions() {
- const response = yield sessionsDB.allDocs({ include_docs: true })
- const sessions = response.rows.map(row => row.doc)
- yield put({ type: types.LOAD_SESSIONS, sessions: Immutable.List(sessions) })
-}
-
-export function* watchLoadSessions() {
- yield takeLatest(types.LOAD_SESSIONS_ASYNC, loadSessions)
-}
-
-// ---
-
-export function* createSession(action) {
- const response = yield sessionsDB.put(action.session);
- // TODO Error control
- const session = Object.assign({}, action.session, { rev: response.rev });
- yield put({ type: types.CREATE_SESSION, session: session })
-}
-
-export function* watchCreateSession() {
- yield takeLatest(types.CREATE_SESSION_ASYNC, createSession)
-}
-
-// ---
-
-export function* updateSession(action) {
-
- const { _id } = action.session;
- let session;
-
- const doc = yield sessionsDB.get(_id);
- session = Object.assign({}, doc, action.values);
- const response = yield sessionsDB.put(session);
-
- yield put({
- type: types.UPDATE_SESSION,
- session: Object.assign({}, session, { rev: response.rev })
- })
-}
-
-export function* watchUpdateSession() {
- yield takeLatest(types.UPDATE_SESSION_ASYNC, updateSession)
-}
-
-// ---
-
-export function* addNote(action) {
- const response = yield notesDB.put(action.note);
- // TODO Error control
- const note = Object.assign({}, action.note, { rev: response.rev });
- yield put({ type: types.ADD_NOTE, note: note })
-}
-
-export function* watchAddNote() {
- yield takeLatest(types.ADD_NOTE_ASYNC, addNote)
-}
-
-// ---
-
-export function* loadNotesBySession(action) {
- const result = yield notesDB.find({
- selector: { session: action.session._id },
- // sort: ['name']
- });
- yield put({ type: types.LOAD_NOTES_BY_SESSION, notes: Immutable.List(result.docs) })
-}
-
-export function* watchLoadNotesBySession() {
- yield takeLatest(types.LOAD_NOTES_BY_SESSION_ASYNC, loadNotesBySession)
-}
// ---
@@ -103,24 +18,22 @@
const client = context.client;
const response = yield client.post('/api/auth/login/', { username, password });
- localStorage.setItem('currentUser', JSON.stringify(response.user));
- localStorage.setItem('token', response.token);
-
const actions = [{
type: types.AUTH_LOGIN_SUCCESS,
user: response.user,
token: response.token,
- meta: {
- transition: (prevState, nextState, action) => ({
- pathname: '/sessions',
- }),
- },
+ // meta: {
+ // transition: (prevState, nextState, action) => ({
+ // pathname: '/sessions',
+ // }),
+ // },
}, {
type: types.AUTH_STORE_TOKEN_ASYNC,
token: response.token,
}];
- yield all(actions.map(action => put(action)))
+ yield all(actions.map(action => put(action)));
+ context.history.push('/sessions');
} catch(e) {
yield put({ type: types.AUTH_LOGIN_ERROR, error: e });
@@ -156,11 +69,6 @@
export default function* rootSaga(context) {
yield all([
- watchLoadSessions(),
- watchLoadNotesBySession(),
- watchAddNote(),
- watchCreateSession(),
- watchUpdateSession(),
watchLoginSubmit(),
watchLoginRequest(context),
watchStoreToken(),