fix: don't show two pending publish cards for edit publishes

This commit is contained in:
Sean Yesmunt 2018-04-06 02:00:36 -04:00
parent b5aefcabad
commit 05e6fbed12
4 changed files with 38 additions and 30 deletions

View file

@ -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);

View file

@ -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<Props> {
}
}
checkSubscription(props) {
checkSubscription = (props: Props) => {
if (
props.subscriptions
.map(subscription => subscription.channelName)
@ -89,12 +88,11 @@ class FilePage extends React.Component<Props> {
),
});
}
}
};
render() {
const {
claim,
fileInfo,
metadata,
contentType,
uri,
@ -109,10 +107,9 @@ class FilePage extends React.Component<Props> {
} = 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<Props> {
icon={icons.EDIT}
label={__('Edit')}
onClick={() => {
prepareEdit(claim);
prepareEdit(claim, uri);
navigate('/publish');
}}
/>

View file

@ -15,7 +15,6 @@ import { CHANNEL_NEW, CHANNEL_ANONYMOUS } from 'constants/claim';
type Action = UpdatePublishFormAction | { type: ACTIONS.CLEAR_PUBLISH };
type PromiseAction = Promise<Action>;
type Dispatch = (action: Action | PromiseAction | Array<Action>) => 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

View file

@ -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 => {