soapbox/app/soapbox/actions/import-data.ts

79 wiersze
2.8 KiB
TypeScript
Czysty Zwykły widok Historia

import { defineMessages } from 'react-intl';
2022-12-20 15:47:46 +00:00
import toast from 'soapbox/toast';
2022-01-10 22:01:24 +00:00
import api from '../api';
import type { RootState } from 'soapbox/store';
export const IMPORT_FOLLOWS_REQUEST = 'IMPORT_FOLLOWS_REQUEST';
export const IMPORT_FOLLOWS_SUCCESS = 'IMPORT_FOLLOWS_SUCCESS';
export const IMPORT_FOLLOWS_FAIL = 'IMPORT_FOLLOWS_FAIL';
2020-09-27 17:24:38 +00:00
export const IMPORT_BLOCKS_REQUEST = 'IMPORT_BLOCKS_REQUEST';
export const IMPORT_BLOCKS_SUCCESS = 'IMPORT_BLOCKS_SUCCESS';
export const IMPORT_BLOCKS_FAIL = 'IMPORT_BLOCKS_FAIL';
export const IMPORT_MUTES_REQUEST = 'IMPORT_MUTES_REQUEST';
export const IMPORT_MUTES_SUCCESS = 'IMPORT_MUTES_SUCCESS';
export const IMPORT_MUTES_FAIL = 'IMPORT_MUTES_FAIL';
type ImportDataActions = {
type: typeof IMPORT_FOLLOWS_REQUEST
| typeof IMPORT_FOLLOWS_SUCCESS
| typeof IMPORT_FOLLOWS_FAIL
| typeof IMPORT_BLOCKS_REQUEST
| typeof IMPORT_BLOCKS_SUCCESS
| typeof IMPORT_BLOCKS_FAIL
| typeof IMPORT_MUTES_REQUEST
| typeof IMPORT_MUTES_SUCCESS
| typeof IMPORT_MUTES_FAIL,
error?: any,
config?: string
2022-12-20 17:45:46 +00:00
}
const messages = defineMessages({
blocksSuccess: { id: 'import_data.success.blocks', defaultMessage: 'Blocks imported successfully' },
followersSuccess: { id: 'import_data.success.followers', defaultMessage: 'Followers imported successfully' },
mutesSuccess: { id: 'import_data.success.mutes', defaultMessage: 'Mutes imported successfully' },
});
export const importFollows = (params: FormData) =>
(dispatch: React.Dispatch<ImportDataActions>, getState: () => RootState) => {
dispatch({ type: IMPORT_FOLLOWS_REQUEST });
return api(getState)
.post('/api/pleroma/follow_import', params)
.then(response => {
2022-12-20 15:47:46 +00:00
toast.success(messages.followersSuccess);
dispatch({ type: IMPORT_FOLLOWS_SUCCESS, config: response.data });
}).catch(error => {
dispatch({ type: IMPORT_FOLLOWS_FAIL, error });
});
};
2020-09-27 17:24:38 +00:00
export const importBlocks = (params: FormData) =>
(dispatch: React.Dispatch<ImportDataActions>, getState: () => RootState) => {
2020-09-27 17:24:38 +00:00
dispatch({ type: IMPORT_BLOCKS_REQUEST });
return api(getState)
.post('/api/pleroma/blocks_import', params)
.then(response => {
2022-12-20 15:47:46 +00:00
toast.success(messages.blocksSuccess);
2020-09-27 17:24:38 +00:00
dispatch({ type: IMPORT_BLOCKS_SUCCESS, config: response.data });
}).catch(error => {
dispatch({ type: IMPORT_BLOCKS_FAIL, error });
});
};
export const importMutes = (params: FormData) =>
(dispatch: React.Dispatch<ImportDataActions>, getState: () => RootState) => {
2020-09-27 17:24:38 +00:00
dispatch({ type: IMPORT_MUTES_REQUEST });
return api(getState)
.post('/api/pleroma/mutes_import', params)
.then(response => {
2022-12-20 15:47:46 +00:00
toast.success(messages.mutesSuccess);
2020-09-27 17:24:38 +00:00
dispatch({ type: IMPORT_MUTES_SUCCESS, config: response.data });
}).catch(error => {
dispatch({ type: IMPORT_MUTES_FAIL, error });
});
};