p5.js-web-editor/client/modules/IDE/actions/assets.js
Andrew Nicolaou a225d28f75 Use apiClient instance instead of directly calling Axios
Reduces the amount of duplication and provides a single place where
we can configure base URL, crendentials and other headers
2020-06-08 12:31:30 +02:00

49 lines
1.1 KiB
JavaScript

import apiClient from '../../../utils/apiClient';
import * as ActionTypes from '../../../constants';
import { startLoader, stopLoader } from './loader';
function setAssets(assets, totalSize) {
return {
type: ActionTypes.SET_ASSETS,
assets,
totalSize
};
}
export function getAssets() {
return (dispatch) => {
dispatch(startLoader());
apiClient.get('/S3/objects')
.then((response) => {
dispatch(setAssets(response.data.assets, response.data.totalSize));
dispatch(stopLoader());
})
.catch(() => {
dispatch({
type: ActionTypes.ERROR
});
dispatch(stopLoader());
});
};
}
export function deleteAsset(assetKey) {
return {
type: ActionTypes.DELETE_ASSET,
key: assetKey
};
}
export function deleteAssetRequest(assetKey) {
return (dispatch) => {
apiClient.delete(`/S3/${assetKey}`)
.then((response) => {
dispatch(deleteAsset(assetKey));
})
.catch(() => {
dispatch({
type: ActionTypes.ERROR
});
});
};
}