闭社主体 forked from https://github.com/tootsuite/mastodon
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

83 lines
2.3 KiB

  1. import api, { getLinks } from '../api';
  2. export const FAVOURITED_STATUSES_FETCH_REQUEST = 'FAVOURITED_STATUSES_FETCH_REQUEST';
  3. export const FAVOURITED_STATUSES_FETCH_SUCCESS = 'FAVOURITED_STATUSES_FETCH_SUCCESS';
  4. export const FAVOURITED_STATUSES_FETCH_FAIL = 'FAVOURITED_STATUSES_FETCH_FAIL';
  5. export const FAVOURITED_STATUSES_EXPAND_REQUEST = 'FAVOURITED_STATUSES_EXPAND_REQUEST';
  6. export const FAVOURITED_STATUSES_EXPAND_SUCCESS = 'FAVOURITED_STATUSES_EXPAND_SUCCESS';
  7. export const FAVOURITED_STATUSES_EXPAND_FAIL = 'FAVOURITED_STATUSES_EXPAND_FAIL';
  8. export function fetchFavouritedStatuses() {
  9. return (dispatch, getState) => {
  10. dispatch(fetchFavouritedStatusesRequest());
  11. api(getState).get('/api/v1/favourites').then(response => {
  12. const next = getLinks(response).refs.find(link => link.rel === 'next');
  13. dispatch(fetchFavouritedStatusesSuccess(response.data, next ? next.uri : null));
  14. }).catch(error => {
  15. dispatch(fetchFavouritedStatusesFail(error));
  16. });
  17. };
  18. };
  19. export function fetchFavouritedStatusesRequest() {
  20. return {
  21. type: FAVOURITED_STATUSES_FETCH_REQUEST,
  22. };
  23. };
  24. export function fetchFavouritedStatusesSuccess(statuses, next) {
  25. return {
  26. type: FAVOURITED_STATUSES_FETCH_SUCCESS,
  27. statuses,
  28. next,
  29. };
  30. };
  31. export function fetchFavouritedStatusesFail(error) {
  32. return {
  33. type: FAVOURITED_STATUSES_FETCH_FAIL,
  34. error,
  35. };
  36. };
  37. export function expandFavouritedStatuses() {
  38. return (dispatch, getState) => {
  39. const url = getState().getIn(['status_lists', 'favourites', 'next'], null);
  40. if (url === null) {
  41. return;
  42. }
  43. dispatch(expandFavouritedStatusesRequest());
  44. api(getState).get(url).then(response => {
  45. const next = getLinks(response).refs.find(link => link.rel === 'next');
  46. dispatch(expandFavouritedStatusesSuccess(response.data, next ? next.uri : null));
  47. }).catch(error => {
  48. dispatch(expandFavouritedStatusesFail(error));
  49. });
  50. };
  51. };
  52. export function expandFavouritedStatusesRequest() {
  53. return {
  54. type: FAVOURITED_STATUSES_EXPAND_REQUEST,
  55. };
  56. };
  57. export function expandFavouritedStatusesSuccess(statuses, next) {
  58. return {
  59. type: FAVOURITED_STATUSES_EXPAND_SUCCESS,
  60. statuses,
  61. next,
  62. };
  63. };
  64. export function expandFavouritedStatusesFail(error) {
  65. return {
  66. type: FAVOURITED_STATUSES_EXPAND_FAIL,
  67. error,
  68. };
  69. };