clean up code and fix edit this claim button

This commit is contained in:
Sean Yesmunt 2018-06-12 23:28:06 -04:00
parent a8d693d890
commit 6e5edbdb34
5 changed files with 47 additions and 66 deletions
src/renderer
component/publishForm
page/publish
redux
actions
reducers
selectors

View file

@ -177,25 +177,13 @@ class PublishForm extends React.PureComponent<Props> {
handlePublish() { handlePublish() {
const { const {
publish,
filePath, filePath,
bid, copyrightNotice,
title,
thumbnail,
description,
language,
nsfw,
licenseType, licenseType,
licenseUrl, licenseUrl,
otherLicenseDescription, otherLicenseDescription,
copyrightNotice,
name,
contentIsFree,
price,
uri,
myClaimForUri, myClaimForUri,
channel, publish,
isStillEditing
} = this.props; } = this.props;
let publishingLicense; let publishingLicense;
@ -214,22 +202,22 @@ class PublishForm extends React.PureComponent<Props> {
const publishParams = { const publishParams = {
filePath, filePath,
bid, bid: this.props.bid,
title, title: this.props.title,
thumbnail, thumbnail: this.props.thumbnail,
description, description: this.props.description,
language, language: this.props.language,
nsfw, nsfw: this.props.nsfw,
license: publishingLicense, license: publishingLicense,
licenseUrl: publishingLicenseUrl, licenseUrl: publishingLicenseUrl,
otherLicenseDescription, otherLicenseDescription,
copyrightNotice, copyrightNotice,
name, name: this.props.name,
contentIsFree, contentIsFree: this.props.contentIsFree,
price, price: this.props.price,
uri, uri: this.props.uri,
channel, channel: this.props.channel,
isStillEditing isStillEditing: this.props.isStillEditing,
}; };
// Editing a claim // Editing a claim

View file

@ -35,7 +35,7 @@ const select = state => {
// ex: "you own this, for 5 more lbc you will win this claim" // ex: "you own this, for 5 more lbc you will win this claim"
const claimsByUri = selectClaimsByUri(state); const claimsByUri = selectClaimsByUri(state);
claimForUri = claimsByUri[uri]; claimForUri = claimsByUri[uri];
winningBidForClaimUri = claimForUri ? claimForUri.effective_amount : undefined; winningBidForClaimUri = claimForUri ? claimForUri.effective_amount : null;
} }
return { return {
@ -59,7 +59,7 @@ const perform = dispatch => ({
resolveUri: uri => dispatch(doResolveUri(uri)), resolveUri: uri => dispatch(doResolveUri(uri)),
publish: params => dispatch(doPublish(params)), publish: params => dispatch(doPublish(params)),
navigate: path => dispatch(doNavigate(path)), navigate: path => dispatch(doNavigate(path)),
prepareEdit: claim => dispatch(doPrepareEdit(claim)), prepareEdit: (claim, uri) => dispatch(doPrepareEdit(claim, uri)),
resetThumbnailStatus: () => dispatch(doResetThumbnailStatus()), resetThumbnailStatus: () => dispatch(doResetThumbnailStatus()),
}); });

View file

@ -2,7 +2,6 @@
import { import {
ACTIONS, ACTIONS,
Lbry, Lbry,
selectMyClaimsWithoutChannels,
doNotify, doNotify,
MODALS, MODALS,
selectMyChannelClaims, selectMyChannelClaims,
@ -168,7 +167,6 @@ export const doPrepareEdit = (claim: any, uri: string) => (dispatch: Dispatch) =
export const doPublish = (params: PublishParams) => (dispatch: Dispatch, getState: () => {}) => { export const doPublish = (params: PublishParams) => (dispatch: Dispatch, getState: () => {}) => {
const state = getState(); const state = getState();
const myClaims = selectMyClaimsWithoutChannels(state);
const myChannels = selectMyChannelClaims(state); const myChannels = selectMyChannelClaims(state);
const { const {
@ -233,7 +231,6 @@ export const doPublish = (params: PublishParams) => (dispatch: Dispatch, getStat
data: { pendingPublish: { ...publishPayload, isEdit: isStillEditing } }, data: { pendingPublish: { ...publishPayload, isEdit: isStillEditing } },
}); });
dispatch(doNotify({ id: MODALS.PUBLISH }, { uri })); dispatch(doNotify({ id: MODALS.PUBLISH }, { uri }));
dispatch(doCheckPendingPublishes());
}; };
const failure = error => { const failure = error => {
@ -258,25 +255,29 @@ export const doCheckPendingPublishes = () => (dispatch: Dispatch, getState: GetS
pendingPublishMap[name] = name; pendingPublishMap[name] = name;
}); });
const actions = [];
claims.forEach(claim => { claims.forEach(claim => {
if (pendingPublishMap[claim.name]) { if (pendingPublishMap[claim.name]) {
dispatch({ actions.push({
type: ACTIONS.REMOVE_PENDING_PUBLISH, type: ACTIONS.REMOVE_PENDING_PUBLISH,
data: { data: {
name: claim.name, name: claim.name,
}, },
}); });
dispatch({
type: ACTIONS.FETCH_CLAIM_LIST_MINE_COMPLETED,
data: {
claims,
},
});
delete pendingPublishMap[claim.name]; delete pendingPublishMap[claim.name];
} }
}); });
actions.push({
type: ACTIONS.FETCH_CLAIM_LIST_MINE_COMPLETED,
data: {
claims,
},
});
dispatch(batchActions(...actions));
if (!pendingPublishes.length) { if (!pendingPublishes.length) {
clearInterval(publishCheckInterval); clearInterval(publishCheckInterval);
} }

View file

@ -169,6 +169,7 @@ export default handleActions(
}; };
}, },
[ACTIONS.DO_PREPARE_EDIT]: (state: PublishState, action) => { [ACTIONS.DO_PREPARE_EDIT]: (state: PublishState, action) => {
const { pendingPublishes } = state;
const { ...publishData } = action.data; const { ...publishData } = action.data;
const { channel, name, uri } = publishData; const { channel, name, uri } = publishData;
@ -182,6 +183,7 @@ export default handleActions(
return { return {
...defaultState, ...defaultState,
...publishData, ...publishData,
pendingPublishes,
editingURI: uri, editingURI: uri,
uri: shortUri, uri: shortUri,
}; };

View file

@ -1,10 +1,5 @@
import { createSelector } from 'reselect'; import { createSelector } from 'reselect';
import { import { parseURI, selectClaimsById, selectMyClaimsWithoutChannels } from 'lbry-redux';
parseURI,
selectClaimsById,
selectMyClaims,
selectMyClaimsWithoutChannels,
} from 'lbry-redux';
const selectState = state => state.publish || {}; 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 // 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 // ex: going from a channel to anonymous, the new uri won't return contentName, so we need to use claimName
if (!currentIsChannel && editIsChannel) { const currentName = currentIsChannel ? currentContentName : currentClaimName;
return currentClaimName === editContentName; const editName = editIsChannel ? editContentName : editClaimName;
} else if (currentIsChannel && !editIsChannel) { return currentName === editName;
return currentContentName === editClaimName;
} else if (!currentIsChannel && !editIsChannel) {
return currentClaimName === editClaimName;
}
return currentContentName === editContentName;
}); });
export const selectMyClaimForUri = createSelector( export const selectMyClaimForUri = createSelector(
selectPublishFormValues, selectPublishFormValues,
selectIsStillEditing, selectIsStillEditing,
selectClaimsById, selectClaimsById,
selectMyClaims, selectMyClaimsWithoutChannels,
({ editingURI, uri }, isStillEditing, claimsById, myClaims) => { ({ editingURI, uri }, isStillEditing, claimsById, myClaims) => {
const { contentName: currentContentName } = parseURI(uri); const { contentName, claimName } = parseURI(uri);
const { claimId: editClaimId } = parseURI(editingURI); const { claimId: editClaimId } = parseURI(editingURI);
let myClaimForUri;
if (isStillEditing) { // If isStillEditing
// They clicked "edit" from the file page // They clicked "edit" from the file page
// They haven't changed the channel/name after clicking edit // They haven't changed the channel/name after clicking edit
// Get the claim so they can edit without re-uploading a new file // Get the claim so they can edit without re-uploading a new file
myClaimForUri = claimsById[editClaimId]; return isStillEditing
} else { ? claimsById[editClaimId]
// Check if they have a previous claim based on the channel/name : myClaims.find(
myClaimForUri = myClaims.find(claim => claim.name === currentContentName); claim =>
} !contentName
? claim.name === claimName
return myClaimForUri; : claim.name === contentName || claim.name === claimName
);
} }
); );