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