fix: editing with no source
This commit is contained in:
parent
feffa76a22
commit
a69a4e2852
10 changed files with 125 additions and 55 deletions
|
@ -48,7 +48,7 @@
|
|||
"formik": "^0.10.4",
|
||||
"hast-util-sanitize": "^1.1.2",
|
||||
"keytar": "^4.2.1",
|
||||
"lbry-redux": "lbryio/lbry-redux#7759bc6e8c482bed173d1f10aee6f6f9a439a15a",
|
||||
"lbry-redux": "lbryio/lbry-redux#121ba56f47fff05531e27a7c99d7d417e79cd3ee",
|
||||
"localforage": "^1.7.1",
|
||||
"mixpanel-browser": "^2.17.1",
|
||||
"moment": "^2.22.0",
|
||||
|
|
|
@ -1,32 +1,34 @@
|
|||
// @flow
|
||||
import * as React from 'react';
|
||||
import Button from 'component/button';
|
||||
import { buildURI } from 'lbry-redux';
|
||||
import type { Claim } from 'types/claim';
|
||||
|
||||
type Props = {
|
||||
uri: ?string,
|
||||
editingURI: ?string,
|
||||
isResolvingUri: boolean,
|
||||
winningBidForClaimUri: ?number,
|
||||
myClaimForUri: ?{},
|
||||
onEditMyClaim: any => void,
|
||||
myClaimForUri: ?Claim,
|
||||
isStillEditing: boolean,
|
||||
onEditMyClaim: (any, string) => void,
|
||||
};
|
||||
|
||||
class BidHelpText extends React.PureComponent<Props> {
|
||||
render() {
|
||||
const {
|
||||
uri,
|
||||
editingURI,
|
||||
isResolvingUri,
|
||||
winningBidForClaimUri,
|
||||
myClaimForUri,
|
||||
onEditMyClaim,
|
||||
isStillEditing,
|
||||
} = this.props;
|
||||
|
||||
if (!uri) {
|
||||
return __('Create a URL for this content');
|
||||
}
|
||||
|
||||
if (uri === editingURI) {
|
||||
if (isStillEditing) {
|
||||
return __('You are currently editing this claim');
|
||||
}
|
||||
|
||||
|
@ -35,11 +37,20 @@ class BidHelpText extends React.PureComponent<Props> {
|
|||
}
|
||||
|
||||
if (myClaimForUri) {
|
||||
const editUri = buildURI({
|
||||
contentName: myClaimForUri.name,
|
||||
claimId: myClaimForUri.claim_id,
|
||||
});
|
||||
|
||||
return (
|
||||
<React.Fragment>
|
||||
{__('You already have a claim at')}
|
||||
{` ${uri} `}
|
||||
<Button button="link" label="Edit it" onClick={() => onEditMyClaim(myClaimForUri, uri)} />
|
||||
<Button
|
||||
button="link"
|
||||
label="Edit it"
|
||||
onClick={() => onEditMyClaim(myClaimForUri, editUri)}
|
||||
/>
|
||||
<br />
|
||||
{__('Publishing will update your existing claim.')}
|
||||
</React.Fragment>
|
||||
|
|
|
@ -49,6 +49,7 @@ type Props = {
|
|||
bidError: ?string,
|
||||
publishing: boolean,
|
||||
balance: number,
|
||||
isStillEditing: boolean,
|
||||
clearPublish: () => void,
|
||||
resolveUri: string => void,
|
||||
scrollToTop: () => void,
|
||||
|
@ -194,6 +195,7 @@ class PublishForm extends React.PureComponent<Props> {
|
|||
uri,
|
||||
myClaimForUri,
|
||||
channel,
|
||||
isStillEditing
|
||||
} = this.props;
|
||||
|
||||
let publishingLicense;
|
||||
|
@ -227,6 +229,7 @@ class PublishForm extends React.PureComponent<Props> {
|
|||
price,
|
||||
uri,
|
||||
channel,
|
||||
isStillEditing
|
||||
};
|
||||
|
||||
// Editing a claim
|
||||
|
@ -299,19 +302,12 @@ class PublishForm extends React.PureComponent<Props> {
|
|||
clearPublish,
|
||||
thumbnailPath,
|
||||
resetThumbnailStatus,
|
||||
isStillEditing,
|
||||
} = this.props;
|
||||
|
||||
const formDisabled = (!filePath && !editingURI) || publishing;
|
||||
const formValid = this.checkIsFormValid();
|
||||
|
||||
// The user could be linked from lbry://@channel... or lbry://claim-name...
|
||||
// If a channel exists, we need to make sure it is added to the uri for proper edit handling
|
||||
// If this isn't an edit, just use the pregenerated uri
|
||||
const simpleUri = myClaimForUri
|
||||
? buildURI({ channelName: myClaimForUri.channel_name, contentName: myClaimForUri.name })
|
||||
: uri;
|
||||
|
||||
const isStillEditing = editingURI === simpleUri;
|
||||
let submitLabel;
|
||||
if (isStillEditing) {
|
||||
submitLabel = !publishing ? __('Edit') : __('Editing...');
|
||||
|
@ -463,7 +459,8 @@ class PublishForm extends React.PureComponent<Props> {
|
|||
error={nameError}
|
||||
helper={
|
||||
<BidHelpText
|
||||
uri={simpleUri}
|
||||
isStillEditing={isStillEditing}
|
||||
uri={uri}
|
||||
editingURI={editingURI}
|
||||
isResolvingUri={isResolvingUri}
|
||||
winningBidForClaimUri={winningBidForClaimUri}
|
||||
|
|
|
@ -133,7 +133,12 @@ class FilePage extends React.Component<Props> {
|
|||
// We will select the claim id before they publish
|
||||
let editUri;
|
||||
if (claimIsMine) {
|
||||
editUri = buildURI({ channelName, contentName: claim.name });
|
||||
const uriObject = { contentName: claim.name, claimId: claim.claim_id };
|
||||
if (channelName) {
|
||||
uriObject.channelName = channelName;
|
||||
}
|
||||
|
||||
editUri = buildURI(uriObject);
|
||||
}
|
||||
|
||||
return (
|
||||
|
|
|
@ -25,6 +25,7 @@ class HelpPage extends React.PureComponent {
|
|||
|
||||
componentDidMount() {
|
||||
Native.getAppVersionInfo().then(({ remoteVersion, localVersion, upgradeAvailable }) => {
|
||||
console.log('localVersion: ', localVersion);
|
||||
this.setState({
|
||||
uiVersion: localVersion,
|
||||
upgradeAvailable,
|
||||
|
|
|
@ -1,14 +1,11 @@
|
|||
import { connect } from 'react-redux';
|
||||
import {
|
||||
doResolveUri,
|
||||
makeSelectCostInfoForUri,
|
||||
selectMyClaims,
|
||||
selectClaimsByUri,
|
||||
selectResolvingUris,
|
||||
selectBalance,
|
||||
} from 'lbry-redux';
|
||||
import { doResolveUri, selectClaimsByUri, selectResolvingUris, selectBalance } from 'lbry-redux';
|
||||
import { doNavigate } from 'redux/actions/navigation';
|
||||
import { selectPublishFormValues } from 'redux/selectors/publish';
|
||||
import {
|
||||
selectPublishFormValues,
|
||||
selectIsStillEditing,
|
||||
selectMyClaimForUri,
|
||||
} from 'redux/selectors/publish';
|
||||
import {
|
||||
doResetThumbnailStatus,
|
||||
doClearPublish,
|
||||
|
@ -18,9 +15,11 @@ import {
|
|||
} from 'redux/actions/publish';
|
||||
import PublishPage from './view';
|
||||
|
||||
const select = (state, props) => {
|
||||
const select = state => {
|
||||
const isStillEditing = selectIsStillEditing(state);
|
||||
const myClaimForUri = selectMyClaimForUri(state);
|
||||
const publishState = selectPublishFormValues(state);
|
||||
const { uri, name } = publishState;
|
||||
const { uri } = publishState;
|
||||
|
||||
const resolvingUris = selectResolvingUris(state);
|
||||
let isResolvingUri = false;
|
||||
|
@ -28,24 +27,28 @@ const select = (state, props) => {
|
|||
isResolvingUri = resolvingUris.includes(uri);
|
||||
}
|
||||
|
||||
const claimsByUri = selectClaimsByUri(state);
|
||||
const myClaims = selectMyClaims(state);
|
||||
|
||||
const claimForUri = claimsByUri[uri];
|
||||
let claimForUri;
|
||||
let winningBidForClaimUri;
|
||||
let myClaimForUri;
|
||||
if (claimForUri) {
|
||||
winningBidForClaimUri = claimForUri.effective_amount;
|
||||
myClaimForUri = myClaims.find(claim => claim.name === name);
|
||||
if (!myClaimForUri) {
|
||||
// if the uri isn't from a users claim, find the winning bid needed for the vanity url
|
||||
// in the future we may want to display this on users claims
|
||||
// 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;
|
||||
}
|
||||
|
||||
return {
|
||||
...publishState,
|
||||
isResolvingUri,
|
||||
// The winning claim for a short lbry uri
|
||||
claimForUri,
|
||||
winningBidForClaimUri,
|
||||
// My previously published claims under this short lbry uri
|
||||
myClaimForUri,
|
||||
costInfo: makeSelectCostInfoForUri(props.uri)(state),
|
||||
// If I clicked the "edit" button, have I changed the uri?
|
||||
// Need this to make it easier to find the source on previously published content
|
||||
isStillEditing,
|
||||
balance: selectBalance(state),
|
||||
};
|
||||
};
|
||||
|
@ -60,4 +63,7 @@ const perform = dispatch => ({
|
|||
resetThumbnailStatus: () => dispatch(doResetThumbnailStatus()),
|
||||
});
|
||||
|
||||
export default connect(select, perform)(PublishPage);
|
||||
export default connect(
|
||||
select,
|
||||
perform
|
||||
)(PublishPage);
|
||||
|
|
|
@ -187,22 +187,23 @@ export const doPublish = (params: PublishParams) => (dispatch: Dispatch, getStat
|
|||
price,
|
||||
uri,
|
||||
sources,
|
||||
isStillEditing
|
||||
} = params;
|
||||
|
||||
// get the claim id from the channel name, we will use that instead
|
||||
const namedChannelClaim = myChannels.find(myChannel => myChannel.name === channel);
|
||||
const channelId = namedChannelClaim ? namedChannelClaim.claim_id : '';
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
// 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 fee = contentIsFree || !price.amount ? undefined : { ...price };
|
||||
|
||||
|
@ -241,7 +242,7 @@ export const doPublish = (params: PublishParams) => (dispatch: Dispatch, getStat
|
|||
const success = () => {
|
||||
dispatch({
|
||||
type: ACTIONS.PUBLISH_SUCCESS,
|
||||
data: { pendingPublish: { ...publishPayload, isEdit } },
|
||||
data: { pendingPublish: { ...publishPayload, isEdit: isStillEditing } },
|
||||
});
|
||||
dispatch(doNotify({ id: MODALS.PUBLISH }, { uri }));
|
||||
};
|
||||
|
|
|
@ -170,17 +170,20 @@ export default handleActions(
|
|||
},
|
||||
[ACTIONS.DO_PREPARE_EDIT]: (state: PublishState, action) => {
|
||||
const { ...publishData } = action.data;
|
||||
const { channel, name } = publishData;
|
||||
const { channel, name, uri } = publishData;
|
||||
|
||||
const uri = buildURI({
|
||||
// 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,
|
||||
editingURI: uri,
|
||||
...publishData,
|
||||
editingURI: uri,
|
||||
uri: shortUri,
|
||||
};
|
||||
},
|
||||
},
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { createSelector } from 'reselect';
|
||||
import { parseURI } from 'lbry-redux';
|
||||
import { parseURI, selectClaimsById, selectMyClaims } from 'lbry-redux';
|
||||
|
||||
const selectState = state => state.publish || {};
|
||||
|
||||
|
@ -25,3 +25,49 @@ export const selectPendingPublish = uri =>
|
|||
publish => (publish.name === claimName || publish.name === contentName) && !publish.isEdit
|
||||
)[0];
|
||||
});
|
||||
|
||||
// Is the current uri the same as the uri they clicked "edit" on
|
||||
export const selectIsStillEditing = createSelector(selectPublishFormValues, publishState => {
|
||||
const { editingURI, uri } = publishState;
|
||||
|
||||
const { isChannel: currentIsChannel, claimName: currentClaimName, contentName: currentContentName } = parseURI(uri);
|
||||
const { isChannel: editIsChannel, claimName: editClaimName, contentName: editContentName } = parseURI(editingURI);
|
||||
|
||||
// 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;
|
||||
} else {
|
||||
return currentContentName === editContentName;
|
||||
}
|
||||
});
|
||||
|
||||
export const selectMyClaimForUri = createSelector(
|
||||
selectPublishFormValues,
|
||||
selectIsStillEditing,
|
||||
selectClaimsById,
|
||||
selectMyClaims,
|
||||
({ editingURI, uri }, isStillEditing, claimsById, myClaims) => {
|
||||
const { contentName: currentContentName } = 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;
|
||||
}
|
||||
);
|
||||
|
|
|
@ -5564,9 +5564,9 @@ lazy-val@^1.0.3:
|
|||
version "1.0.3"
|
||||
resolved "https://registry.yarnpkg.com/lazy-val/-/lazy-val-1.0.3.tgz#bb97b200ef00801d94c317e29dc6ed39e31c5edc"
|
||||
|
||||
lbry-redux@lbryio/lbry-redux#7759bc6e8c482bed173d1f10aee6f6f9a439a15a:
|
||||
lbry-redux@lbryio/lbry-redux#121ba56f47fff05531e27a7c99d7d417e79cd3ee:
|
||||
version "0.0.1"
|
||||
resolved "https://codeload.github.com/lbryio/lbry-redux/tar.gz/7759bc6e8c482bed173d1f10aee6f6f9a439a15a"
|
||||
resolved "https://codeload.github.com/lbryio/lbry-redux/tar.gz/121ba56f47fff05531e27a7c99d7d417e79cd3ee"
|
||||
dependencies:
|
||||
proxy-polyfill "0.1.6"
|
||||
reselect "^3.0.0"
|
||||
|
|
Loading…
Add table
Reference in a new issue