mirror of
https://github.com/LBRYFoundation/lbry-desktop.git
synced 2025-09-03 02:35:12 +00:00
fix auto populate title logic
This commit is contained in:
parent
0b3fe001d0
commit
d93d97882b
3 changed files with 47 additions and 28 deletions
|
@ -35,6 +35,7 @@ type Props = {
|
||||||
autoPopulateName: boolean,
|
autoPopulateName: boolean,
|
||||||
setPublishMode: string => void,
|
setPublishMode: string => void,
|
||||||
setPrevFileText: string => void,
|
setPrevFileText: string => void,
|
||||||
|
setAutoPopulateName: boolean => void,
|
||||||
};
|
};
|
||||||
|
|
||||||
function PublishFile(props: Props) {
|
function PublishFile(props: Props) {
|
||||||
|
@ -60,6 +61,7 @@ function PublishFile(props: Props) {
|
||||||
setPublishMode,
|
setPublishMode,
|
||||||
setPrevFileText,
|
setPrevFileText,
|
||||||
autoPopulateName,
|
autoPopulateName,
|
||||||
|
setAutoPopulateName,
|
||||||
} = props;
|
} = props;
|
||||||
|
|
||||||
const ffmpegAvail = ffmpegStatus.available;
|
const ffmpegAvail = ffmpegStatus.available;
|
||||||
|
@ -217,15 +219,13 @@ function PublishFile(props: Props) {
|
||||||
return newName.replace(INVALID_URI_CHARS, '-');
|
return newName.replace(INVALID_URI_CHARS, '-');
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleTitleChange(e) {
|
function handleTitleChange(event) {
|
||||||
const newTitle = e.target.value;
|
const title = event.target.value;
|
||||||
const noName = !name || name.trim() === '';
|
|
||||||
const hasTitle = newTitle && newTitle.trim() !== '';
|
|
||||||
// Update title
|
// Update title
|
||||||
updatePublishForm({ title: newTitle });
|
updatePublishForm({ title });
|
||||||
// Auto-populate name from title
|
// Auto populate name from title
|
||||||
if (hasTitle && (noName || autoPopulateName)) {
|
if (autoPopulateName) {
|
||||||
updatePublishForm({ name: parseName(newTitle) });
|
updatePublishForm({ name: parseName(title) });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -313,6 +313,12 @@ function PublishFile(props: Props) {
|
||||||
if (!isStillEditing) {
|
if (!isStillEditing) {
|
||||||
publishFormParams.name = parseName(fileName);
|
publishFormParams.name = parseName(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Prevent name autopopulation from title
|
||||||
|
if (autoPopulateName) {
|
||||||
|
setAutoPopulateName(false);
|
||||||
|
}
|
||||||
|
|
||||||
// File path is not supported on web for security reasons so we use the name instead.
|
// File path is not supported on web for security reasons so we use the name instead.
|
||||||
setCurrentFile(file.path || file.name);
|
setCurrentFile(file.path || file.name);
|
||||||
updatePublishForm(publishFormParams);
|
updatePublishForm(publishFormParams);
|
||||||
|
|
|
@ -64,7 +64,6 @@ type Props = {
|
||||||
licenseType: string,
|
licenseType: string,
|
||||||
otherLicenseDescription: ?string,
|
otherLicenseDescription: ?string,
|
||||||
licenseUrl: ?string,
|
licenseUrl: ?string,
|
||||||
uri: ?string,
|
|
||||||
useLBRYUploader: ?boolean,
|
useLBRYUploader: ?boolean,
|
||||||
publishing: boolean,
|
publishing: boolean,
|
||||||
balance: number,
|
balance: number,
|
||||||
|
@ -86,6 +85,9 @@ function PublishForm(props: Props) {
|
||||||
const [mode, setMode] = React.useState(PUBLISH_MODES.FILE);
|
const [mode, setMode] = React.useState(PUBLISH_MODES.FILE);
|
||||||
const [autoSwitchMode, setAutoSwitchMode] = React.useState(true);
|
const [autoSwitchMode, setAutoSwitchMode] = React.useState(true);
|
||||||
|
|
||||||
|
// Used to checl if the url name has changed:
|
||||||
|
// A new file needs to be provided
|
||||||
|
const [prevName, setPrevName] = React.useState(false);
|
||||||
// Used to checl if the file has been modified by user
|
// Used to checl if the file has been modified by user
|
||||||
const [fileEdited, setFileEdited] = React.useState(false);
|
const [fileEdited, setFileEdited] = React.useState(false);
|
||||||
const [prevFileText, setPrevFileText] = React.useState('');
|
const [prevFileText, setPrevFileText] = React.useState('');
|
||||||
|
@ -124,9 +126,11 @@ function PublishForm(props: Props) {
|
||||||
const emptyPostError = mode === PUBLISH_MODES.POST && (!fileText || fileText.trim() === '');
|
const emptyPostError = mode === PUBLISH_MODES.POST && (!fileText || fileText.trim() === '');
|
||||||
const formDisabled = (fileFormDisabled && !editingURI) || emptyPostError || publishing;
|
const formDisabled = (fileFormDisabled && !editingURI) || emptyPostError || publishing;
|
||||||
const isInProgress = filePath || editingURI || name || title;
|
const isInProgress = filePath || editingURI || name || title;
|
||||||
|
|
||||||
// Editing content info
|
// Editing content info
|
||||||
const uri = myClaimForUri ? myClaimForUri.permanent_url : undefined;
|
const uri = myClaimForUri ? myClaimForUri.permanent_url : undefined;
|
||||||
const fileMimeType = myClaimForUri ? myClaimForUri.value.source.media_type : undefined;
|
const fileMimeType = myClaimForUri ? myClaimForUri.value.source.media_type : undefined;
|
||||||
|
const nameEdited = isStillEditing && name !== prevName;
|
||||||
|
|
||||||
// If they are editing, they don't need a new file chosen
|
// If they are editing, they don't need a new file chosen
|
||||||
const formValidLessFile =
|
const formValidLessFile =
|
||||||
|
@ -159,6 +163,15 @@ function PublishForm(props: Props) {
|
||||||
}
|
}
|
||||||
}, [thumbnail, resetThumbnailStatus]);
|
}, [thumbnail, resetThumbnailStatus]);
|
||||||
|
|
||||||
|
// Save current name of the editing claim
|
||||||
|
useEffect(() => {
|
||||||
|
if (isStillEditing && (!prevName || !prevName.trim() === '')) {
|
||||||
|
if (name !== prevName) {
|
||||||
|
setPrevName(name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, [name, prevName, setPrevName, isStillEditing]);
|
||||||
|
|
||||||
// Check for content changes on the text editor
|
// Check for content changes on the text editor
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!fileEdited && fileText !== prevFileText && fileText !== '') {
|
if (!fileEdited && fileText !== prevFileText && fileText !== '') {
|
||||||
|
@ -238,9 +251,9 @@ function PublishForm(props: Props) {
|
||||||
|
|
||||||
if (mode === PUBLISH_MODES.POST) {
|
if (mode === PUBLISH_MODES.POST) {
|
||||||
let outputFile = filePath;
|
let outputFile = filePath;
|
||||||
// If user modified content on the text editor:
|
// If user modified content on the text editor or editing name has changed:
|
||||||
// Save changes and updat file path
|
// Save changes and updat file path
|
||||||
if (fileEdited) {
|
if (fileEdited || nameEdited) {
|
||||||
// @if TARGET='app'
|
// @if TARGET='app'
|
||||||
outputFile = await saveFileChanges();
|
outputFile = await saveFileChanges();
|
||||||
// @endif
|
// @endif
|
||||||
|
@ -306,6 +319,7 @@ function PublishForm(props: Props) {
|
||||||
setPublishMode={setMode}
|
setPublishMode={setMode}
|
||||||
setPrevFileText={setPrevFileText}
|
setPrevFileText={setPrevFileText}
|
||||||
autoPopulateName={autoPopulateNameFromTitle}
|
autoPopulateName={autoPopulateNameFromTitle}
|
||||||
|
setAutoPopulateName={setAutoPopulateNameFromTitle}
|
||||||
/>
|
/>
|
||||||
{!publishing && (
|
{!publishing && (
|
||||||
<div className={classnames({ 'card--disabled': formDisabled })}>
|
<div className={classnames({ 'card--disabled': formDisabled })}>
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
// @flow
|
// @flow
|
||||||
import { CHANNEL_NEW, CHANNEL_ANONYMOUS, MINIMUM_PUBLISH_BID, INVALID_NAME_ERROR } from 'constants/claim';
|
import { CHANNEL_NEW, CHANNEL_ANONYMOUS, MINIMUM_PUBLISH_BID, INVALID_NAME_ERROR } from 'constants/claim';
|
||||||
import React, { useState, useEffect, useCallback } from 'react';
|
import React, { useState, useEffect } from 'react';
|
||||||
import { isNameValid } from 'lbry-redux';
|
import { isNameValid } from 'lbry-redux';
|
||||||
import { FormField } from 'component/common/form';
|
import { FormField } from 'component/common/form';
|
||||||
import NameHelpText from './name-help-text';
|
import NameHelpText from './name-help-text';
|
||||||
|
@ -48,23 +48,22 @@ function PublishName(props: Props) {
|
||||||
prepareEdit(myClaimForUri, uri);
|
prepareEdit(myClaimForUri, uri);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const handleNameChange = useCallback(
|
|
||||||
event => {
|
|
||||||
const newName = event.target.value;
|
|
||||||
const hasName = newName && newName.trim() !== '';
|
|
||||||
updatePublishForm({ name: newName });
|
|
||||||
|
|
||||||
// Don't autoPopulate name from title if user sets a custom name
|
function handleNameChange(event) {
|
||||||
if (hasName && autoPopulateName) {
|
updatePublishForm({ name: event.target.value });
|
||||||
setAutoPopulateName(false);
|
|
||||||
}
|
if (autoPopulateName) {
|
||||||
// Enable name autopopulation from title
|
setAutoPopulateName(false);
|
||||||
if (!hasName && !autoPopulateName) {
|
}
|
||||||
setAutoPopulateName(true);
|
}
|
||||||
}
|
|
||||||
},
|
useEffect(() => {
|
||||||
[autoPopulateName, setAutoPopulateName]
|
const hasName = name && name.trim() !== '';
|
||||||
);
|
// Enable name autopopulation from title
|
||||||
|
if (!hasName && !autoPopulateName) {
|
||||||
|
setAutoPopulateName(true);
|
||||||
|
}
|
||||||
|
}, [name, autoPopulateName, setAutoPopulateName]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
let nameError;
|
let nameError;
|
||||||
|
|
Loading…
Add table
Reference in a new issue