2018-03-26 14:32:43 -07:00
|
|
|
// @flow
|
2018-10-29 13:23:53 -04:00
|
|
|
import * as MODALS from 'constants/modal_types';
|
2019-07-12 10:58:24 -04:00
|
|
|
import * as ACTIONS from 'constants/action_types';
|
2019-10-23 15:39:51 -04:00
|
|
|
import * as PAGES from 'constants/pages';
|
2020-04-24 09:51:00 -04:00
|
|
|
import {
|
|
|
|
batchActions,
|
|
|
|
selectMyClaims,
|
|
|
|
doPublish,
|
2020-06-21 12:51:06 -04:00
|
|
|
doCheckPendingClaims,
|
2020-05-07 08:22:55 -04:00
|
|
|
doCheckReflectingFiles,
|
2020-04-24 09:51:00 -04:00
|
|
|
ACTIONS as LBRY_REDUX_ACTIONS,
|
|
|
|
} from 'lbry-redux';
|
2020-06-12 16:44:25 -04:00
|
|
|
import { doError } from 'redux/actions/notifications';
|
2019-07-12 22:59:45 -04:00
|
|
|
import { push } from 'connected-react-router';
|
|
|
|
import analytics from 'analytics';
|
2020-10-05 14:31:51 -04:00
|
|
|
import { doOpenModal } from 'redux/actions/app';
|
2018-03-26 14:32:43 -07:00
|
|
|
|
2020-11-02 11:51:08 -05:00
|
|
|
export const doPublishDesktop = (filePath: string, preview?: boolean) => (
|
|
|
|
dispatch: Dispatch<*>,
|
|
|
|
getState: () => {}
|
|
|
|
) => {
|
2020-07-31 21:33:49 +08:00
|
|
|
const publishPreview = previewResponse => {
|
|
|
|
dispatch(
|
|
|
|
doOpenModal(MODALS.PUBLISH_PREVIEW, {
|
|
|
|
previewResponse,
|
|
|
|
})
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2020-07-09 10:58:43 -04:00
|
|
|
const publishSuccess = (successResponse, lbryFirstError) => {
|
2019-07-12 10:58:24 -04:00
|
|
|
const state = getState();
|
2019-07-12 22:59:45 -04:00
|
|
|
const myClaims = selectMyClaims(state);
|
2019-04-24 10:02:08 -04:00
|
|
|
const pendingClaim = successResponse.outputs[0];
|
2019-10-16 17:36:50 -04:00
|
|
|
analytics.apiLogPublish(pendingClaim);
|
2019-10-11 21:55:54 -04:00
|
|
|
const { permanent_url: url } = pendingClaim;
|
2018-11-02 14:33:00 -04:00
|
|
|
const actions = [];
|
|
|
|
|
2019-11-13 10:59:34 -05:00
|
|
|
// @if TARGET='app'
|
2020-07-23 13:02:07 -04:00
|
|
|
actions.push(push(`/$/${PAGES.UPLOADS}`));
|
2019-11-13 10:59:34 -05:00
|
|
|
// @endif
|
2019-11-07 14:39:22 -05:00
|
|
|
|
2018-11-02 14:33:00 -04:00
|
|
|
actions.push({
|
2018-04-06 02:00:36 -04:00
|
|
|
type: ACTIONS.PUBLISH_SUCCESS,
|
|
|
|
});
|
2018-11-02 14:33:00 -04:00
|
|
|
// We have to fake a temp claim until the new pending one is returned by claim_list_mine
|
|
|
|
// We can't rely on claim_list_mine because there might be some delay before the new claims are returned
|
|
|
|
// Doing this allows us to show the pending claim immediately, it will get overwritten by the real one
|
|
|
|
const isMatch = claim => claim.claim_id === pendingClaim.claim_id;
|
|
|
|
const isEdit = myClaims.some(isMatch);
|
2019-06-24 23:05:46 -05:00
|
|
|
|
2020-04-24 09:51:00 -04:00
|
|
|
actions.push({
|
|
|
|
type: LBRY_REDUX_ACTIONS.UPDATE_PENDING_CLAIMS,
|
|
|
|
data: {
|
|
|
|
claims: [pendingClaim],
|
|
|
|
},
|
|
|
|
});
|
2020-05-07 08:22:55 -04:00
|
|
|
// @if TARGET='app'
|
|
|
|
actions.push({
|
|
|
|
type: LBRY_REDUX_ACTIONS.ADD_FILES_REFLECTING,
|
|
|
|
data: pendingClaim,
|
|
|
|
});
|
|
|
|
// @endif
|
2020-04-24 09:51:00 -04:00
|
|
|
|
|
|
|
dispatch(batchActions(...actions));
|
|
|
|
dispatch(
|
2019-11-13 10:59:34 -05:00
|
|
|
doOpenModal(MODALS.PUBLISH, {
|
|
|
|
uri: url,
|
|
|
|
isEdit,
|
|
|
|
filePath,
|
2020-07-09 10:58:43 -04:00
|
|
|
lbryFirstError,
|
2019-11-13 10:59:34 -05:00
|
|
|
})
|
|
|
|
);
|
2020-07-23 10:22:57 -04:00
|
|
|
dispatch(doCheckPendingClaims());
|
2020-05-07 08:22:55 -04:00
|
|
|
// @if TARGET='app'
|
|
|
|
dispatch(doCheckReflectingFiles());
|
|
|
|
// @endif
|
2018-04-06 02:00:36 -04:00
|
|
|
};
|
2018-03-26 14:32:43 -07:00
|
|
|
|
2019-07-12 10:58:24 -04:00
|
|
|
const publishFail = error => {
|
|
|
|
const actions = [];
|
2019-11-13 10:59:34 -05:00
|
|
|
actions.push({
|
|
|
|
type: ACTIONS.PUBLISH_FAIL,
|
|
|
|
});
|
2019-07-12 10:58:24 -04:00
|
|
|
actions.push(doError(error.message));
|
|
|
|
dispatch(batchActions(...actions));
|
2018-03-26 14:32:43 -07:00
|
|
|
};
|
2019-07-09 02:02:08 -04:00
|
|
|
|
2020-07-31 21:33:49 +08:00
|
|
|
if (preview) {
|
|
|
|
dispatch(doPublish(publishSuccess, publishFail, publishPreview));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-11-13 10:59:34 -05:00
|
|
|
// Redirect on web immediately because we have a file upload progress componenet
|
|
|
|
// on the publishes page. This doesn't exist on desktop so wait until we get a response
|
|
|
|
// from the SDK
|
|
|
|
// @if TARGET='web'
|
2020-07-23 13:02:07 -04:00
|
|
|
dispatch(push(`/$/${PAGES.UPLOADS}`));
|
2019-11-13 10:59:34 -05:00
|
|
|
// @endif
|
|
|
|
|
2019-10-23 15:39:51 -04:00
|
|
|
dispatch(doPublish(publishSuccess, publishFail));
|
2018-03-26 14:32:43 -07:00
|
|
|
};
|