import { getClient } from 'soapbox/api'; import { importFetchedAccounts } from './importer'; import type { StatusEdit } from 'pl-api'; import type { AppDispatch, RootState } from 'soapbox/store'; const HISTORY_FETCH_REQUEST = 'HISTORY_FETCH_REQUEST' as const; const HISTORY_FETCH_SUCCESS = 'HISTORY_FETCH_SUCCESS' as const; const HISTORY_FETCH_FAIL = 'HISTORY_FETCH_FAIL' as const; 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(statusId, error))); }; const fetchHistoryRequest = (statusId: string) => ({ type: HISTORY_FETCH_REQUEST, statusId, }); const fetchHistorySuccess = (statusId: string, history: Array) => ({ type: HISTORY_FETCH_SUCCESS, statusId, history, }); const fetchHistoryFail = (statusId: string, error: unknown) => ({ type: HISTORY_FETCH_FAIL, statusId, error, }); type HistoryAction = ReturnType | ReturnType | ReturnType; export { HISTORY_FETCH_REQUEST, HISTORY_FETCH_SUCCESS, HISTORY_FETCH_FAIL, fetchHistory, fetchHistoryRequest, fetchHistorySuccess, fetchHistoryFail, type HistoryAction, };