Advertisement
Guest User

Untitled

a guest
Mar 19th, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.07 KB | None | 0 0
  1. import * as actionTypes from '../actions/actionTypes';
  2.  
  3. const initialState = {
  4. notFound: false,
  5. loadedUser: false,
  6. alertMessage: null,
  7. alertPreserve: false,
  8. isFetchingUsersInfo: false,
  9. isFetchingUserLogin: false,
  10. isFetchingUserLogout: false,
  11. isFetchingContent: false,
  12. isSendingData: false
  13. };
  14.  
  15. export default function appState(state = initialState, action) {
  16. switch (action.type) {
  17. case actionTypes.NOT_FOUND_RENDER: {
  18. return {
  19. ...state,
  20. notFound: true,
  21. isFetchingContent: false,
  22. }
  23. }
  24.  
  25. case actionTypes.NOT_FOUND_RESET: {
  26. return {
  27. ...state,
  28. notFound: initialState.notFound,
  29. }
  30. }
  31.  
  32. case actionTypes.FETCH_USER_BASIC_INFO_REQUEST_TRIGGERED: {
  33. return {
  34. ...state,
  35. isFetchingUsersInfo: true,
  36. }
  37. }
  38.  
  39. case actionTypes.FETCH_USER_BASIC_INFO_REQUEST_SUCCESS: {
  40. return {
  41. ...state,
  42. loadedUser: true,
  43. isFetchingUsersInfo: false,
  44. };
  45. }
  46. case actionTypes.FETCH_USER_BASIC_INFO_REQUEST_FAILURE: {
  47. return {
  48. ...state,
  49. isFetchingUsersInfo: false,
  50. };
  51. }
  52.  
  53. // Fetch User Login
  54. case actionTypes.FETCH_USER_LOGIN_REQUEST_TRIGGERED: {
  55. return {
  56. ...state,
  57. isFetchingUserLogin: true,
  58. };
  59. }
  60. case actionTypes.FETCH_USER_LOGIN_REQUEST_SUCCESS:
  61. case actionTypes.FETCH_USER_LOGIN_REQUEST_FAILURE: {
  62. return {
  63. ...state,
  64. isFetchingContent: false,
  65. isFetchingUserLogin: initialState.isFetchingUserLogin,
  66. };
  67. }
  68.  
  69. // Fetch User Logout
  70. case actionTypes.FETCH_USER_LOGOUT_REQUEST_TRIGGERED: {
  71. return {
  72. ...state,
  73. isFetchingUserLogout: true,
  74. };
  75. }
  76. case actionTypes.FETCH_USER_LOGOUT_REQUEST_SUCCESS:
  77. case actionTypes.FETCH_USER_LOGOUT_REQUEST_FAILURE: {
  78. return {
  79. ...state,
  80. isFetchingUserLogout: initialState.isFetchingUserLogout,
  81. };
  82. }
  83.  
  84. // Fetch Content
  85. case actionTypes.FETCH_CONTENT_REQUEST_TRIGGERED: {
  86. return {
  87. ...state,
  88. isFetchingContent: true,
  89. isSendingData: false,
  90. };
  91. }
  92.  
  93. case actionTypes.FETCH_CONTENT_REQUEST_FAILED: {
  94. return {
  95. ...state,
  96. isFetchingContent: initialState.isFetchingContent
  97. }
  98. }
  99.  
  100. case actionTypes.FETCH_CONTENT_REQUEST_SUCCESS:
  101. case actionTypes.FETCH_FORUMS_LIST_REQUEST_SUCCESS:
  102. case actionTypes.FETCH_FORUM_REQUEST_SUCCESS:
  103. case actionTypes.FETCH_TOPIC_REQUEST_SUCCESS:
  104. case actionTypes.USER_RESET_PASSWORD_FETCHED:
  105. case actionTypes.USER_FETCHED_PROFILE: {
  106. return {
  107. ...state,
  108. isFetchingContent: initialState.isFetchingContent,
  109. };
  110. }
  111.  
  112. case actionTypes.FORM_SUBMIT_TRIGGERED: {
  113. return {
  114. ...state,
  115. isSendingData: true
  116. }
  117. }
  118.  
  119. case actionTypes.FORM_SUBMIT_FAILURE:
  120. case actionTypes.FORUM_POST_DESTROY:
  121. case actionTypes.FORUM_POST_UPDATE:
  122. case actionTypes.FORUM_CREATE_POST_SUCCESS:
  123. case actionTypes.USER_ADD_AVATAR:
  124. case actionTypes.USER_SIGN_UP:
  125. case actionTypes.USER_PROFILE_UPDATE: {
  126. return {
  127. ...state,
  128. isSendingData: false
  129. }
  130. }
  131.  
  132.  
  133. // Show error message
  134. case actionTypes.SHOW_ALERT_MESSAGE: {
  135. return {
  136. ...state,
  137. alertMessage: {
  138. isError: action.isError,
  139. message: action.message || action.error,
  140. errors: action.errors
  141. },
  142. };
  143. }
  144.  
  145.  
  146. // Reset alert message
  147. case actionTypes.RESET_ALERT_MESSAGE: {
  148.  
  149. if (state.alertPreserve) {
  150. return {
  151. ...state,
  152. alertPreserve: false,
  153. }
  154. } else {
  155. return {
  156. ...state,
  157. alertMessage: initialState.alertMessage,
  158. };
  159. }
  160. }
  161.  
  162. case actionTypes.CLOSE_ALERT_MESSAGE: {
  163. return {
  164. ...state,
  165. alertMessage: null,
  166. alertPreserve: false
  167. }
  168. }
  169.  
  170. case actionTypes.ALERT_MESSAGE_PRESERVE: {
  171. return {
  172. ...state,
  173. alertPreserve: true
  174. }
  175. }
  176.  
  177. default: {
  178. return state;
  179. }
  180. }
  181. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement