client/src/actions/notesActions.js
author ymh <ymh.work@gmail.com>
Fri, 30 Nov 2018 10:53:15 +0100
changeset 183 f8f3af9e5c83
parent 132 906a6c7c7943
permissions -rw-r--r--
Change the settings to avoid using Session authentication for rest framework as it raise exceptions in case client and backend are on the same domain On the filter, adapt to take into account new version of django_filters
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3
3b5d37d84cfe Some code rename and reorg + basic tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
     1
import uuidV1 from 'uuid/v1';
3b5d37d84cfe Some code rename and reorg + basic tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
     2
3b5d37d84cfe Some code rename and reorg + basic tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
     3
import * as types from '../constants/actionTypes';
129
d48946d164c6 Add a first version of synchronisation
ymh <ymh.work@gmail.com>
parents: 98
diff changeset
     4
// import WebAnnotationSerializer from '../api/WebAnnotationSerializer';
d48946d164c6 Add a first version of synchronisation
ymh <ymh.work@gmail.com>
parents: 98
diff changeset
     5
import { ActionEnum } from '../constants';
3
3b5d37d84cfe Some code rename and reorg + basic tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
     6
15
4a8bbd314a46 Store note JSON data.
Alexandre Segura <mex.zktk@gmail.com>
parents: 12
diff changeset
     7
export const addNote = (session, data) => {
74
043477fd5c5c add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents: 66
diff changeset
     8
  const noteId = uuidV1();
043477fd5c5c add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents: 66
diff changeset
     9
  const note = {
043477fd5c5c add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents: 66
diff changeset
    10
    _id: noteId,
043477fd5c5c add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents: 66
diff changeset
    11
    session: session._id,
043477fd5c5c add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents: 66
diff changeset
    12
    raw: data.raw,
043477fd5c5c add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents: 66
diff changeset
    13
    plain: data.plain,
043477fd5c5c add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents: 66
diff changeset
    14
    html: data.html,
043477fd5c5c add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents: 66
diff changeset
    15
    startedAt: data.startedAt,
043477fd5c5c add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents: 66
diff changeset
    16
    finishedAt: data.finishedAt,
043477fd5c5c add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents: 66
diff changeset
    17
    categories: data.categories,
78
49c5ea36d0a4 Store margin comment.
Alexandre Segura <mex.zktk@gmail.com>
parents: 74
diff changeset
    18
    marginComment: data.marginComment,
129
d48946d164c6 Add a first version of synchronisation
ymh <ymh.work@gmail.com>
parents: 98
diff changeset
    19
    action: ActionEnum.CREATED
74
043477fd5c5c add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents: 66
diff changeset
    20
  };
043477fd5c5c add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents: 66
diff changeset
    21
3
3b5d37d84cfe Some code rename and reorg + basic tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
    22
  return {
62
b2514a9bcd49 migrate to redux-offline + various optimisation
ymh <ymh.work@gmail.com>
parents: 59
diff changeset
    23
    type: types.ADD_NOTE,
74
043477fd5c5c add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents: 66
diff changeset
    24
    note,
3
3b5d37d84cfe Some code rename and reorg + basic tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
    25
  };
3b5d37d84cfe Some code rename and reorg + basic tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
    26
}
79
772b73e31069 Introduce note editing, allow deleting note.
Alexandre Segura <mex.zktk@gmail.com>
parents: 78
diff changeset
    27
772b73e31069 Introduce note editing, allow deleting note.
Alexandre Segura <mex.zktk@gmail.com>
parents: 78
diff changeset
    28
export const deleteNote = (note) => {
772b73e31069 Introduce note editing, allow deleting note.
Alexandre Segura <mex.zktk@gmail.com>
parents: 78
diff changeset
    29
  return {
772b73e31069 Introduce note editing, allow deleting note.
Alexandre Segura <mex.zktk@gmail.com>
parents: 78
diff changeset
    30
    type: types.DELETE_NOTE,
83
76a4e4b11762 add server request for note update and delete
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
    31
    note,
79
772b73e31069 Introduce note editing, allow deleting note.
Alexandre Segura <mex.zktk@gmail.com>
parents: 78
diff changeset
    32
  };
772b73e31069 Introduce note editing, allow deleting note.
Alexandre Segura <mex.zktk@gmail.com>
parents: 78
diff changeset
    33
}
80
b3a02ea6d097 Implement note edition.
Alexandre Segura <mex.zktk@gmail.com>
parents: 79
diff changeset
    34
