2024-08-04 07:09:52 -07:00
|
|
|
import { getClient } from '../api';
|
2022-03-21 11:09:01 -07:00
|
|
|
|
|
|
|
import { importFetchedStatuses } from './importer';
|
|
|
|
|
2024-08-28 04:41:08 -07:00
|
|
|
import type { AppDispatch, RootState } from 'pl-fe/store';
|
2022-03-21 11:09:01 -07:00
|
|
|
|
2024-08-11 01:48:58 -07:00
|
|
|
const TRENDING_STATUSES_FETCH_REQUEST = 'TRENDING_STATUSES_FETCH_REQUEST' as const;
|
|
|
|
const TRENDING_STATUSES_FETCH_SUCCESS = 'TRENDING_STATUSES_FETCH_SUCCESS' as const;
|
|
|
|
const TRENDING_STATUSES_FETCH_FAIL = 'TRENDING_STATUSES_FETCH_FAIL' as const;
|
2022-06-15 13:11:36 -07:00
|
|
|
|
|
|
|
const fetchTrendingStatuses = () =>
|
|
|
|
(dispatch: AppDispatch, getState: () => RootState) => {
|
2022-03-29 12:15:06 -07:00
|
|
|
const state = getState();
|
2024-08-11 01:48:58 -07:00
|
|
|
const client = getClient(state);
|
2022-03-29 12:15:06 -07:00
|
|
|
|
2024-08-11 01:48:58 -07:00
|
|
|
if (!client.features.trendingStatuses) return;
|
2022-12-27 12:42:17 -08:00
|
|
|
|
2022-03-21 11:09:01 -07:00
|
|
|
dispatch({ type: TRENDING_STATUSES_FETCH_REQUEST });
|
2024-08-04 07:09:52 -07:00
|
|
|
|
2024-08-11 01:48:58 -07:00
|
|
|
return client.trends.getTrendingStatuses().then((statuses) => {
|
2022-03-21 11:09:01 -07:00
|
|
|
dispatch(importFetchedStatuses(statuses));
|
|
|
|
dispatch({ type: TRENDING_STATUSES_FETCH_SUCCESS, statuses });
|
|
|
|
return statuses;
|
|
|
|
}).catch(error => {
|
|
|
|
dispatch({ type: TRENDING_STATUSES_FETCH_FAIL, error });
|
|
|
|
});
|
|
|
|
};
|
2022-06-15 13:11:36 -07:00
|
|
|
|
|
|
|
export {
|
|
|
|
TRENDING_STATUSES_FETCH_REQUEST,
|
|
|
|
TRENDING_STATUSES_FETCH_SUCCESS,
|
|
|
|
TRENDING_STATUSES_FETCH_FAIL,
|
|
|
|
fetchTrendingStatuses,
|
|
|
|
};
|