logo

mastofe

My custom branche(s) on git.pleroma.social/pleroma/mastofe git clone https://hacktivis.me/git/mastofe.git

favourites.js (2686B)


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