From 295f6ca61d99880d90828ad5495132799177e451 Mon Sep 17 00:00:00 2001 From: Chakrit Likitkhajorn Date: Sat, 13 Oct 2018 23:56:52 +0700 Subject: [PATCH] Refactor action/publish.js to use redux action centralized --- src/renderer/redux/actions/publish.js | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/renderer/redux/actions/publish.js b/src/renderer/redux/actions/publish.js index 70a5cdcf9..2421375ab 100644 --- a/src/renderer/redux/actions/publish.js +++ b/src/renderer/redux/actions/publish.js @@ -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; -type Dispatch = (action: Action | PromiseAction | Array) => any; -type GetState = () => {}; -export const doResetThumbnailStatus = () => (dispatch: Dispatch): PromiseAction => { +export const doResetThumbnailStatus = () => (dispatch: Dispatch): Promise => { 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): Promise => { dispatch({ type: ACTIONS.CLEAR_PUBLISH }); return dispatch(doResetThumbnailStatus()); }; export const doUpdatePublishForm = (publishFormValue: UpdatePublishFormData) => ( - dispatch: Dispatch + dispatch: Dispatch ): 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 +) => { 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) => { 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, + 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, getState: GetState) => { const state = getState(); const pendingPublishes = selectPendingPublishes(state);