pleroma/src/actions/history.ts

52 lines
1.4 KiB
TypeScript
Raw Normal View History

import { getClient } from 'soapbox/api';
import { importFetchedAccounts } from './importer';
import type { AppDispatch, RootState } from 'soapbox/store';
import type { APIEntity } from 'soapbox/types/entities';
const HISTORY_FETCH_REQUEST = 'HISTORY_FETCH_REQUEST';
const HISTORY_FETCH_SUCCESS = 'HISTORY_FETCH_SUCCESS';
const HISTORY_FETCH_FAIL = 'HISTORY_FETCH_FAIL';
const fetchHistory = (statusId: string) =>
(dispatch: AppDispatch, getState: () => RootState) => {
const loading = getState().history.getIn([statusId, 'loading']);
if (loading) {
return;
}
dispatch(fetchHistoryRequest(statusId));
return getClient(getState()).statuses.getStatusHistory(statusId).then(data => {
dispatch(importFetchedAccounts(data.map((x) => x.account)));
dispatch(fetchHistorySuccess(statusId, data));
}).catch(error => dispatch(fetchHistoryFail(error)));
};
const fetchHistoryRequest = (statusId: string) => ({
type: HISTORY_FETCH_REQUEST,
statusId,
});
const fetchHistorySuccess = (statusId: String, history: APIEntity[]) => ({
type: HISTORY_FETCH_SUCCESS,
statusId,
history,
});
2023-10-23 15:22:10 -07:00
const fetchHistoryFail = (error: unknown) => ({
type: HISTORY_FETCH_FAIL,
error,
});
export {
HISTORY_FETCH_REQUEST,
HISTORY_FETCH_SUCCESS,
HISTORY_FETCH_FAIL,
fetchHistory,
fetchHistoryRequest,
fetchHistorySuccess,
fetchHistoryFail,
};