tags.js 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. import api from '../api';
  2. export const HASHTAG_FETCH_REQUEST = 'HASHTAG_FETCH_REQUEST';
  3. export const HASHTAG_FETCH_SUCCESS = 'HASHTAG_FETCH_SUCCESS';
  4. export const HASHTAG_FETCH_FAIL = 'HASHTAG_FETCH_FAIL';
  5. export const HASHTAG_FOLLOW_REQUEST = 'HASHTAG_FOLLOW_REQUEST';
  6. export const HASHTAG_FOLLOW_SUCCESS = 'HASHTAG_FOLLOW_SUCCESS';
  7. export const HASHTAG_FOLLOW_FAIL = 'HASHTAG_FOLLOW_FAIL';
  8. export const HASHTAG_UNFOLLOW_REQUEST = 'HASHTAG_UNFOLLOW_REQUEST';
  9. export const HASHTAG_UNFOLLOW_SUCCESS = 'HASHTAG_UNFOLLOW_SUCCESS';
  10. export const HASHTAG_UNFOLLOW_FAIL = 'HASHTAG_UNFOLLOW_FAIL';
  11. export const fetchHashtag = name => (dispatch, getState) => {
  12. dispatch(fetchHashtagRequest());
  13. api(getState).get(`/api/v1/tags/${name}`).then(({ data }) => {
  14. dispatch(fetchHashtagSuccess(name, data));
  15. }).catch(err => {
  16. dispatch(fetchHashtagFail(err));
  17. });
  18. };
  19. export const fetchHashtagRequest = () => ({
  20. type: HASHTAG_FETCH_REQUEST,
  21. });
  22. export const fetchHashtagSuccess = (name, tag) => ({
  23. type: HASHTAG_FETCH_SUCCESS,
  24. name,
  25. tag,
  26. });
  27. export const fetchHashtagFail = error => ({
  28. type: HASHTAG_FETCH_FAIL,
  29. error,
  30. });
  31. export const followHashtag = name => (dispatch, getState) => {
  32. dispatch(followHashtagRequest(name));
  33. api(getState).post(`/api/v1/tags/${name}/follow`).then(({ data }) => {
  34. dispatch(followHashtagSuccess(name, data));
  35. }).catch(err => {
  36. dispatch(followHashtagFail(name, err));
  37. });
  38. };
  39. export const followHashtagRequest = name => ({
  40. type: HASHTAG_FOLLOW_REQUEST,
  41. name,
  42. });
  43. export const followHashtagSuccess = (name, tag) => ({
  44. type: HASHTAG_FOLLOW_SUCCESS,
  45. name,
  46. tag,
  47. });
  48. export const followHashtagFail = (name, error) => ({
  49. type: HASHTAG_FOLLOW_FAIL,
  50. name,
  51. error,
  52. });
  53. export const unfollowHashtag = name => (dispatch, getState) => {
  54. dispatch(unfollowHashtagRequest(name));
  55. api(getState).post(`/api/v1/tags/${name}/unfollow`).then(({ data }) => {
  56. dispatch(unfollowHashtagSuccess(name, data));
  57. }).catch(err => {
  58. dispatch(unfollowHashtagFail(name, err));
  59. });
  60. };
  61. export const unfollowHashtagRequest = name => ({
  62. type: HASHTAG_UNFOLLOW_REQUEST,
  63. name,
  64. });
  65. export const unfollowHashtagSuccess = (name, tag) => ({
  66. type: HASHTAG_UNFOLLOW_SUCCESS,
  67. name,
  68. tag,
  69. });
  70. export const unfollowHashtagFail = (name, error) => ({
  71. type: HASHTAG_UNFOLLOW_FAIL,
  72. name,
  73. error,
  74. });