Refactor action/publish.js to use redux action centralized

This commit is contained in:
Chakrit Likitkhajorn 2018-10-13 23:56:52 +07:00
parent d594f46bad
commit 295f6ca61d

View file

@ -19,13 +19,11 @@ import { doNavigate } from 'redux/actions/navigation';
import fs from 'fs';
import path from 'path';
import { CC_LICENSES, COPYRIGHT, OTHER } from 'constants/licenses';
import type { Dispatch, GetState } from 'types/redux';
type Action = UpdatePublishFormAction | { type: ACTIONS.CLEAR_PUBLISH };
type PromiseAction = Promise<Action>;
type Dispatch = (action: Action | PromiseAction | Array<Action>) => any;
type GetState = () => {};
export const doResetThumbnailStatus = () => (dispatch: Dispatch): PromiseAction => {
export const doResetThumbnailStatus = () => (dispatch: Dispatch<Action>): Promise<Action> => {
dispatch({
type: ACTIONS.UPDATE_PUBLISH_FORM,
data: {
@ -61,20 +59,22 @@ export const doResetThumbnailStatus = () => (dispatch: Dispatch): PromiseAction
);
};
export const doClearPublish = () => (dispatch: Dispatch): PromiseAction => {
export const doClearPublish = () => (dispatch: Dispatch<Action>): Promise<Action> => {
dispatch({ type: ACTIONS.CLEAR_PUBLISH });
return dispatch(doResetThumbnailStatus());
};
export const doUpdatePublishForm = (publishFormValue: UpdatePublishFormData) => (
dispatch: Dispatch
dispatch: Dispatch<Action>
): UpdatePublishFormAction =>
dispatch({
type: ACTIONS.UPDATE_PUBLISH_FORM,
data: { ...publishFormValue },
});
export const doUploadThumbnail = (filePath: string, nsfw: boolean) => (dispatch: Dispatch) => {
export const doUploadThumbnail = (filePath: string, nsfw: boolean) => (
dispatch: Dispatch<Action>
) => {
const thumbnail = fs.readFileSync(filePath);
const fileExt = path.extname(filePath);
const fileName = path.basename(filePath);
@ -128,7 +128,7 @@ export const doUploadThumbnail = (filePath: string, nsfw: boolean) => (dispatch:
.catch(err => uploadError(err.message));
};
export const doPrepareEdit = (claim: any, uri: string) => (dispatch: Dispatch) => {
export const doPrepareEdit = (claim: any, uri: string) => (dispatch: Dispatch<Action>) => {
const {
name,
amount,
@ -189,7 +189,10 @@ export const doPrepareEdit = (claim: any, uri: string) => (dispatch: Dispatch) =
dispatch({ type: ACTIONS.DO_PREPARE_EDIT, data: publishData });
};
export const doPublish = (params: PublishParams) => (dispatch: Dispatch, getState: () => {}) => {
export const doPublish = (params: PublishParams) => (
dispatch: Dispatch<Action>,
getState: () => {}
) => {
const state = getState();
const myChannels = selectMyChannelClaims(state);
@ -265,7 +268,7 @@ export const doPublish = (params: PublishParams) => (dispatch: Dispatch, getStat
};
// Calls claim_list_mine until any pending publishes are confirmed
export const doCheckPendingPublishes = () => (dispatch: Dispatch, getState: GetState) => {
export const doCheckPendingPublishes = () => (dispatch: Dispatch<Action>, getState: GetState) => {
const state = getState();
const pendingPublishes = selectPendingPublishes(state);