| author | ymh <ymh.work@gmail.com> |
| Thu, 03 Aug 2017 09:44:37 +0200 | |
| changeset 133 | 6f3078f7fd47 |
| parent 130 | 78246db1cbac |
| permissions | -rw-r--r-- |
|
129
d48946d164c6
Add a first version of synchronisation
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
1 |
// Define state selector for saga |
|
d48946d164c6
Add a first version of synchronisation
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
2 |
import Immutable from 'immutable'; |
|
d48946d164c6
Add a first version of synchronisation
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
3 |
import { ActionEnum } from '../constants' |
|
d48946d164c6
Add a first version of synchronisation
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
4 |
|
|
d48946d164c6
Add a first version of synchronisation
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
5 |
export const getLastSync = state => state.getIn(['authStatus', 'lastSync']) || 0 |
|
d48946d164c6
Add a first version of synchronisation
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
6 |
|
|
130
78246db1cbac
make synchronization recurent, improve synchronization status display
ymh <ymh.work@gmail.com>
parents:
129
diff
changeset
|
7 |
export const getOnline = state => state.getIn(["status", 'online']) |
|
78246db1cbac
make synchronization recurent, improve synchronization status display
ymh <ymh.work@gmail.com>
parents:
129
diff
changeset
|
8 |
|
|
129
d48946d164c6
Add a first version of synchronisation
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
9 |
export const getToken = state => state.getIn(['authStatus','token']) |
|
d48946d164c6
Add a first version of synchronisation
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
10 |
|
|
d48946d164c6
Add a first version of synchronisation
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
11 |
const getSessionMapSelector = actionVal => state => |
|
d48946d164c6
Add a first version of synchronisation
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
12 |
state.get('sessions') |
|
d48946d164c6
Add a first version of synchronisation
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
13 |
.filter(s => s.get('action') === actionVal) |
|
d48946d164c6
Add a first version of synchronisation
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
14 |
.reduce( |
|
d48946d164c6
Add a first version of synchronisation
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
15 |
(res, obj) => { |
|
d48946d164c6
Add a first version of synchronisation
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
16 |
return res.set(obj.get('_id'), obj); |
|
d48946d164c6
Add a first version of synchronisation
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
17 |
}, |
|
d48946d164c6
Add a first version of synchronisation
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
18 |
Immutable.Map() |
|
d48946d164c6
Add a first version of synchronisation
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
19 |
); |
|
d48946d164c6
Add a first version of synchronisation
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
20 |
|
|
d48946d164c6
Add a first version of synchronisation
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
21 |
const getNoteMapSelector = actionVal => state => { |
|
d48946d164c6
Add a first version of synchronisation
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
22 |
const deletedSessions = state.get('sessions') |
|
d48946d164c6
Add a first version of synchronisation
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
23 |
.filter(s => s.get('action') === ActionEnum.DELETED) |
|
d48946d164c6
Add a first version of synchronisation
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
24 |
.reduce( |
|
d48946d164c6
Add a first version of synchronisation
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
25 |
(res, obj) => { |
|
d48946d164c6
Add a first version of synchronisation
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
26 |
return res.set(obj.get('_id'), obj); |
|
d48946d164c6
Add a first version of synchronisation
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
27 |
}, |
|
d48946d164c6
Add a first version of synchronisation
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
28 |
Immutable.Map() |
|
d48946d164c6
Add a first version of synchronisation
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
29 |
); |
|
d48946d164c6
Add a first version of synchronisation
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
30 |
return state.get('notes') |
|
d48946d164c6
Add a first version of synchronisation
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
31 |
.filter(n => (n.get('action') === actionVal && !deletedSessions.has(n.get('session')))) |
|
d48946d164c6
Add a first version of synchronisation
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
32 |
.reduce( |
|
d48946d164c6
Add a first version of synchronisation
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
33 |
(res, obj) => { |
|
d48946d164c6
Add a first version of synchronisation
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
34 |
return res.set(obj.get('_id'), obj); |
|
d48946d164c6
Add a first version of synchronisation
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
35 |
}, |
|
d48946d164c6
Add a first version of synchronisation
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
36 |
Immutable.Map() |
|
d48946d164c6
Add a first version of synchronisation
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
37 |
); |
|
d48946d164c6
Add a first version of synchronisation
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
38 |
} |
|
d48946d164c6
Add a first version of synchronisation
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
39 |
|
|
d48946d164c6
Add a first version of synchronisation
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
40 |
|
|
d48946d164c6
Add a first version of synchronisation
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
41 |
export const getUpdatedSessions = getSessionMapSelector(ActionEnum.UPDATED); |
|
d48946d164c6
Add a first version of synchronisation
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
42 |
|
|
d48946d164c6
Add a first version of synchronisation
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
43 |
export const getCreatedSessions = getSessionMapSelector(ActionEnum.CREATED); |
|
d48946d164c6
Add a first version of synchronisation
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
44 |
|
|
d48946d164c6
Add a first version of synchronisation
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
45 |
export const getDeletedSessions = getSessionMapSelector(ActionEnum.DELETED); |
|
d48946d164c6
Add a first version of synchronisation
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
46 |
|
|
d48946d164c6
Add a first version of synchronisation
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
47 |
export const getUpdatedNotes = getNoteMapSelector(ActionEnum.UPDATED); |
|
d48946d164c6
Add a first version of synchronisation
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
48 |
|
|
d48946d164c6
Add a first version of synchronisation
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
49 |
export const getCreatedNotes = getNoteMapSelector(ActionEnum.CREATED); |
|
d48946d164c6
Add a first version of synchronisation
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
50 |
|
|
d48946d164c6
Add a first version of synchronisation
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
51 |
export const getDeletedNotes = getNoteMapSelector(ActionEnum.DELETED); |