2019-06-28 09:27:55 +02:00
|
|
|
// @flow
|
2021-02-09 17:05:56 +01:00
|
|
|
import { DOMAIN } from 'config';
|
|
|
|
import { INVALID_NAME_ERROR } from 'constants/claim';
|
2020-07-30 06:03:56 +02:00
|
|
|
import React, { useState, useEffect } from 'react';
|
2021-10-08 05:47:39 +02:00
|
|
|
import { isNameValid } from 'util/lbryURI';
|
2019-06-28 09:27:55 +02:00
|
|
|
import { FormField } from 'component/common/form';
|
|
|
|
import NameHelpText from './name-help-text';
|
|
|
|
|
|
|
|
type Props = {
|
|
|
|
name: string,
|
|
|
|
uri: string,
|
|
|
|
isStillEditing: boolean,
|
|
|
|
myClaimForUri: ?StreamClaim,
|
|
|
|
amountNeededForTakeover: number,
|
|
|
|
prepareEdit: ({}, string) => void,
|
|
|
|
updatePublishForm: ({}) => void,
|
2021-02-09 17:05:56 +01:00
|
|
|
activeChannelClaim: ?ChannelClaim,
|
|
|
|
incognito: boolean,
|
2019-06-28 09:27:55 +02:00
|
|
|
};
|
|
|
|
|
2019-07-02 06:49:21 +02:00
|
|
|
function PublishName(props: Props) {
|
2019-06-28 09:27:55 +02:00
|
|
|
const {
|
|
|
|
name,
|
|
|
|
uri,
|
|
|
|
isStillEditing,
|
|
|
|
myClaimForUri,
|
|
|
|
prepareEdit,
|
|
|
|
updatePublishForm,
|
2021-02-09 17:05:56 +01:00
|
|
|
activeChannelClaim,
|
|
|
|
incognito,
|
2019-06-28 09:27:55 +02:00
|
|
|
} = props;
|
|
|
|
const [nameError, setNameError] = useState(undefined);
|
2021-02-09 17:05:56 +01:00
|
|
|
const [blurred, setBlurred] = React.useState(false);
|
|
|
|
const activeChannelName = activeChannelClaim && activeChannelClaim.name;
|
|
|
|
let prefix = IS_WEB ? `${DOMAIN}/` : 'lbry://';
|
|
|
|
if (activeChannelName && !incognito) {
|
|
|
|
prefix += `${activeChannelName}/`;
|
|
|
|
}
|
2019-06-28 09:27:55 +02:00
|
|
|
|
|
|
|
function editExistingClaim() {
|
|
|
|
if (myClaimForUri) {
|
|
|
|
prepareEdit(myClaimForUri, uri);
|
|
|
|
}
|
|
|
|
}
|
2020-07-30 00:55:48 +02:00
|
|
|
|
2020-07-30 06:03:56 +02:00
|
|
|
function handleNameChange(event) {
|
|
|
|
updatePublishForm({ name: event.target.value });
|
|
|
|
}
|
|
|
|
|
|
|
|
useEffect(() => {
|
2021-02-09 17:05:56 +01:00
|
|
|
if (!blurred && !name) {
|
|
|
|
return;
|
2020-07-30 06:03:56 +02:00
|
|
|
}
|
2019-06-28 09:27:55 +02:00
|
|
|
|
|
|
|
let nameError;
|
|
|
|
if (!name) {
|
|
|
|
nameError = __('A name is required');
|
2021-10-08 05:47:39 +02:00
|
|
|
} else if (!isNameValid(name)) {
|
2019-10-03 23:40:54 +02:00
|
|
|
nameError = INVALID_NAME_ERROR;
|
2019-06-28 09:27:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
setNameError(nameError);
|
2021-02-09 17:05:56 +01:00
|
|
|
}, [name, blurred]);
|
2019-06-28 09:27:55 +02:00
|
|
|
|
|
|
|
return (
|
2021-02-09 17:05:56 +01:00
|
|
|
<>
|
|
|
|
<fieldset-group class="fieldset-group--smushed fieldset-group--disabled-prefix">
|
|
|
|
<fieldset-section>
|
|
|
|
<label>{__('Name')}</label>
|
|
|
|
<div className="form-field__prefix">{prefix}</div>
|
|
|
|
</fieldset-section>
|
|
|
|
<FormField
|
|
|
|
type="text"
|
|
|
|
name="content_name"
|
|
|
|
value={name}
|
|
|
|
error={nameError}
|
2021-02-23 04:03:15 +01:00
|
|
|
disabled={isStillEditing}
|
2021-02-09 17:05:56 +01:00
|
|
|
onChange={handleNameChange}
|
|
|
|
onBlur={() => setBlurred(true)}
|
|
|
|
/>
|
|
|
|
</fieldset-group>
|
|
|
|
<div className="form-field__help">
|
|
|
|
<NameHelpText
|
|
|
|
uri={uri}
|
|
|
|
isStillEditing={isStillEditing}
|
|
|
|
myClaimForUri={myClaimForUri}
|
|
|
|
onEditMyClaim={editExistingClaim}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</>
|
2019-06-28 09:27:55 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-07-02 06:49:21 +02:00
|
|
|
export default PublishName;
|