This commit is contained in:
mgabdev
2020-03-02 17:26:25 -05:00
parent c6aa4e08a1
commit 0df3c073a5
43 changed files with 602 additions and 719 deletions

View File

@@ -1,41 +1,41 @@
import api, { getLinks } from '../api';
import { importFetchedStatuses } from './importer';
import { me } from '../initial_state';
import api, { getLinks } from '../api'
import { importFetchedStatuses } from './importer'
import { me } from '../initial_state'
export const FAVORITED_STATUSES_FETCH_REQUEST = 'FAVORITED_STATUSES_FETCH_REQUEST';
export const FAVORITED_STATUSES_FETCH_SUCCESS = 'FAVORITED_STATUSES_FETCH_SUCCESS';
export const FAVORITED_STATUSES_FETCH_FAIL = 'FAVORITED_STATUSES_FETCH_FAIL';
export const FAVORITED_STATUSES_FETCH_REQUEST = 'FAVORITED_STATUSES_FETCH_REQUEST'
export const FAVORITED_STATUSES_FETCH_SUCCESS = 'FAVORITED_STATUSES_FETCH_SUCCESS'
export const FAVORITED_STATUSES_FETCH_FAIL = 'FAVORITED_STATUSES_FETCH_FAIL'
export const FAVORITED_STATUSES_EXPAND_REQUEST = 'FAVORITED_STATUSES_EXPAND_REQUEST';
export const FAVORITED_STATUSES_EXPAND_SUCCESS = 'FAVORITED_STATUSES_EXPAND_SUCCESS';
export const FAVORITED_STATUSES_EXPAND_FAIL = 'FAVORITED_STATUSES_EXPAND_FAIL';
export const FAVORITED_STATUSES_EXPAND_REQUEST = 'FAVORITED_STATUSES_EXPAND_REQUEST'
export const FAVORITED_STATUSES_EXPAND_SUCCESS = 'FAVORITED_STATUSES_EXPAND_SUCCESS'
export const FAVORITED_STATUSES_EXPAND_FAIL = 'FAVORITED_STATUSES_EXPAND_FAIL'
export function fetchFavoritedStatuses() {
return (dispatch, getState) => {
if (!me) return;
if (!me) return
if (getState().getIn(['status_lists', 'favourites', 'isLoading'])) {
return;
if (getState().getIn(['status_lists', 'favorites', 'isLoading'])) {
return
}
dispatch(fetchFavoritedStatusesRequest());
dispatch(fetchFavoritedStatusesRequest())
api(getState).get('/api/v1/favourites').then(response => {
const next = getLinks(response).refs.find(link => link.rel === 'next');
dispatch(importFetchedStatuses(response.data));
dispatch(fetchFavoritedStatusesSuccess(response.data, next ? next.uri : null));
const next = getLinks(response).refs.find(link => link.rel === 'next')
dispatch(importFetchedStatuses(response.data))
dispatch(fetchFavoritedStatusesSuccess(response.data, next ? next.uri : null))
}).catch(error => {
dispatch(fetchFavoritedStatusesFail(error));
});
};
};
dispatch(fetchFavoritedStatusesFail(error))
})
}
}
export function fetchFavoritedStatusesRequest() {
return {
type: FAVORITED_STATUSES_FETCH_REQUEST,
skipLoading: true,
};
};
}
}
export function fetchFavoritedStatusesSuccess(statuses, next) {
return {
@@ -43,56 +43,56 @@ export function fetchFavoritedStatusesSuccess(statuses, next) {
statuses,
next,
skipLoading: true,
};
};
}
}
export function fetchFavoritedStatusesFail(error) {
return {
type: FAVORITED_STATUSES_FETCH_FAIL,
error,
skipLoading: true,
};
};
}
}
export function expandFavoritedStatuses() {
return (dispatch, getState) => {
if (!me) return;
const url = getState().getIn(['status_lists', 'favourites', 'next'], null);
if (!me) return
if (url === null || getState().getIn(['status_lists', 'favourites', 'isLoading'])) {
return;
const url = getState().getIn(['status_lists', 'favorites', 'next'], null)
if (url === null || getState().getIn(['status_lists', 'favorites', 'isLoading'])) {
return
}
dispatch(expandFavoritedStatusesRequest());
dispatch(expandFavoritedStatusesRequest())
api(getState).get(url).then(response => {
const next = getLinks(response).refs.find(link => link.rel === 'next');
dispatch(importFetchedStatuses(response.data));
dispatch(expandFavoritedStatusesSuccess(response.data, next ? next.uri : null));
const next = getLinks(response).refs.find(link => link.rel === 'next')
dispatch(importFetchedStatuses(response.data))
dispatch(expandFavoritedStatusesSuccess(response.data, next ? next.uri : null))
}).catch(error => {
dispatch(expandFavoritedStatusesFail(error));
});
};
};
dispatch(expandFavoritedStatusesFail(error))
})
}
}
export function expandFavoritedStatusesRequest() {
return {
type: FAVORITED_STATUSES_EXPAND_REQUEST,
};
};
}
}
export function expandFavoritedStatusesSuccess(statuses, next) {
return {
type: FAVORITED_STATUSES_EXPAND_SUCCESS,
statuses,
next,
};
};
}
}
export function expandFavoritedStatusesFail(error) {
return {
type: FAVORITED_STATUSES_EXPAND_FAIL,
error,
};
};
}
}

