equal
deleted
inserted
replaced
1 /* eslint-disable func-names */ |
1 /* eslint-disable func-names */ |
2 import fetch from 'isomorphic-fetch'; |
2 import fetch from 'isomorphic-fetch'; |
3 import _ from 'lodash'; |
3 import _ from 'lodash'; |
4 |
4 |
5 import { getTerms, toBase64 } from './utils'; |
5 import { getTerms, getTermId } from './utils'; |
6 |
6 |
7 |
7 |
8 export const REQUEST_ANNOTATIONS = 'REQUEST_ANNOTATIONS'; |
8 export const REQUEST_ANNOTATIONS = 'REQUEST_ANNOTATIONS'; |
9 export function requestAnnotations(url) { |
9 export function requestAnnotations(url) { |
10 return { |
10 return { |
43 terms64, |
43 terms64, |
44 }; |
44 }; |
45 } |
45 } |
46 |
46 |
47 export const FETCH_MESSAGES_COUNT = 'FETCH_MESSAGES_COUNT'; |
47 export const FETCH_MESSAGES_COUNT = 'FETCH_MESSAGES_COUNT'; |
48 export function fetchMessagesCount(terms, discussionUrl) { |
48 export function fetchMessagesCount(terms, discussionUrl, dashboardId) { |
49 const url = `${discussionUrl}count`; |
49 const url = `${discussionUrl}count`; |
50 const terms64 = _.map(terms, toBase64); |
50 const terms64 = _.map(terms, term => getTermId(term, dashboardId)); |
51 |
51 |
52 return function (dispatch) { |
52 return function (dispatch) { |
53 dispatch(requestMessagesCount(url, terms, terms64)); |
53 dispatch(requestMessagesCount(url, terms, terms64)); |
54 |
54 |
55 if (!discussionUrl) { |
55 if (!discussionUrl) { |
72 ); |
72 ); |
73 }; |
73 }; |
74 } |
74 } |
75 |
75 |
76 export const FETCH_ANNOTATIONS = 'FETCH_ANNOTATIONS'; |
76 export const FETCH_ANNOTATIONS = 'FETCH_ANNOTATIONS'; |
77 export function fetchAnnotations(url, discussionUrl) { |
77 export function fetchAnnotations(url, discussionUrl, dashboardId) { |
78 return function (dispatch) { |
78 return function (dispatch) { |
79 dispatch(requestAnnotations(url)); |
79 dispatch(requestAnnotations(url)); |
80 |
80 |
81 return fetch(url) |
81 return fetch(url) |
82 .then( |
82 .then( |
85 ) |
85 ) |
86 .then((json) => { |
86 .then((json) => { |
87 const annotations = json.rows; |
87 const annotations = json.rows; |
88 const terms = getTerms(annotations); |
88 const terms = getTerms(annotations); |
89 |
89 |
90 dispatch(fetchMessagesCount(Object.keys(terms), discussionUrl)); |
90 dispatch(fetchMessagesCount(Object.keys(terms), discussionUrl, dashboardId)); |
91 dispatch(receiveAnnotations(url, annotations, terms)); |
91 dispatch(receiveAnnotations(url, annotations, terms)); |
92 }); |
92 }); |
93 }; |
93 }; |
94 } |
94 } |