b3a02ea6d097 Implement note edition.
Alexandre Segura <mex.zktk@gmail.com>
parents: 79
diff changeset
    35
export const updateNote = (note, data) => {
83
76a4e4b11762 add server request for note update and delete
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
    36
80
b3a02ea6d097 Implement note edition.
Alexandre Segura <mex.zktk@gmail.com>
parents: 79
diff changeset
    37
  return {
b3a02ea6d097 Implement note edition.
Alexandre Segura <mex.zktk@gmail.com>
parents: 79
diff changeset
    38
    type: types.UPDATE_NOTE,
b3a02ea6d097 Implement note edition.
Alexandre Segura <mex.zktk@gmail.com>
parents: 79
diff changeset
    39
    note,
83
76a4e4b11762 add server request for note update and delete
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
    40
    data,
80
b3a02ea6d097 Implement note edition.
Alexandre Segura <mex.zktk@gmail.com>
parents: 79
diff changeset
    41
  };
b3a02ea6d097 Implement note edition.
Alexandre Segura <mex.zktk@gmail.com>
parents: 79
diff changeset
    42
}
129
d48946d164c6 Add a first version of synchronisation
ymh <ymh.work@gmail.com>
parents: 98
diff changeset
    43
d48946d164c6 Add a first version of synchronisation
ymh <ymh.work@gmail.com>
parents: 98
diff changeset
    44
export const doDeleteNote = (noteId) => {
d48946d164c6 Add a first version of synchronisation
ymh <ymh.work@gmail.com>
parents: 98
diff changeset
    45
  return { type: types.DO_DELETE_NOTE, noteId };
d48946d164c6 Add a first version of synchronisation
ymh <ymh.work@gmail.com>
parents: 98
diff changeset
    46
}
d48946d164c6 Add a first version of synchronisation
ymh <ymh.work@gmail.com>
parents: 98
diff changeset
    47
132
906a6c7c7943 add group to sync + create groups + various component cleaning
ymh <ymh.work@gmail.com>
parents: 129
diff changeset
    48
export const doDeleteAllNote = () => {
906a6c7c7943 add group to sync + create groups + various component cleaning
ymh <ymh.work@gmail.com>
parents: 129
diff changeset
    49
  return { type: types.DO_DELETE_ALL_NOTE };
906a6c7c7943 add group to sync + create groups + various component cleaning
ymh <ymh.work@gmail.com>
parents: 129
diff changeset
    50
}
906a6c7c7943 add group to sync + create groups + various component cleaning
ymh <ymh.work@gmail.com>
parents: 129
diff changeset
    51
129
d48946d164c6 Add a first version of synchronisation
ymh <ymh.work@gmail.com>
parents: 98
diff changeset
    52
export const loadNote = (note) => {
d48946d164c6 Add a first version of synchronisation
ymh <ymh.work@gmail.com>
parents: 98
diff changeset
    53
  return { type: types.LOAD_NOTE, note };
d48946d164c6 Add a first version of synchronisation
ymh <ymh.work@gmail.com>
parents: 98
diff changeset
    54
}
d48946d164c6 Add a first version of synchronisation
ymh <ymh.work@gmail.com>
parents: 98
diff changeset
    55
d48946d164c6 Add a first version of synchronisation
ymh <ymh.work@gmail.com>
parents: 98
diff changeset
    56
export const resetActionNote = (note) => {
d48946d164c6 Add a first version of synchronisation
ymh <ymh.work@gmail.com>
parents: 98
diff changeset
    57
  return { type: types.RESET_ACTION_NOTE, note };
d48946d164c6 Add a first version of synchronisation
ymh <ymh.work@gmail.com>
parents: 98
diff changeset
    58
}
d48946d164c6 Add a first version of synchronisation
ymh <ymh.work@gmail.com>
parents: 98
diff changeset
    59