successfully publishes using lbry-redux

updates lbry-redux hash

adds streamPublish success and fail callbacks

passing callbacks in doPublish( success, fail )

update redux

prepare rebase
This commit is contained in:
jessop 2019-07-02 22:30:34 -04:00 committed by Sean Yesmunt
parent 6eafb3a561
commit f2c51f7735
18 changed files with 243 additions and 152 deletions

View file

@ -1,19 +1,18 @@
import { connect } from 'react-redux';
import { doResolveUri, selectBalance } from 'lbry-redux';
import {
doResolveUri,
selectBalance,
selectPublishFormValues,
selectIsStillEditing,
selectMyClaimForUri,
selectIsResolvingPublishUris,
selectTakeOverAmount,
} from 'redux/selectors/publish';
import {
doResetThumbnailStatus,
doClearPublish,
doUpdatePublishForm,
doPublish,
doPrepareEdit,
} from 'redux/actions/publish';
} from 'lbry-redux';
import { doPublish } from 'redux/actions/publish';
import { selectUnclaimedRewardValue } from 'lbryinc';
import PublishPage from './view';

View file

@ -1,7 +1,6 @@
import { connect } from 'react-redux';
import { selectBalance } from 'lbry-redux';
import { selectIsStillEditing, makeSelectPublishFormValue } from 'redux/selectors/publish';
import { doUpdatePublishForm } from 'redux/actions/publish';
import { selectBalance, selectIsStillEditing, makeSelectPublishFormValue, doUpdatePublishForm } from 'lbry-redux';
import PublishPage from './view';
const select = state => ({

View file

@ -1,19 +1,17 @@
import { connect } from 'react-redux';
import { doResolveUri } from 'lbry-redux';
import {
doResolveUri,
selectPublishFormValues,
selectIsStillEditing,
selectMyClaimForUri,
selectIsResolvingPublishUris,
selectTakeOverAmount,
} from 'redux/selectors/publish';
import {
doResetThumbnailStatus,
doClearPublish,
doUpdatePublishForm,
doPublish,
doPrepareEdit,
} from 'redux/actions/publish';
} from 'lbry-redux';
import { doPublish } from 'redux/actions/publish';
import { selectUnclaimedRewardValue } from 'lbryinc';
import PublishPage from './view';
@ -34,7 +32,7 @@ const perform = dispatch => ({
updatePublishForm: value => dispatch(doUpdatePublishForm(value)),
clearPublish: () => dispatch(doClearPublish()),
resolveUri: uri => dispatch(doResolveUri(uri)),
publish: params => dispatch(doPublish(params)),
publish: (success, fail) => dispatch(doPublish(success, fail)),
prepareEdit: (claim, uri) => dispatch(doPrepareEdit(claim, uri)),
resetThumbnailStatus: () => dispatch(doResetThumbnailStatus()),
});

View file

@ -170,7 +170,7 @@ function PublishForm(props: Props) {
<div className="card__actions">
<Button
button="primary"
onClick={publish}
onClick={() => publish(success, fail)}
label={submitLabel}
disabled={formDisabled || !formValid || uploadThumbnailStatus === THUMBNAIL_STATUSES.IN_PROGRESS}
/>

View file

@ -1,5 +1,5 @@
import { connect } from 'react-redux';
import { makeSelectPublishFormValue, selectIsStillEditing } from 'redux/selectors/publish';
import { makeSelectPublishFormValue, selectIsStillEditing } from 'lbry-redux';
import PublishPage from './view';
const select = state => ({

View file

@ -5,9 +5,11 @@ import {
selectMyClaimForUri,
selectIsResolvingPublishUris,
selectTakeOverAmount,
} from 'redux/selectors/publish';
import { doUpdatePublishForm, doPrepareEdit } from 'redux/actions/publish';
import { selectBalance } from 'lbry-redux';
doUpdatePublishForm,
doPrepareEdit,
selectBalance,
} from 'lbry-redux';
import PublishPage from './view';
const select = state => ({
@ -15,7 +17,6 @@ const select = state => ({
channel: makeSelectPublishFormValue('channel')(state),
bid: makeSelectPublishFormValue('bid')(state),
uri: makeSelectPublishFormValue('uri')(state),
bid: makeSelectPublishFormValue('bid')(state),
isStillEditing: selectIsStillEditing(state),
isResolvingUri: selectIsResolvingPublishUris(state),
amountNeededForTakeover: selectTakeOverAmount(state),

View file

@ -1,6 +1,5 @@
import { connect } from 'react-redux';
import { doUpdatePublishForm } from 'redux/actions/publish';
import { makeSelectPublishFormValue } from 'redux/selectors/publish';
import { makeSelectPublishFormValue, doUpdatePublishForm } from 'lbry-redux';
import PublishPage from './view';
const select = state => ({

View file

@ -1,6 +1,5 @@
import { connect } from 'react-redux';
import { makeSelectPublishFormValue } from 'redux/selectors/publish';
import { doUpdatePublishForm } from 'redux/actions/publish';
import { doUpdatePublishForm, makeSelectPublishFormValue } from 'lbry-redux';
import PublishPage from './view';
const select = state => ({

View file

@ -1,20 +1,19 @@
import { connect } from 'react-redux';
import { doResolveUri } from 'lbry-redux';
import {
doResolveUri,
selectPublishFormValues,
selectIsStillEditing,
selectMyClaimForUri,
selectIsResolvingPublishUris,
selectTakeOverAmount,
} from 'redux/selectors/publish';
import {
doResetThumbnailStatus,
doClearPublish,
doUpdatePublishForm,
doPublish,
doPrepareEdit,
} from 'redux/actions/publish';
} from 'lbry-redux';
import { doOpenModal } from 'redux/actions/app';
import { doPublish } from 'redux/actions/publish';
import { selectUnclaimedRewardValue } from 'lbryinc';
import PublishPage from './view';

View file

@ -12,7 +12,16 @@ import React, { useState, useEffect } from 'react';
import ReactDOM from 'react-dom';
import { Provider } from 'react-redux';
import { doConditionalAuthNavigate, doDaemonReady, doAutoUpdate, doOpenModal, doHideModal } from 'redux/actions/app';
import { Lbry, doToast, isURIValid, setSearchApi } from 'lbry-redux';
import {
Lbry,
doToast,
isURIValid,
setSearchApi,
// reduxCallbacks,
// batchActions,
// selectMyClaimsWithoutChannels,
// doError,
} from 'lbry-redux';
import { doInitLanguage, doUpdateIsNightAsync } from 'redux/actions/settings';
import {
doAuthenticate,
@ -129,6 +138,45 @@ rewards.setCallback('claimRewardSuccess', () => {
app.store.dispatch(doHideModal(MODALS.REWARD_APPROVAL_REQUIRED));
});
// mimicking app.js.doOpenModal(id, modalProps {}) here
// reduxCallbacks.setCallback('streamPublishSuccess', successResponse => {
// const state = store.getState();
// analytics.apiLogPublish();
// const myClaims = selectMyClaimsWithoutChannels(state);
// const pendingClaim = successResponse.outputs[0];
// const uri = pendingClaim.permanent_url;
// const actions = [];
//
// actions.push({
// type: ACTIONS.PUBLISH_SUCCESS,
// });
//
// // 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);
//
// const myNewClaims = isEdit
// ? myClaims.map(claim => (isMatch(claim) ? pendingClaim : claim))
// : myClaims.concat(pendingClaim);
//
// actions.push(doOpenModal(MODALS.PUBLISH, { uri, isEdit }));
//
// actions.push({
// type: ACTIONS.FETCH_CLAIM_LIST_MINE_COMPLETED,
// data: {
// claims: myNewClaims,
// },
// });
//
// store.dispatch(batchActions(...actions));
// });
//
// reduxCallbacks.setCallback('streamPublishFail', error => {
// store.dispatch({ type: ACTIONS.PUBLISH_FAIL });
// store.dispatch(doError(error.message));
// });
// @if TARGET='app'
ipcRenderer.on('open-uri-requested', (event, uri, newSession) => {
if (uri && uri.startsWith('lbry://')) {

View file

@ -1,7 +1,6 @@
import { connect } from 'react-redux';
import { doHideModal } from 'redux/actions/app';
import { doUploadThumbnail } from 'redux/actions/publish';
import { doToast } from 'lbry-redux';
import { doToast, doUploadThumbnail } from 'lbry-redux';
import ModalAutoGenerateThumbnail from './view';
const perform = dispatch => ({

View file

@ -1,6 +1,6 @@
import { connect } from 'react-redux';
import { doHideModal } from 'redux/actions/app';
import { doUploadThumbnail, doUpdatePublishForm } from 'redux/actions/publish';
import { doUploadThumbnail, doUpdatePublishForm } from 'lbry-redux';
import ModalConfirmThumbnailUpload from './view';
const perform = dispatch => ({

View file

@ -1,7 +1,7 @@
import { connect } from 'react-redux';
import { doHideModal } from 'redux/actions/app';
import ModalPublishSuccess from './view';
import { doClearPublish } from 'redux/actions/publish';
import { doClearPublish } from 'lbry-redux';
import { push } from 'connected-react-router';
const perform = dispatch => ({

View file

@ -16,11 +16,11 @@ import {
makeSelectTitleForUri,
makeSelectThumbnailForUri,
makeSelectClaimIsNsfw,
doPrepareEdit,
} from 'lbry-redux';
import { doFetchViewCount, makeSelectViewCountForUri, makeSelectCostInfoForUri, doFetchCostInfoForUri } from 'lbryinc';
import { selectShowNsfw, makeSelectClientSetting } from 'redux/selectors/settings';
import { makeSelectIsSubscribed } from 'redux/selectors/subscriptions';
import { doPrepareEdit } from 'redux/actions/publish';
import { doOpenModal } from 'redux/actions/app';
import FilePage from './view';

View file

@ -1,6 +1,5 @@
import { connect } from 'react-redux';
import { selectIsFetchingClaimListMine, selectMyClaimUrisWithoutChannels } from 'lbry-redux';
import { doCheckPendingPublishes } from 'redux/actions/publish';
import { selectIsFetchingClaimListMine, selectMyClaimUrisWithoutChannels, doCheckPendingPublishes } from 'lbry-redux';
import FileListPublished from './view';
const select = state => ({

View file

@ -8,6 +8,7 @@ import {
notificationsReducer,
tagsReducer,
commentReducer,
publishReducer,
} from 'lbry-redux';
import {
userReducer,
@ -23,7 +24,7 @@ import availabilityReducer from 'redux/reducers/availability';
import contentReducer from 'redux/reducers/content';
import settingsReducer from 'redux/reducers/settings';
import subscriptionsReducer from 'redux/reducers/subscriptions';
import publishReducer from 'redux/reducers/publish';
export default history =>
combineReducers({

View file

@ -9,19 +9,23 @@ import {
batchActions,
creditsToString,
selectPendingById,
selectMyClaimsWithoutChannels,
doError,
isClaimNsfw,
selectMyClaimForUri,
selectPublishFormValues,
selectMyClaimsWithoutChannels,
} from 'lbry-redux';
import { doOpenModal } from 'redux/actions/app';
// import { doOpenModal } from 'redux/actions/app';
import { selectosNotificationsEnabled } from 'redux/selectors/settings';
import { selectMyClaimForUri, selectPublishFormValues } from 'redux/selectors/publish';
import { push } from 'connected-react-router';
import analytics from 'analytics';
// import analytics from 'analytics';
import { formatLbryUriForWeb } from 'util/uri';
// @if TARGET='app'
import fs from 'fs';
import path from 'path';
import { store } from '../../store';
import analytics from '../../analytics';
import { doOpenModal } from './app';
// @endif
export const doResetThumbnailStatus = () => (dispatch: Dispatch) => {
@ -207,6 +211,49 @@ export const doPrepareEdit = (claim: StreamClaim, uri: string, fileInfo: FileLis
dispatch({ type: ACTIONS.DO_PREPARE_EDIT, data: publishData });
};
const publishSuccess = successResponse => {
const state = store.getState();
analytics.apiLogPublish();
const myClaims = selectMyClaimsWithoutChannels(state);
const pendingClaim = successResponse.outputs[0];
const uri = pendingClaim.permanent_url;
const actions = [];
actions.push({
type: ACTIONS.PUBLISH_SUCCESS,
});
// 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);
const myNewClaims = isEdit
? myClaims.map(claim => (isMatch(claim) ? pendingClaim : claim))
: myClaims.concat(pendingClaim);
actions.push(doOpenModal(MODALS.PUBLISH, { uri, isEdit }));
actions.push({
type: ACTIONS.FETCH_CLAIM_LIST_MINE_COMPLETED,
data: {
claims: myNewClaims,
},
});
store.dispatch(batchActions(...actions));
};
const publishFail = error => {
store.dispatch({ type: ACTIONS.PUBLISH_FAIL });
store.dispatch(doError(error.message));
};
export const doPublishDesktop = (publishSuccess, publishFail) => {
doPublish(publishSuccess, publishFail);
};
export const doPublish = () => (dispatch: Dispatch, getState: () => {}) => {
dispatch({ type: ACTIONS.PUBLISH_START });
@ -252,17 +299,20 @@ export const doPublish = () => (dispatch: Dispatch, getState: () => {}) => {
const publishPayload: {
name: ?string,
channel_id?: string,
bid: number,
description?: string,
channel_id?: string,
file_path?: string,
tags: Array<string>,
locations?: Array<Location>,
license_url?: string,
license?: string,
thumbnail_url?: string,
release_time?: number,
fee_currency?: string,
fee_amount?: string,
tags: Array<string>,
locations?: Array<Location>,
languages?: Array<string>,
} = {
name,
title,

View file

@ -1,107 +1,107 @@
// @flow
import { handleActions } from 'util/redux-utils';
import { buildURI } from 'lbry-redux';
import * as ACTIONS from 'constants/action_types';
import * as THUMBNAIL_STATUSES from 'constants/thumbnail_upload_statuses';
import { CHANNEL_ANONYMOUS } from 'constants/claim';
type PublishState = {
editingURI: ?string,
filePath: ?string,
contentIsFree: boolean,
fee: {
amount: number,
currency: string,
},
title: string,
thumbnail_url: string,
thumbnailPath: string,
uploadThumbnailStatus: string,
description: string,
language: string,
channel: string,
channelId: ?string,
name: string,
nameError: ?string,
bid: number,
bidError: ?string,
otherLicenseDescription: string,
licenseUrl: string,
tags: Array<string>,
};
const defaultState: PublishState = {
editingURI: undefined,
filePath: undefined,
contentIsFree: true,
fee: {
amount: 1,
currency: 'LBC',
},
title: '',
thumbnail_url: '',
thumbnailPath: '',
uploadThumbnailStatus: THUMBNAIL_STATUSES.API_DOWN,
description: '',
language: 'en',
nsfw: false,
channel: CHANNEL_ANONYMOUS,
channelId: '',
name: '',
nameError: undefined,
bid: 0.1,
bidError: undefined,
licenseType: 'None',
otherLicenseDescription: 'All rights reserved',
licenseUrl: '',
tags: [],
publishing: false,
publishSuccess: false,
publishError: undefined,
};
export default handleActions(
{
[ACTIONS.UPDATE_PUBLISH_FORM]: (state, action): PublishState => {
const { data } = action;
return {
...state,
...data,
};
},
[ACTIONS.CLEAR_PUBLISH]: (): PublishState => ({
...defaultState,
}),
[ACTIONS.PUBLISH_START]: (state: PublishState): PublishState => ({
...state,
publishing: true,
}),
[ACTIONS.PUBLISH_FAIL]: (state: PublishState): PublishState => ({
...state,
publishing: false,
}),
[ACTIONS.PUBLISH_SUCCESS]: (state: PublishState): PublishState => ({
...state,
publishing: false,
}),
[ACTIONS.DO_PREPARE_EDIT]: (state: PublishState, action) => {
const { ...publishData } = action.data;
const { channel, name, uri } = publishData;
// The short uri is what is presented to the user
// The editingUri is the full uri with claim id
const shortUri = buildURI({
channelName: channel,
contentName: name,
});
return {
...defaultState,
...publishData,
editingURI: uri,
uri: shortUri,
};
},
},
defaultState
);
// // @flow
// import { handleActions } from 'util/redux-utils';
// import { buildURI } from 'lbry-redux';
// import * as ACTIONS from 'constants/action_types';
// import * as THUMBNAIL_STATUSES from 'constants/thumbnail_upload_statuses';
// import { CHANNEL_ANONYMOUS } from 'constants/claim';
//
// type PublishState = {
// editingURI: ?string,
// filePath: ?string,
// contentIsFree: boolean,
// fee: {
// amount: number,
// currency: string,
// },
// title: string,
// thumbnail_url: string,
// thumbnailPath: string,
// uploadThumbnailStatus: string,
// description: string,
// language: string,
// channel: string,
// channelId: ?string,
// name: string,
// nameError: ?string,
// bid: number,
// bidError: ?string,
// otherLicenseDescription: string,
// licenseUrl: string,
// tags: Array<string>,
// };
//
// const defaultState: PublishState = {
// editingURI: undefined,
// filePath: undefined,
// contentIsFree: true,
// fee: {
// amount: 1,
// currency: 'LBC',
// },
// title: '',
// thumbnail_url: '',
// thumbnailPath: '',
// uploadThumbnailStatus: THUMBNAIL_STATUSES.API_DOWN,
// description: '',
// language: 'en',
// nsfw: false,
// channel: CHANNEL_ANONYMOUS,
// channelId: '',
// name: '',
// nameError: undefined,
// bid: 0.1,
// bidError: undefined,
// licenseType: 'None',
// otherLicenseDescription: 'All rights reserved',
// licenseUrl: '',
// tags: [],
// publishing: false,
// publishSuccess: false,
// publishError: undefined,
// };
//
// export default handleActions(
// {
// [ACTIONS.UPDATE_PUBLISH_FORM]: (state, action): PublishState => {
// const { data } = action;
// return {
// ...state,
// ...data,
// };
// },
// [ACTIONS.CLEAR_PUBLISH]: (): PublishState => ({
// ...defaultState,
// }),
// [ACTIONS.PUBLISH_START]: (state: PublishState): PublishState => ({
// ...state,
// publishing: true,
// }),
// [ACTIONS.PUBLISH_FAIL]: (state: PublishState): PublishState => ({
// ...state,
// publishing: false,
// }),
// [ACTIONS.PUBLISH_SUCCESS]: (state: PublishState): PublishState => ({
// ...state,
// publishing: false,
// }),
// [ACTIONS.DO_PREPARE_EDIT]: (state: PublishState, action) => {
// const { ...publishData } = action.data;
// const { channel, name, uri } = publishData;
//
// // The short uri is what is presented to the user
// // The editingUri is the full uri with claim id
// const shortUri = buildURI({
// channelName: channel,
// contentName: name,
// });
//
// return {
// ...defaultState,
// ...publishData,
// editingURI: uri,
// uri: shortUri,
// };
// },
// },
// defaultState
// );