2022-04-06 20:53:29 +00:00
|
|
|
import api, { getLinks } from '../api';
|
2023-05-23 15:15:17 +00:00
|
|
|
|
2024-06-13 13:04:16 +00:00
|
|
|
import { importFetchedStatuses, importFetchedAccounts } from './importer';
|
2019-08-06 15:57:52 +00:00
|
|
|
|
2022-02-24 23:34:33 +00:00
|
|
|
export const TRENDS_TAGS_FETCH_REQUEST = 'TRENDS_TAGS_FETCH_REQUEST';
|
|
|
|
export const TRENDS_TAGS_FETCH_SUCCESS = 'TRENDS_TAGS_FETCH_SUCCESS';
|
|
|
|
export const TRENDS_TAGS_FETCH_FAIL = 'TRENDS_TAGS_FETCH_FAIL';
|
2019-08-06 15:57:52 +00:00
|
|
|
|
2022-02-24 23:34:33 +00:00
|
|
|
export const TRENDS_LINKS_FETCH_REQUEST = 'TRENDS_LINKS_FETCH_REQUEST';
|
|
|
|
export const TRENDS_LINKS_FETCH_SUCCESS = 'TRENDS_LINKS_FETCH_SUCCESS';
|
|
|
|
export const TRENDS_LINKS_FETCH_FAIL = 'TRENDS_LINKS_FETCH_FAIL';
|
|
|
|
|
|
|
|
export const TRENDS_STATUSES_FETCH_REQUEST = 'TRENDS_STATUSES_FETCH_REQUEST';
|
|
|
|
export const TRENDS_STATUSES_FETCH_SUCCESS = 'TRENDS_STATUSES_FETCH_SUCCESS';
|
|
|
|
export const TRENDS_STATUSES_FETCH_FAIL = 'TRENDS_STATUSES_FETCH_FAIL';
|
|
|
|
|
2022-04-06 20:53:29 +00:00
|
|
|
export const TRENDS_STATUSES_EXPAND_REQUEST = 'TRENDS_STATUSES_EXPAND_REQUEST';
|
|
|
|
export const TRENDS_STATUSES_EXPAND_SUCCESS = 'TRENDS_STATUSES_EXPAND_SUCCESS';
|
|
|
|
export const TRENDS_STATUSES_EXPAND_FAIL = 'TRENDS_STATUSES_EXPAND_FAIL';
|
|
|
|
|
2024-05-22 14:45:18 +00:00
|
|
|
export const fetchTrendingHashtags = () => (dispatch) => {
|
2022-02-24 23:34:33 +00:00
|
|
|
dispatch(fetchTrendingHashtagsRequest());
|
|
|
|
|
2024-05-22 14:45:18 +00:00
|
|
|
api()
|
2022-02-24 23:34:33 +00:00
|
|
|
.get('/api/v1/trends/tags')
|
|
|
|
.then(({ data }) => dispatch(fetchTrendingHashtagsSuccess(data)))
|
|
|
|
.catch(err => dispatch(fetchTrendingHashtagsFail(err)));
|
|
|
|
};
|
|
|
|
|
|
|
|
export const fetchTrendingHashtagsRequest = () => ({
|
|
|
|
type: TRENDS_TAGS_FETCH_REQUEST,
|
|
|
|
skipLoading: true,
|
|
|
|
});
|
|
|
|
|
|
|
|
export const fetchTrendingHashtagsSuccess = trends => ({
|
|
|
|
type: TRENDS_TAGS_FETCH_SUCCESS,
|
|
|
|
trends,
|
|
|
|
skipLoading: true,
|
|
|
|
});
|
|
|
|
|
|
|
|
export const fetchTrendingHashtagsFail = error => ({
|
|
|
|
type: TRENDS_TAGS_FETCH_FAIL,
|
|
|
|
error,
|
|
|
|
skipLoading: true,
|
|
|
|
skipAlert: true,
|
|
|
|
});
|
|
|
|
|
2024-05-22 14:45:18 +00:00
|
|
|
export const fetchTrendingLinks = () => (dispatch) => {
|
2022-02-24 23:34:33 +00:00
|
|
|
dispatch(fetchTrendingLinksRequest());
|
2019-08-06 15:57:52 +00:00
|
|
|
|
2024-05-22 14:45:18 +00:00
|
|
|
api()
|
2024-06-13 13:04:16 +00:00
|
|
|
.get('/api/v1/trends/links', { params: { limit: 20 } })
|
|
|
|
.then(({ data }) => {
|
2024-06-27 13:17:18 +00:00
|
|
|
dispatch(importFetchedAccounts(data.flatMap(link => link.authors.map(author => author.account)).filter(account => !!account)));
|
2024-06-13 13:04:16 +00:00
|
|
|
dispatch(fetchTrendingLinksSuccess(data));
|
|
|
|
})
|
2022-02-24 23:34:33 +00:00
|
|
|
.catch(err => dispatch(fetchTrendingLinksFail(err)));
|
2019-08-06 15:57:52 +00:00
|
|
|
};
|
|
|
|
|
2022-02-24 23:34:33 +00:00
|
|
|
export const fetchTrendingLinksRequest = () => ({
|
|
|
|
type: TRENDS_LINKS_FETCH_REQUEST,
|
2019-08-06 15:57:52 +00:00
|
|
|
skipLoading: true,
|
|
|
|
});
|
|
|
|
|
2022-02-24 23:34:33 +00:00
|
|
|
export const fetchTrendingLinksSuccess = trends => ({
|
|
|
|
type: TRENDS_LINKS_FETCH_SUCCESS,
|
2019-08-06 15:57:52 +00:00
|
|
|
trends,
|
|
|
|
skipLoading: true,
|
|
|
|
});
|
|
|
|
|
2022-02-24 23:34:33 +00:00
|
|
|
export const fetchTrendingLinksFail = error => ({
|
|
|
|
type: TRENDS_LINKS_FETCH_FAIL,
|
|
|
|
error,
|
|
|
|
skipLoading: true,
|
|
|
|
skipAlert: true,
|
|
|
|
});
|
|
|
|
|
|
|
|
export const fetchTrendingStatuses = () => (dispatch, getState) => {
|
2022-04-06 20:53:29 +00:00
|
|
|
if (getState().getIn(['status_lists', 'trending', 'isLoading'])) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-02-24 23:34:33 +00:00
|
|
|
dispatch(fetchTrendingStatusesRequest());
|
|
|
|
|
2024-05-22 14:45:18 +00:00
|
|
|
api().get('/api/v1/trends/statuses').then(response => {
|
2022-04-06 20:53:29 +00:00
|
|
|
const next = getLinks(response).refs.find(link => link.rel === 'next');
|
|
|
|
dispatch(importFetchedStatuses(response.data));
|
|
|
|
dispatch(fetchTrendingStatusesSuccess(response.data, next ? next.uri : null));
|
2022-02-24 23:34:33 +00:00
|
|
|
}).catch(err => dispatch(fetchTrendingStatusesFail(err)));
|
|
|
|
};
|
|
|
|
|
|
|
|
export const fetchTrendingStatusesRequest = () => ({
|
|
|
|
type: TRENDS_STATUSES_FETCH_REQUEST,
|
|
|
|
skipLoading: true,
|
|
|
|
});
|
|
|
|
|
2022-04-06 20:53:29 +00:00
|
|
|
export const fetchTrendingStatusesSuccess = (statuses, next) => ({
|
2022-02-24 23:34:33 +00:00
|
|
|
type: TRENDS_STATUSES_FETCH_SUCCESS,
|
|
|
|
statuses,
|
2022-04-06 20:53:29 +00:00
|
|
|
next,
|
2022-02-24 23:34:33 +00:00
|
|
|
skipLoading: true,
|
|
|
|
});
|
|
|
|
|
|
|
|
export const fetchTrendingStatusesFail = error => ({
|
|
|
|
type: TRENDS_STATUSES_FETCH_FAIL,
|
2019-08-06 15:57:52 +00:00
|
|
|
error,
|
|
|
|
skipLoading: true,
|
|
|
|
skipAlert: true,
|
|
|
|
});
|
2022-04-06 20:53:29 +00:00
|
|
|
|
|
|
|
|
|
|
|
export const expandTrendingStatuses = () => (dispatch, getState) => {
|
|
|
|
const url = getState().getIn(['status_lists', 'trending', 'next'], null);
|
|
|
|
|
|
|
|
if (url === null || getState().getIn(['status_lists', 'trending', 'isLoading'])) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
dispatch(expandTrendingStatusesRequest());
|
|
|
|
|
2024-05-22 14:45:18 +00:00
|
|
|
api().get(url).then(response => {
|
2022-04-06 20:53:29 +00:00
|
|
|
const next = getLinks(response).refs.find(link => link.rel === 'next');
|
|
|
|
dispatch(importFetchedStatuses(response.data));
|
|
|
|
dispatch(expandTrendingStatusesSuccess(response.data, next ? next.uri : null));
|
|
|
|
}).catch(error => {
|
|
|
|
dispatch(expandTrendingStatusesFail(error));
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
export const expandTrendingStatusesRequest = () => ({
|
|
|
|
type: TRENDS_STATUSES_EXPAND_REQUEST,
|
|
|
|
});
|
|
|
|
|
|
|
|
export const expandTrendingStatusesSuccess = (statuses, next) => ({
|
|
|
|
type: TRENDS_STATUSES_EXPAND_SUCCESS,
|
|
|
|
statuses,
|
|
|
|
next,
|
|
|
|
});
|
|
|
|
|
|
|
|
export const expandTrendingStatusesFail = error => ({
|
|
|
|
type: TRENDS_STATUSES_EXPAND_FAIL,
|
|
|
|
error,
|
|
|
|
});
|