client/src/actions/sessionsActions.js
author ymh <ymh.work@gmail.com>
Thu, 22 Jun 2017 12:09:48 +0200
changeset 74 043477fd5c5c
parent 68 6e18b31b0ad5
child 93 469da13402e2
permissions -rw-r--r--
add api call to save notes. internally use ts for time data for notes and session
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
74
043477fd5c5c add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents: 68
diff changeset
     1
import { now } from '../utils';
12
48ddaa42b810 Draft implementation of sessions.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
     2
import * as types from '../constants/actionTypes';
48ddaa42b810 Draft implementation of sessions.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
     3
62
b2514a9bcd49 migrate to redux-offline + various optimisation
ymh <ymh.work@gmail.com>
parents: 59
diff changeset
     4
export const createSession = (sessionId) => {
b2514a9bcd49 migrate to redux-offline + various optimisation
ymh <ymh.work@gmail.com>
parents: 59
diff changeset
     5
b2514a9bcd49 migrate to redux-offline + various optimisation
ymh <ymh.work@gmail.com>
parents: 59
diff changeset
     6
  const newSession = {
b2514a9bcd49 migrate to redux-offline + various optimisation
ymh <ymh.work@gmail.com>
parents: 59
diff changeset
     7
      _id: sessionId,
b2514a9bcd49 migrate to redux-offline + various optimisation
ymh <ymh.work@gmail.com>
parents: 59
diff changeset
     8
      ext_id: sessionId,
74
043477fd5c5c add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents: 68
diff changeset
     9
      date: now(),
12
48ddaa42b810 Draft implementation of sessions.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    10
      title: '',
48ddaa42b810 Draft implementation of sessions.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    11
      description: '',
62
b2514a9bcd49 migrate to redux-offline + various optimisation
ymh <ymh.work@gmail.com>
parents: 59
diff changeset
    12
  };
b2514a9bcd49 migrate to redux-offline + various optimisation
ymh <ymh.work@gmail.com>
parents: 59
diff changeset
    13
b2514a9bcd49 migrate to redux-offline + various optimisation
ymh <ymh.work@gmail.com>
parents: 59
diff changeset
    14
  return {
b2514a9bcd49 migrate to redux-offline + various optimisation
ymh <ymh.work@gmail.com>
parents: 59
diff changeset
    15
    type: types.CREATE_SESSION,
b2514a9bcd49 migrate to redux-offline + various optimisation
ymh <ymh.work@gmail.com>
parents: 59
diff changeset
    16
    session: newSession,
b2514a9bcd49 migrate to redux-offline + various optimisation
ymh <ymh.work@gmail.com>
parents: 59
diff changeset
    17
    meta: {
b2514a9bcd49 migrate to redux-offline + various optimisation
ymh <ymh.work@gmail.com>
parents: 59
diff changeset
    18
      offline: {
b2514a9bcd49 migrate to redux-offline + various optimisation
ymh <ymh.work@gmail.com>
parents: 59
diff changeset
    19
        effect: {
68
6e18b31b0ad5 Correct session creation and add offline to the persisted state
ymh <ymh.work@gmail.com>
parents: 66
diff changeset
    20
          url: `/api/notes/sessions/`,
62
b2514a9bcd49 migrate to redux-offline + various optimisation
ymh <ymh.work@gmail.com>
parents: 59
diff changeset
    21
          method: 'POST',
b2514a9bcd49 migrate to redux-offline + various optimisation
ymh <ymh.work@gmail.com>
parents: 59
diff changeset
    22
          data: newSession
b2514a9bcd49 migrate to redux-offline + various optimisation
ymh <ymh.work@gmail.com>
parents: 59
diff changeset
    23
        },
66
f402435be429 Action types cleaning
ymh <ymh.work@gmail.com>
parents: 62
diff changeset
    24
        commit: { type: types.NOOP },
f402435be429 Action types cleaning
ymh <ymh.work@gmail.com>
parents: 62
diff changeset
    25
        rollback: { type: types.NOOP }
62
b2514a9bcd49 migrate to redux-offline + various optimisation
ymh <ymh.work@gmail.com>
parents: 59
diff changeset
    26
      }
12
48ddaa42b810 Draft implementation of sessions.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    27
    }
48ddaa42b810 Draft implementation of sessions.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    28
  };
48ddaa42b810 Draft implementation of sessions.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    29
}
48ddaa42b810 Draft implementation of sessions.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    30
48ddaa42b810 Draft implementation of sessions.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    31
export const updateSession = (session, values) => {
48ddaa42b810 Draft implementation of sessions.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    32
  return {
62
b2514a9bcd49 migrate to redux-offline + various optimisation
ymh <ymh.work@gmail.com>
parents: 59
diff changeset
    33
    type: types.UPDATE_SESSION,
12
48ddaa42b810 Draft implementation of sessions.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    34
    session: session,
48ddaa42b810 Draft implementation of sessions.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    35
    values: values,
74
043477fd5c5c add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents: 68
diff changeset
    36
    meta: {
043477fd5c5c add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents: 68
diff changeset
    37
      offline: {
043477fd5c5c add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents: 68
diff changeset
    38
        effect: {
043477fd5c5c add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents: 68
diff changeset
    39
          url: `/api/notes/sessions/${session.get('_id')}/`,
043477fd5c5c add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents: 68
diff changeset
    40
          method: 'PUT',
043477fd5c5c add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents: 68
diff changeset
    41
          data: values
043477fd5c5c add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents: 68
diff changeset
    42
        },
043477fd5c5c add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents: 68
diff changeset
    43
        commit: { type: types.NOOP },
043477fd5c5c add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents: 68
diff changeset
    44
        rollback: { type: types.NOOP }
043477fd5c5c add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents: 68
diff changeset
    45
      }
043477fd5c5c add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents: 68
diff changeset
    46
    }
12
48ddaa42b810 Draft implementation of sessions.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    47
  };
48ddaa42b810 Draft implementation of sessions.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    48
}
29
4cfeabef7d5e Store data in PouchDB.
Alexandre Segura <mex.zktk@gmail.com>
parents: 12
diff changeset
    49
4cfeabef7d5e Store data in PouchDB.
Alexandre Segura <mex.zktk@gmail.com>
parents: 12
diff changeset
    50
export const loadSessions = () => {
4cfeabef7d5e Store data in PouchDB.
Alexandre Segura <mex.zktk@gmail.com>
parents: 12
diff changeset
    51
  return {
62
b2514a9bcd49 migrate to redux-offline + various optimisation
ymh <ymh.work@gmail.com>
parents: 59
diff changeset
    52
    type: types.LOAD_SESSIONS
29
4cfeabef7d5e Store data in PouchDB.
Alexandre Segura <mex.zktk@gmail.com>
parents: 12
diff changeset
    53
  }
4cfeabef7d5e Store data in PouchDB.
Alexandre Segura <mex.zktk@gmail.com>
parents: 12
diff changeset
    54
}