diff --git a/src/renderer/page/file/index.js b/src/renderer/page/file/index.js index 08e25e314..5e618c4c9 100644 --- a/src/renderer/page/file/index.js +++ b/src/renderer/page/file/index.js @@ -15,10 +15,9 @@ import { makeSelectCostInfoForUri } from 'redux/selectors/cost_info'; import { selectShowNsfw } from 'redux/selectors/settings'; import { selectMediaPaused } from 'redux/selectors/media'; import { doOpenModal } from 'redux/actions/app'; -import FilePage from './view'; -import { makeSelectCurrentParam } from 'redux/selectors/navigation'; import { selectSubscriptions } from 'redux/selectors/subscriptions'; import { doPrepareEdit } from 'redux/actions/publish'; +import FilePage from './view'; const select = (state, props) => ({ claim: makeSelectClaimForUri(props.uri)(state), @@ -40,7 +39,7 @@ const perform = dispatch => ({ fetchCostInfo: uri => dispatch(doFetchCostInfoForUri(uri)), checkSubscription: subscription => dispatch(doCheckSubscription(subscription)), openModal: (modal, props) => dispatch(doOpenModal(modal, props)), - prepareEdit: publishData => dispatch(doPrepareEdit(publishData)), + prepareEdit: (publishData, uri) => dispatch(doPrepareEdit(publishData, uri)), }); export default connect(select, perform)(FilePage); diff --git a/src/renderer/page/file/view.jsx b/src/renderer/page/file/view.jsx index b017ea745..98ee33ffa 100644 --- a/src/renderer/page/file/view.jsx +++ b/src/renderer/page/file/view.jsx @@ -9,7 +9,6 @@ import FileDetails from 'component/fileDetails'; import FileActions from 'component/fileActions'; import UriIndicator from 'component/uriIndicator'; import Icon from 'component/common/icon'; -import WalletSendTip from 'component/walletSendTip'; import DateTime from 'component/dateTime'; import * as icons from 'constants/icons'; import Button from 'component/button'; @@ -72,7 +71,7 @@ class FilePage extends React.Component { } } - checkSubscription(props) { + checkSubscription = (props: Props) => { if ( props.subscriptions .map(subscription => subscription.channelName) @@ -89,12 +88,11 @@ class FilePage extends React.Component { ), }); } - } + }; render() { const { claim, - fileInfo, metadata, contentType, uri, @@ -109,10 +107,9 @@ class FilePage extends React.Component { } = this.props; // File info - const title = metadata.title; + const { title, thumbnail } = metadata; const isRewardContent = rewardedContentClaimIds.includes(claim.claim_id); const shouldObscureThumbnail = obscureNsfw && metadata.nsfw; - const thumbnail = metadata.thumbnail; const { height, channel_name: channelName, value } = claim; const mediaType = lbry.getMediaType(contentType); const isPlayable = @@ -165,7 +162,7 @@ class FilePage extends React.Component { icon={icons.EDIT} label={__('Edit')} onClick={() => { - prepareEdit(claim); + prepareEdit(claim, uri); navigate('/publish'); }} /> diff --git a/src/renderer/redux/actions/publish.js b/src/renderer/redux/actions/publish.js index 3bda0253c..f592df6fb 100644 --- a/src/renderer/redux/actions/publish.js +++ b/src/renderer/redux/actions/publish.js @@ -15,7 +15,6 @@ import { CHANNEL_NEW, CHANNEL_ANONYMOUS } from 'constants/claim'; type Action = UpdatePublishFormAction | { type: ACTIONS.CLEAR_PUBLISH }; type PromiseAction = Promise; type Dispatch = (action: Action | PromiseAction | Array) => any; -type ThunkAction = (dispatch: Dispatch) => any; type GetState = () => {}; export const doClearPublish = () => (dispatch: Dispatch): Action => @@ -29,7 +28,7 @@ export const doUpdatePublishForm = (publishFormValue: UpdatePublishFormData) => data: { ...publishFormValue }, }); -export const doPrepareEdit = (claim: any) => (dispatch: Dispatch) => { +export const doPrepareEdit = (claim: any, uri: string) => (dispatch: Dispatch) => { const { name, amount, channel_name: channelName, value: { stream: { metadata } } } = claim; const { author, @@ -63,12 +62,16 @@ export const doPrepareEdit = (claim: any) => (dispatch: Dispatch) => { nsfw, thumbnail, title, + uri, }; dispatch({ type: ACTIONS.DO_PREPARE_EDIT, data: publishData }); }; -export const doPublish = (params: PublishParams): ThunkAction => { +export const doPublish = (params: PublishParams) => (dispatch: Dispatch, getState: () => {}) => { + const state = getState(); + const myClaims = selectMyClaimsWithoutChannels(state); + const { name, bid, @@ -87,6 +90,17 @@ export const doPublish = (params: PublishParams): ThunkAction => { sources, } = params; + let isEdit; + const newPublishName = channel ? `${channel}/${name}` : name; + for (let i = 0; i < myClaims.length; i += 1) { + const { channel_name: claimChannelName, name: claimName } = myClaims[i]; + const contentName = claimChannelName ? `${claimChannelName}/${claimName}` : claimName; + if (contentName === newPublishName) { + isEdit = true; + break; + } + } + const channelName = channel === CHANNEL_ANONYMOUS || channel === CHANNEL_NEW ? '' : channel; const fee = contentIsFree || !price.amount ? undefined : { ...price }; @@ -120,24 +134,22 @@ export const doPublish = (params: PublishParams): ThunkAction => { publishPayload.sources = sources; } - return (dispatch: Dispatch) => { - dispatch({ type: ACTIONS.PUBLISH_START }); + dispatch({ type: ACTIONS.PUBLISH_START }); - const success = () => { - dispatch({ - type: ACTIONS.PUBLISH_SUCCESS, - data: { pendingPublish: publishPayload }, - }); - dispatch(doOpenModal(MODALS.PUBLISH, { uri })); - }; - - const failure = error => { - dispatch({ type: ACTIONS.PUBLISH_FAIL }); - dispatch(doOpenModal(MODALS.ERROR, { error: error.message })); - }; - - return Lbry.publish(publishPayload).then(success, failure); + const success = () => { + dispatch({ + type: ACTIONS.PUBLISH_SUCCESS, + data: { pendingPublish: { ...publishPayload, isEdit } }, + }); + dispatch(doOpenModal(MODALS.PUBLISH, { uri })); }; + + const failure = error => { + dispatch({ type: ACTIONS.PUBLISH_FAIL }); + dispatch(doOpenModal(MODALS.ERROR, { error: error.message })); + }; + + return Lbry.publish(publishPayload).then(success, failure); }; // Calls claim_list_mine until any pending publishes are confirmed diff --git a/src/renderer/redux/selectors/publish.js b/src/renderer/redux/selectors/publish.js index 21f27d7d1..f292ea51e 100644 --- a/src/renderer/redux/selectors/publish.js +++ b/src/renderer/redux/selectors/publish.js @@ -10,7 +10,7 @@ export const selectPendingPublishes = createSelector( export const selectPendingPublishesLessEdits = createSelector( selectPendingPublishes, - pendingPublishes => pendingPublishes.filter(pendingPublish => !pendingPublish.sources) + pendingPublishes => pendingPublishes.filter(pendingPublish => !pendingPublish.isEdit) ); export const selectPublishFormValues = createSelector(selectState, state => {