lbry-desktop/ui/component/publishName/view.jsx
Rave | 図書館猫 81eddb2b5d
Publish revamp (Part 1) (#1593)
* Rearrange fields

* Autocomplete title

* Fix class position

* Hide deposit behind advanced settings

* Redesign additional options

* Redesign price section

* Update price section

* Redesign tags section

* Fix title edit

* Make with dynamic

* Redesign thumbnail section

* Redesign description section

* Resedign file section

* Polish sections

* Adjust help text

* Clear title on form reset

* Adjust price section

* Fix help color in light theme

* Polish

* Mobile adjustments

* More mobile adjustments

* Remove border-bottom from publish rows

* Redesign date section

* Adjust some details

* Adjust clear button

* Adjust channel selector on mobile

* Adjust post save button position

* Adjust browse button color

* Adjust channel picker on mobile

* Eenable announcement page

* Remove file title, remove space, redesign licence section

* Fix edit form, existing claim warning, missing title warning

* Adjust light theme

* Adjust icon collor in button
2022-06-03 09:28:12 -04:00

101 lines
2.6 KiB
JavaScript

// @flow
import { DOMAIN } from 'config';
import { INVALID_NAME_ERROR } from 'constants/claim';
import React, { useState, useEffect } from 'react';
import { isNameValid } from 'util/lbryURI';
import { FormField } from 'component/common/form';
import NameHelpText from './name-help-text';
type Props = {
name: string,
uri: string,
isStillEditing: boolean,
myClaimForUri: ?StreamClaim,
myClaimForUriCaseInsensitive: ?StreamClaim,
amountNeededForTakeover: number,
prepareEdit: ({}, string) => void,
updatePublishForm: ({}) => void,
activeChannelClaim: ?ChannelClaim,
incognito: boolean,
currentUploads: { [key: string]: FileUploadItem },
};
function PublishName(props: Props) {
const {
name,
uri,
isStillEditing,
myClaimForUri,
myClaimForUriCaseInsensitive,
prepareEdit,
updatePublishForm,
activeChannelClaim,
incognito,
currentUploads,
} = props;
const [nameError, setNameError] = useState(undefined);
const [blurred, setBlurred] = React.useState(false);
const activeChannelName = activeChannelClaim && activeChannelClaim.name;
let prefix = IS_WEB ? `${DOMAIN}/` : 'lbry://';
if (activeChannelName && !incognito) {
prefix += `${activeChannelName}/`;
}
function editExistingClaim() {
if (myClaimForUri) {
prepareEdit(myClaimForUri, uri);
}
}
function handleNameChange(event) {
updatePublishForm({ name: event.target.value });
}
useEffect(() => {
if (!blurred && !name) {
return;
}
let nameError;
if (!name) {
nameError = __('A name is required');
} else if (!isNameValid(name)) {
nameError = INVALID_NAME_ERROR;
}
setNameError(nameError);
}, [name, blurred]);
return (
<>
<fieldset-group class="fieldset-group--smushed fieldset-group--disabled-prefix">
<fieldset-section>
<label>{__('URL')}</label>
<div className="form-field__prefix">{prefix}</div>
</fieldset-section>
<FormField
type="text"
name="content_name"
value={name}
error={nameError}
disabled={isStillEditing}
onChange={handleNameChange}
onBlur={() => setBlurred(true)}
/>
</fieldset-group>
<div className="form-field__help">
<NameHelpText
uri={uri}
isStillEditing={isStillEditing}
myClaimForUri={myClaimForUri}
myClaimForUriCaseInsensitive={myClaimForUriCaseInsensitive}
currentUploads={currentUploads}
onEditMyClaim={editExistingClaim}
/>
</div>
</>
);
}
export default PublishName;