2018-03-26 23:32:43 +02:00
|
|
|
// @flow
|
2018-10-29 18:23:53 +01:00
|
|
|
import * as MODALS from 'constants/modal_types';
|
2019-07-12 16:58:24 +02:00
|
|
|
import * as ACTIONS from 'constants/action_types';
|
2019-10-23 21:39:51 +02:00
|
|
|
import * as PAGES from 'constants/pages';
|
2020-04-24 15:51:00 +02:00
|
|
|
import {
|
|
|
|
batchActions,
|
|
|
|
selectMyClaims,
|
|
|
|
doPublish,
|
2020-06-21 18:51:06 +02:00
|
|
|
doCheckPendingClaims,
|
2020-05-07 14:22:55 +02:00
|
|
|
doCheckReflectingFiles,
|
2020-04-24 15:51:00 +02:00
|
|
|
ACTIONS as LBRY_REDUX_ACTIONS,
|
2021-03-30 01:05:18 +02:00
|
|
|
makeSelectPublishFormValue,
|
|
|
|
makeSelectClaimForUri,
|
2020-04-24 15:51:00 +02:00
|
|
|
} from 'lbry-redux';
|
2020-06-12 22:44:25 +02:00
|
|
|
import { doError } from 'redux/actions/notifications';
|
2019-07-13 04:59:45 +02:00
|
|
|
import { push } from 'connected-react-router';
|
|
|
|
import analytics from 'analytics';
|
2020-10-05 20:31:51 +02:00
|
|
|
import { doOpenModal } from 'redux/actions/app';
|
2021-03-26 23:03:16 +01:00
|
|
|
export const NO_FILE = '---';
|
2020-11-16 20:09:00 +01:00
|
|
|
export const doPublishDesktop = (filePath: string, preview?: boolean) => (dispatch: Dispatch, getState: () => {}) => {
|
2021-03-24 06:22:02 +01:00
|
|
|
const publishPreview = (previewResponse) => {
|
2020-07-31 15:33:49 +02:00
|
|
|
dispatch(
|
|
|
|
doOpenModal(MODALS.PUBLISH_PREVIEW, {
|
|
|
|
previewResponse,
|
|
|
|
})
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2021-03-30 01:05:18 +02:00
|
|
|
const noFileParam = !filePath || filePath === NO_FILE;
|
|
|
|
const state = getState();
|
|
|
|
const editingUri = makeSelectPublishFormValue('editingURI')(state) || '';
|
2021-04-14 06:06:11 +02:00
|
|
|
const remoteUrl = makeSelectPublishFormValue('remoteFileUrl')(state);
|
2021-03-30 01:05:18 +02:00
|
|
|
const claim = makeSelectClaimForUri(editingUri)(state) || {};
|
|
|
|
const hasSourceFile = claim.value && claim.value.source;
|
2021-04-14 06:06:11 +02:00
|
|
|
const redirectToLivestream = noFileParam && !hasSourceFile && !remoteUrl;
|
2021-03-26 23:03:16 +01:00
|
|
|
|
2020-07-09 16:58:43 +02:00
|
|
|
const publishSuccess = (successResponse, lbryFirstError) => {
|
2019-07-12 16:58:24 +02:00
|
|
|
const state = getState();
|
2019-07-13 04:59:45 +02:00
|
|
|
const myClaims = selectMyClaims(state);
|
2019-04-24 16:02:08 +02:00
|
|
|
const pendingClaim = successResponse.outputs[0];
|
2019-10-16 23:36:50 +02:00
|
|
|
analytics.apiLogPublish(pendingClaim);
|
2019-10-12 03:55:54 +02:00
|
|
|
const { permanent_url: url } = pendingClaim;
|
2018-11-02 19:33:00 +01:00
|
|
|
const actions = [];
|
|
|
|
|
2019-11-13 16:59:34 +01:00
|
|
|
// @if TARGET='app'
|
2020-07-23 19:02:07 +02:00
|
|
|
actions.push(push(`/$/${PAGES.UPLOADS}`));
|
2019-11-13 16:59:34 +01:00
|
|
|
// @endif
|
2019-11-07 20:39:22 +01:00
|
|
|
|
2018-11-02 19:33:00 +01:00
|
|
|
actions.push({
|
2018-04-06 08:00:36 +02:00
|
|
|
type: ACTIONS.PUBLISH_SUCCESS,
|
|
|
|
});
|
2021-03-30 01:05:18 +02:00
|
|
|
|
2018-11-02 19:33:00 +01: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
|
2021-03-24 06:22:02 +01:00
|
|
|
const isMatch = (claim) => claim.claim_id === pendingClaim.claim_id;
|
2018-11-02 19:33:00 +01:00
|
|
|
const isEdit = myClaims.some(isMatch);
|
2019-06-25 06:05:46 +02:00
|
|
|
|
2020-04-24 15:51:00 +02:00
|
|
|
actions.push({
|
|
|
|
type: LBRY_REDUX_ACTIONS.UPDATE_PENDING_CLAIMS,
|
|
|
|
data: {
|
|
|
|
claims: [pendingClaim],
|
|
|
|
},
|
|
|
|
});
|
2020-05-07 14:22:55 +02:00
|
|
|
// @if TARGET='app'
|
|
|
|
actions.push({
|
|
|
|
type: LBRY_REDUX_ACTIONS.ADD_FILES_REFLECTING,
|
|
|
|
data: pendingClaim,
|
|
|
|
});
|
|
|
|
// @endif
|
2020-04-24 15:51:00 +02:00
|
|
|
|
|
|
|
dispatch(batchActions(...actions));
|
|
|
|
dispatch(
|
2019-11-13 16:59:34 +01:00
|
|
|
doOpenModal(MODALS.PUBLISH, {
|
|
|
|
uri: url,
|
|
|
|
isEdit,
|
|
|
|
filePath,
|
2020-07-09 16:58:43 +02:00
|
|
|
lbryFirstError,
|
2019-11-13 16:59:34 +01:00
|
|
|
})
|
|
|
|
);
|
2020-07-23 16:22:57 +02:00
|
|
|
dispatch(doCheckPendingClaims());
|
2020-05-07 14:22:55 +02:00
|
|
|
// @if TARGET='app'
|
|
|
|
dispatch(doCheckReflectingFiles());
|
|
|
|
// @endif
|
2021-03-30 01:05:18 +02:00
|
|
|
// @if TARGET='web'
|
|
|
|
if (redirectToLivestream) {
|
|
|
|
dispatch(push(`/$/${PAGES.LIVESTREAM}`));
|
|
|
|
}
|
|
|
|
// @endif
|
2018-04-06 08:00:36 +02:00
|
|
|
};
|
2018-03-26 23:32:43 +02:00
|
|
|
|
2021-03-24 06:22:02 +01:00
|
|
|
const publishFail = (error) => {
|
2019-07-12 16:58:24 +02:00
|
|
|
const actions = [];
|
2019-11-13 16:59:34 +01:00
|
|
|
actions.push({
|
|
|
|
type: ACTIONS.PUBLISH_FAIL,
|
|
|
|
});
|
2019-07-12 16:58:24 +02:00
|
|
|
actions.push(doError(error.message));
|
|
|
|
dispatch(batchActions(...actions));
|
2018-03-26 23:32:43 +02:00
|
|
|
};
|
2019-07-09 08:02:08 +02:00
|
|
|
|
2020-07-31 15:33:49 +02:00
|
|
|
if (preview) {
|
|
|
|
dispatch(doPublish(publishSuccess, publishFail, publishPreview));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-11-13 16:59:34 +01: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'
|
2021-03-30 01:05:18 +02:00
|
|
|
if (!redirectToLivestream) {
|
|
|
|
dispatch(push(`/$/${PAGES.UPLOADS}`));
|
|
|
|
}
|
2019-11-13 16:59:34 +01:00
|
|
|
// @endif
|
|
|
|
|
2019-10-23 21:39:51 +02:00
|
|
|
dispatch(doPublish(publishSuccess, publishFail));
|
2018-03-26 23:32:43 +02:00
|
|
|
};
|