View File

@@ -6,17 +6,17 @@ export const REBLOG_REQUEST = 'REBLOG_REQUEST';
export const REBLOG_SUCCESS = 'REBLOG_SUCCESS';
export const REBLOG_FAIL = 'REBLOG_FAIL';
export const FAVOURITE_REQUEST = 'FAVOURITE_REQUEST';
export const FAVOURITE_SUCCESS = 'FAVOURITE_SUCCESS';
export const FAVOURITE_FAIL = 'FAVOURITE_FAIL';
export const FAVORITE_REQUEST = 'FAVORITE_REQUEST';
export const FAVORITE_SUCCESS = 'FAVORITE_SUCCESS';
export const FAVORITE_FAIL = 'FAVORITE_FAIL';
export const UNREBLOG_REQUEST = 'UNREBLOG_REQUEST';
export const UNREBLOG_SUCCESS = 'UNREBLOG_SUCCESS';
export const UNREBLOG_FAIL = 'UNREBLOG_FAIL';
export const UNFAVOURITE_REQUEST = 'UNFAVOURITE_REQUEST';
export const UNFAVOURITE_SUCCESS = 'UNFAVOURITE_SUCCESS';
export const UNFAVOURITE_FAIL = 'UNFAVOURITE_FAIL';
export const UNFAVORITE_REQUEST = 'UNFAVORITE_REQUEST';
export const UNFAVORITE_SUCCESS = 'UNFAVORITE_SUCCESS';
export const UNFAVORITE_FAIL = 'UNFAVORITE_FAIL';
export const REBLOGS_FETCH_REQUEST = 'REBLOGS_FETCH_REQUEST';
export const REBLOGS_FETCH_SUCCESS = 'REBLOGS_FETCH_SUCCESS';
@@ -144,7 +144,7 @@ export function unfavourite(status) {
export function favouriteRequest(status) {
return {
type: FAVOURITE_REQUEST,
type: FAVORITE_REQUEST,
status: status,
skipLoading: true,
};
@@ -152,7 +152,7 @@ export function favouriteRequest(status) {
export function favouriteSuccess(status) {
return {
type: FAVOURITE_SUCCESS,
type: FAVORITE_SUCCESS,
status: status,
skipLoading: true,
};
@@ -160,7 +160,7 @@ export function favouriteSuccess(status) {
export function favouriteFail(status, error) {
return {
type: FAVOURITE_FAIL,
type: FAVORITE_FAIL,
status: status,
error: error,
skipLoading: true,
@@ -169,7 +169,7 @@ export function favouriteFail(status, error) {
export function unfavouriteRequest(status) {
return {
type: UNFAVOURITE_REQUEST,
type: UNFAVORITE_REQUEST,
status: status,
skipLoading: true,
};
@@ -177,7 +177,7 @@ export function unfavouriteRequest(status) {
export function unfavouriteSuccess(status) {
return {
type: UNFAVOURITE_SUCCESS,
type: UNFAVORITE_SUCCESS,
status: status,
skipLoading: true,
};
@@ -185,7 +185,7 @@ export function unfavouriteSuccess(status) {
export function unfavouriteFail(status, error) {
return {
type: UNFAVOURITE_FAIL,
type: UNFAVORITE_FAIL,
status: status,
error: error,
skipLoading: true,