2019-06-28 09:27:55 +02:00
|
|
|
// @flow
|
|
|
|
import * as React from 'react';
|
|
|
|
import Button from 'component/button';
|
2021-10-17 10:36:14 +02:00
|
|
|
import { buildURI } from 'util/lbryURI';
|
2020-06-21 16:51:02 +02:00
|
|
|
import I18nMessage from 'component/i18nMessage';
|
2019-06-28 09:27:55 +02:00
|
|
|
|
2021-12-10 13:27:04 +01:00
|
|
|
function isUriPendingUpload(uri: ?string, currentUploadNames: Array<string>) {
|
|
|
|
const protocol = 'lbry://';
|
|
|
|
const uriName = uri && uri.startsWith(protocol) ? uri.substring(protocol.length) : uri;
|
|
|
|
return currentUploadNames.includes(uriName);
|
|
|
|
}
|
|
|
|
|
2019-06-28 09:27:55 +02:00
|
|
|
type Props = {
|
|
|
|
uri: ?string,
|
|
|
|
myClaimForUri: ?StreamClaim,
|
2022-04-18 04:52:40 +02:00
|
|
|
myClaimForUriCaseInsensitive: ?StreamClaim,
|
2021-12-10 13:27:04 +01:00
|
|
|
currentUploads: { [key: string]: FileUploadItem },
|
2019-06-28 09:27:55 +02:00
|
|
|
isStillEditing: boolean,
|
|
|
|
onEditMyClaim: (any, string) => void,
|
|
|
|
};
|
|
|
|
|
|
|
|
function NameHelpText(props: Props) {
|
2022-04-18 04:52:40 +02:00
|
|
|
const { uri, myClaimForUri, myClaimForUriCaseInsensitive, currentUploads, onEditMyClaim, isStillEditing } = props;
|
2021-12-10 13:27:04 +01:00
|
|
|
|
|
|
|
const currentUploadNames: Array<string> = React.useMemo(() => {
|
|
|
|
// $FlowFixMe - unable to resolve mixed
|
|
|
|
return Object.values(currentUploads).map((x) => (x.params ? x.params.name : ''));
|
|
|
|
}, [currentUploads]);
|
|
|
|
|
2019-06-28 09:27:55 +02:00
|
|
|
let nameHelpText;
|
|
|
|
|
|
|
|
if (isStillEditing) {
|
2020-07-30 21:31:55 +02:00
|
|
|
nameHelpText = __('You are currently editing this claim.');
|
2021-12-10 13:27:04 +01:00
|
|
|
} else if (isUriPendingUpload(uri, currentUploadNames)) {
|
|
|
|
nameHelpText = (
|
|
|
|
<div className="error__text">
|
|
|
|
{/* prettier-ignore */}
|
|
|
|
<I18nMessage tokens={{ existing_uri: (<u><em>{uri}</em></u>) }}>
|
|
|
|
You already have a pending upload at %existing_uri%.
|
|
|
|
</I18nMessage>
|
|
|
|
</div>
|
|
|
|
);
|
2019-06-28 09:27:55 +02:00
|
|
|
} else if (uri && myClaimForUri) {
|
|
|
|
const editUri = buildURI({
|
2019-08-30 01:18:06 +02:00
|
|
|
streamName: myClaimForUri.name,
|
|
|
|
streamClaimId: myClaimForUri.claim_id,
|
2019-06-28 09:27:55 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
nameHelpText = (
|
|
|
|
<React.Fragment>
|
2020-06-21 16:51:02 +02:00
|
|
|
<div className="error__text">
|
|
|
|
<I18nMessage
|
|
|
|
tokens={{
|
|
|
|
existing_uri: (
|
|
|
|
<u>
|
|
|
|
<em>{uri}</em>
|
|
|
|
</u>
|
|
|
|
),
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
You already have a claim at %existing_uri%. Publishing will update (overwrite) your existing claim.
|
|
|
|
</I18nMessage>
|
|
|
|
</div>
|
|
|
|
<Button
|
|
|
|
button="link"
|
|
|
|
label={__('Edit existing claim instead')}
|
|
|
|
onClick={() => onEditMyClaim(myClaimForUri, editUri)}
|
|
|
|
/>
|
2019-06-28 09:27:55 +02:00
|
|
|
</React.Fragment>
|
|
|
|
);
|
2022-04-18 04:52:40 +02:00
|
|
|
} else if (uri && myClaimForUriCaseInsensitive) {
|
|
|
|
nameHelpText = <div className="error__text">{__('You already have an upload with that name.')}</div>;
|
2019-06-28 09:27:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<React.Fragment>
|
|
|
|
{nameHelpText || (
|
|
|
|
<span>{__('Create a URL for this content. Simpler names are easier to find and remember.')}</span>
|
|
|
|
)}
|
|
|
|
</React.Fragment>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
export default NameHelpText;
|