Home Reference Source

application/redux/actions/assignment-comment-actions.js

  1. import BaseService from './../../services/base-service';
  2. import {parseSrn} from './../../util/strings';
  3. import Immutable from 'immutable';
  4.  
  5. class AssignmentCommentService extends BaseService {
  6.  
  7. fetch(id, opts = {}) {
  8. return this.get('/v3/assignment-comment/' + id, opts);
  9. }
  10.  
  11. create(id, data) {
  12. return this.post('/v3/assignment-comment/' + id, data);
  13. }
  14. }
  15.  
  16. const service = new AssignmentCommentService;
  17.  
  18. /**
  19. * Action types
  20. */
  21. export const ASSIGNMENT_COMMENTS_REQUEST = 'ASSIGNMENT_COMMENTS_REQUEST';
  22. export const ASSIGNMENT_COMMENTS_RECEIVE = 'ASSIGNMENT_COMMENTS_RECEIVE';
  23. export const ASSIGNMENT_COMMENTS_SELECTED = 'ASSIGNMENT_COMMENTS_SELECTED';
  24. export const ASSIGNMENT_COMMENTS_INVALIDATE = 'ASSIGNMENT_COMMENTS_INVALIDATE';
  25.  
  26. /**
  27. * Action creators
  28. */
  29. export function assignmentCommentsRequest(params = {}) {
  30. return {
  31. type: ASSIGNMENT_COMMENTS_REQUEST,
  32. payload: {
  33. params: params
  34. }
  35. };
  36. }
  37.  
  38. export function assignmentCommentsReceive(items) {
  39.  
  40. return {
  41. type: ASSIGNMENT_COMMENTS_RECEIVE,
  42. payload: {
  43. comments: items ? items : []
  44. }
  45. };
  46. }
  47.  
  48. export function assignmentCommentsInvalidate() {
  49. return {
  50. type: ASSIGNMENT_COMMENTS_INVALIDATE,
  51. payload: {
  52. }
  53. };
  54. }
  55.  
  56. export function assignmentCommentsFetch(id, params = {}) {
  57. return function(dispatch, getState) {
  58. dispatch(assignmentCommentsRequest(params));
  59.  
  60. return service.fetch(id, params)
  61. .then(response => {
  62. return dispatch(assignmentCommentsReceive(response.get('items')));
  63. });
  64. };
  65. }
  66.  
  67. export function assignmentCommentsReceiveWebSocket(comments = {}) {
  68. return function(dispatch, getState) {
  69. return Promise.all([
  70. dispatch(assignmentCommentsReceive(comments.get('items')))
  71. ]);
  72. };
  73. }
  74.  
  75. export function assignmentCommentsCreate(id, comment = {}) {
  76. return function(dispatch, getState) {
  77. return service.create(id, comment)
  78. .then(response => {
  79. return dispatch(assignmentCommentsReceive(response.get('items')));
  80. });
  81. }
  82. }