clean up code and fix edit this claim button
This commit is contained in:
parent
a8d693d890
commit
6e5edbdb34
5 changed files with 47 additions and 66 deletions
|
@ -177,25 +177,13 @@ class PublishForm extends React.PureComponent<Props> {
|
|||
|
||||
handlePublish() {
|
||||
const {
|
||||
publish,
|
||||
filePath,
|
||||
bid,
|
||||
title,
|
||||
thumbnail,
|
||||
description,
|
||||
language,
|
||||
nsfw,
|
||||
copyrightNotice,
|
||||
licenseType,
|
||||
licenseUrl,
|
||||
otherLicenseDescription,
|
||||
copyrightNotice,
|
||||
name,
|
||||
contentIsFree,
|
||||
price,
|
||||
uri,
|
||||
myClaimForUri,
|
||||
channel,
|
||||
isStillEditing
|
||||
publish,
|
||||
} = this.props;
|
||||
|
||||
let publishingLicense;
|
||||
|
@ -214,22 +202,22 @@ class PublishForm extends React.PureComponent<Props> {
|
|||
|
||||
const publishParams = {
|
||||
filePath,
|
||||
bid,
|
||||
title,
|
||||
thumbnail,
|
||||
description,
|
||||
language,
|
||||
nsfw,
|
||||
bid: this.props.bid,
|
||||
title: this.props.title,
|
||||
thumbnail: this.props.thumbnail,
|
||||
description: this.props.description,
|
||||
language: this.props.language,
|
||||
nsfw: this.props.nsfw,
|
||||
license: publishingLicense,
|
||||
licenseUrl: publishingLicenseUrl,
|
||||
otherLicenseDescription,
|
||||
copyrightNotice,
|
||||
name,
|
||||
contentIsFree,
|
||||
price,
|
||||
uri,
|
||||
channel,
|
||||
isStillEditing
|
||||
name: this.props.name,
|
||||
contentIsFree: this.props.contentIsFree,
|
||||
price: this.props.price,
|
||||
uri: this.props.uri,
|
||||
channel: this.props.channel,
|
||||
isStillEditing: this.props.isStillEditing,
|
||||
};
|
||||
|
||||
// Editing a claim
|
||||
|
|
|
@ -35,7 +35,7 @@ const select = state => {
|
|||
// ex: "you own this, for 5 more lbc you will win this claim"
|
||||
const claimsByUri = selectClaimsByUri(state);
|
||||
claimForUri = claimsByUri[uri];
|
||||
winningBidForClaimUri = claimForUri ? claimForUri.effective_amount : undefined;
|
||||
winningBidForClaimUri = claimForUri ? claimForUri.effective_amount : null;
|
||||
}
|
||||
|
||||
return {
|
||||
|
@ -59,7 +59,7 @@ const perform = dispatch => ({
|
|||
resolveUri: uri => dispatch(doResolveUri(uri)),
|
||||
publish: params => dispatch(doPublish(params)),
|
||||
navigate: path => dispatch(doNavigate(path)),
|
||||
prepareEdit: claim => dispatch(doPrepareEdit(claim)),
|
||||
prepareEdit: (claim, uri) => dispatch(doPrepareEdit(claim, uri)),
|
||||
resetThumbnailStatus: () => dispatch(doResetThumbnailStatus()),
|
||||
});
|
||||
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
import {
|
||||
ACTIONS,
|
||||
Lbry,
|
||||
selectMyClaimsWithoutChannels,
|
||||
doNotify,
|
||||
MODALS,
|
||||
selectMyChannelClaims,
|
||||
|
@ -168,7 +167,6 @@ export const doPrepareEdit = (claim: any, uri: string) => (dispatch: Dispatch) =
|
|||
|
||||
export const doPublish = (params: PublishParams) => (dispatch: Dispatch, getState: () => {}) => {
|
||||
const state = getState();
|
||||
const myClaims = selectMyClaimsWithoutChannels(state);
|
||||
const myChannels = selectMyChannelClaims(state);
|
||||
|
||||
const {
|
||||
|
@ -233,7 +231,6 @@ export const doPublish = (params: PublishParams) => (dispatch: Dispatch, getStat
|
|||
data: { pendingPublish: { ...publishPayload, isEdit: isStillEditing } },
|
||||
});
|
||||
dispatch(doNotify({ id: MODALS.PUBLISH }, { uri }));
|
||||
dispatch(doCheckPendingPublishes());
|
||||
};
|
||||
|
||||
const failure = error => {
|
||||
|
@ -258,25 +255,29 @@ export const doCheckPendingPublishes = () => (dispatch: Dispatch, getState: GetS
|
|||
pendingPublishMap[name] = name;
|
||||
});
|
||||
|
||||
const actions = [];
|
||||
claims.forEach(claim => {
|
||||
if (pendingPublishMap[claim.name]) {
|
||||
dispatch({
|
||||
actions.push({
|
||||
type: ACTIONS.REMOVE_PENDING_PUBLISH,
|
||||
data: {
|
||||
name: claim.name,
|
||||
},
|
||||
});
|
||||
dispatch({
|
||||
type: ACTIONS.FETCH_CLAIM_LIST_MINE_COMPLETED,
|
||||
data: {
|
||||
claims,
|
||||
},
|
||||
});
|
||||
|
||||
delete pendingPublishMap[claim.name];
|
||||
}
|
||||
});
|
||||
|
||||
actions.push({
|
||||
type: ACTIONS.FETCH_CLAIM_LIST_MINE_COMPLETED,
|
||||
data: {
|
||||
claims,
|
||||
},
|
||||
});
|
||||
|
||||
dispatch(batchActions(...actions));
|
||||
|
||||
if (!pendingPublishes.length) {
|
||||
clearInterval(publishCheckInterval);
|
||||
}
|
||||
|
|
|
@ -169,6 +169,7 @@ export default handleActions(
|
|||
};
|
||||
},
|
||||
[ACTIONS.DO_PREPARE_EDIT]: (state: PublishState, action) => {
|
||||
const { pendingPublishes } = state;
|
||||
const { ...publishData } = action.data;
|
||||
const { channel, name, uri } = publishData;
|
||||
|
||||
|
@ -182,6 +183,7 @@ export default handleActions(
|
|||
return {
|
||||
...defaultState,
|
||||
...publishData,
|
||||
pendingPublishes,
|
||||
editingURI: uri,
|
||||
uri: shortUri,
|
||||
};
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
import { createSelector } from 'reselect';
|
||||
import {
|
||||
parseURI,
|
||||
selectClaimsById,
|
||||
selectMyClaims,
|
||||
selectMyClaimsWithoutChannels,
|
||||
} from 'lbry-redux';
|
||||
import { parseURI, selectClaimsById, selectMyClaimsWithoutChannels } from 'lbry-redux';
|
||||
|
||||
const selectState = state => state.publish || {};
|
||||
|
||||
|
@ -66,36 +61,31 @@ export const selectIsStillEditing = createSelector(selectPublishFormValues, publ
|
|||
|
||||
// Depending on the previous/current use of a channel, we need to compare different things
|
||||
// ex: going from a channel to anonymous, the new uri won't return contentName, so we need to use claimName
|
||||
if (!currentIsChannel && editIsChannel) {
|
||||
return currentClaimName === editContentName;
|
||||
} else if (currentIsChannel && !editIsChannel) {
|
||||
return currentContentName === editClaimName;
|
||||
} else if (!currentIsChannel && !editIsChannel) {
|
||||
return currentClaimName === editClaimName;
|
||||
}
|
||||
return currentContentName === editContentName;
|
||||
const currentName = currentIsChannel ? currentContentName : currentClaimName;
|
||||
const editName = editIsChannel ? editContentName : editClaimName;
|
||||
return currentName === editName;
|
||||
});
|
||||
|
||||
export const selectMyClaimForUri = createSelector(
|
||||
selectPublishFormValues,
|
||||
selectIsStillEditing,
|
||||
selectClaimsById,
|
||||
selectMyClaims,
|
||||
selectMyClaimsWithoutChannels,
|
||||
({ editingURI, uri }, isStillEditing, claimsById, myClaims) => {
|
||||
const { contentName: currentContentName } = parseURI(uri);
|
||||
const { contentName, claimName } = parseURI(uri);
|
||||
const { claimId: editClaimId } = parseURI(editingURI);
|
||||
let myClaimForUri;
|
||||
|
||||
if (isStillEditing) {
|
||||
// They clicked "edit" from the file page
|
||||
// They haven't changed the channel/name after clicking edit
|
||||
// Get the claim so they can edit without re-uploading a new file
|
||||
myClaimForUri = claimsById[editClaimId];
|
||||
} else {
|
||||
// Check if they have a previous claim based on the channel/name
|
||||
myClaimForUri = myClaims.find(claim => claim.name === currentContentName);
|
||||
}
|
||||
|
||||
return myClaimForUri;
|
||||
// If isStillEditing
|
||||
// They clicked "edit" from the file page
|
||||
// They haven't changed the channel/name after clicking edit
|
||||
// Get the claim so they can edit without re-uploading a new file
|
||||
return isStillEditing
|
||||
? claimsById[editClaimId]
|
||||
: myClaims.find(
|
||||
claim =>
|
||||
!contentName
|
||||
? claim.name === claimName
|
||||
: claim.name === contentName || claim.name === claimName
|
||||
);
|
||||
}
|
||||
);
|
||||
|
|
Loading…
Add table
Reference in a new issue