Properly handle thumbnail field in publish/edit upload/collection.
This commit is contained in:
parent
34ea712874
commit
02e4b651af
4 changed files with 39 additions and 21 deletions
|
@ -23,6 +23,7 @@ import CollectionForm from './view';
|
||||||
import { selectActiveChannelClaim, selectIncognito } from 'redux/selectors/app';
|
import { selectActiveChannelClaim, selectIncognito } from 'redux/selectors/app';
|
||||||
import { doSetActiveChannel, doSetIncognito } from 'redux/actions/app';
|
import { doSetActiveChannel, doSetIncognito } from 'redux/actions/app';
|
||||||
import { doCollectionEdit } from 'redux/actions/collections';
|
import { doCollectionEdit } from 'redux/actions/collections';
|
||||||
|
import { doResetThumbnailStatus } from 'redux/actions/publish';
|
||||||
|
|
||||||
const select = (state, props) => ({
|
const select = (state, props) => ({
|
||||||
claim: makeSelectClaimForUri(props.uri)(state),
|
claim: makeSelectClaimForUri(props.uri)(state),
|
||||||
|
@ -52,6 +53,7 @@ const perform = (dispatch, ownProps) => ({
|
||||||
setActiveChannel: (claimId) => dispatch(doSetActiveChannel(claimId)),
|
setActiveChannel: (claimId) => dispatch(doSetActiveChannel(claimId)),
|
||||||
setIncognito: (incognito) => dispatch(doSetIncognito(incognito)),
|
setIncognito: (incognito) => dispatch(doSetIncognito(incognito)),
|
||||||
doCollectionEdit: (params) => dispatch(doCollectionEdit(ownProps.collectionId, params)),
|
doCollectionEdit: (params) => dispatch(doCollectionEdit(ownProps.collectionId, params)),
|
||||||
|
resetThumbnailStatus: () => dispatch(doResetThumbnailStatus()),
|
||||||
});
|
});
|
||||||
|
|
||||||
export default connect(select, perform)(CollectionForm);
|
export default connect(select, perform)(CollectionForm);
|
||||||
|
|
|
@ -58,6 +58,7 @@ type Props = {
|
||||||
setActiveChannel: (string) => void,
|
setActiveChannel: (string) => void,
|
||||||
setIncognito: (boolean) => void,
|
setIncognito: (boolean) => void,
|
||||||
doCollectionEdit: (CollectionEditParams) => void,
|
doCollectionEdit: (CollectionEditParams) => void,
|
||||||
|
resetThumbnailStatus: () => void,
|
||||||
};
|
};
|
||||||
|
|
||||||
function CollectionForm(props: Props) {
|
function CollectionForm(props: Props) {
|
||||||
|
@ -92,6 +93,7 @@ function CollectionForm(props: Props) {
|
||||||
setIncognito,
|
setIncognito,
|
||||||
onDone,
|
onDone,
|
||||||
doCollectionEdit,
|
doCollectionEdit,
|
||||||
|
resetThumbnailStatus,
|
||||||
} = props;
|
} = props;
|
||||||
const activeChannelName = activeChannelClaim && activeChannelClaim.name;
|
const activeChannelName = activeChannelClaim && activeChannelClaim.name;
|
||||||
let prefix = 'lbry://';
|
let prefix = 'lbry://';
|
||||||
|
@ -158,7 +160,7 @@ function CollectionForm(props: Props) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleUpdateThumbnail(update: { [string]: string }) {
|
function handleUpdateThumbnail(update: { [string]: string }) {
|
||||||
if (update.thumbnail_url) {
|
if (update.thumbnail_url !== undefined) {
|
||||||
setParam(update);
|
setParam(update);
|
||||||
} else if (update.thumbnail_status) {
|
} else if (update.thumbnail_status) {
|
||||||
setThumbStatus(update.thumbnail_status);
|
setThumbStatus(update.thumbnail_status);
|
||||||
|
@ -309,6 +311,10 @@ function CollectionForm(props: Props) {
|
||||||
}
|
}
|
||||||
}, [uri, hasClaim]);
|
}, [uri, hasClaim]);
|
||||||
|
|
||||||
|
React.useEffect(() => {
|
||||||
|
resetThumbnailStatus();
|
||||||
|
}, [resetThumbnailStatus]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<div className={classnames('main--contained', { 'card--disabled': disabled })}>
|
<div className={classnames('main--contained', { 'card--disabled': disabled })}>
|
||||||
|
@ -358,8 +364,8 @@ function CollectionForm(props: Props) {
|
||||||
/>
|
/>
|
||||||
<fieldset-section>
|
<fieldset-section>
|
||||||
<SelectThumbnail
|
<SelectThumbnail
|
||||||
thumbnailParam={params.thumbnail_url}
|
thumbnail={params.thumbnail_url}
|
||||||
thumbnailParamError={thumbError}
|
thumbnailError={thumbError}
|
||||||
thumbnailParamStatus={thumbStatus}
|
thumbnailParamStatus={thumbStatus}
|
||||||
updateThumbnailParams={handleUpdateThumbnail}
|
updateThumbnailParams={handleUpdateThumbnail}
|
||||||
usePublishFormMode
|
usePublishFormMode
|
||||||
|
|
|
@ -5,11 +5,15 @@ import { doUpdatePublishForm, doResetThumbnailStatus } from 'redux/actions/publi
|
||||||
import { doOpenModal } from 'redux/actions/app';
|
import { doOpenModal } from 'redux/actions/app';
|
||||||
import PublishPage from './view';
|
import PublishPage from './view';
|
||||||
|
|
||||||
const select = (state) => ({
|
const select = (state, props) => {
|
||||||
...selectPublishFormValues(state),
|
const publishFormFields = selectPublishFormValues(state);
|
||||||
|
return {
|
||||||
|
...publishFormFields,
|
||||||
|
thumbnail: props.thumbnail || publishFormFields.thumbnail,
|
||||||
fileInfos: selectFileInfosByOutpoint(state),
|
fileInfos: selectFileInfosByOutpoint(state),
|
||||||
myClaimForUri: selectMyClaimForUri(state),
|
myClaimForUri: selectMyClaimForUri(state),
|
||||||
});
|
};
|
||||||
|
};
|
||||||
|
|
||||||
const perform = (dispatch) => ({
|
const perform = (dispatch) => ({
|
||||||
updatePublishForm: (value) => dispatch(doUpdatePublishForm(value)),
|
updatePublishForm: (value) => dispatch(doUpdatePublishForm(value)),
|
||||||
|
|
|
@ -69,10 +69,10 @@ function SelectThumbnail(props: Props) {
|
||||||
|
|
||||||
function handleThumbnailChange(e: SyntheticInputEvent<*>) {
|
function handleThumbnailChange(e: SyntheticInputEvent<*>) {
|
||||||
const newThumbnail = e.target.value.replace(' ', '');
|
const newThumbnail = e.target.value.replace(' ', '');
|
||||||
|
|
||||||
if (updateThumbnailParams) {
|
if (updateThumbnailParams) {
|
||||||
updateThumbnailParams({ thumbnail_url: newThumbnail });
|
updateThumbnailParams({ thumbnail_url: newThumbnail });
|
||||||
} else {
|
}
|
||||||
|
if (updatePublishForm) {
|
||||||
updatePublishForm({ thumbnail: newThumbnail });
|
updatePublishForm({ thumbnail: newThumbnail });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -108,16 +108,22 @@ function SelectThumbnail(props: Props) {
|
||||||
style={{ display: 'none' }}
|
style={{ display: 'none' }}
|
||||||
src={thumbnail}
|
src={thumbnail}
|
||||||
alt={__('Thumbnail Preview')}
|
alt={__('Thumbnail Preview')}
|
||||||
onError={() =>
|
onError={() => {
|
||||||
publishForm
|
if (updateThumbnailParams) {
|
||||||
? updatePublishForm({ thumbnailError: true })
|
updateThumbnailParams({ thumbnail_error: Boolean(thumbnail) });
|
||||||
: updateThumbnailParams({ thumbnail_error: Boolean(thumbnail) })
|
|
||||||
}
|
}
|
||||||
onLoad={() =>
|
if (publishForm) {
|
||||||
publishForm
|
updatePublishForm({ thumbnailError: true });
|
||||||
? updatePublishForm({ thumbnailError: !isUrlInput })
|
|
||||||
: updateThumbnailParams({ thumbnail_error: !isUrlInput })
|
|
||||||
}
|
}
|
||||||
|
}}
|
||||||
|
onLoad={() => {
|
||||||
|
if (updateThumbnailParams) {
|
||||||
|
updateThumbnailParams({ thumbnail_error: !isUrlInput });
|
||||||
|
}
|
||||||
|
if (publishForm) {
|
||||||
|
updatePublishForm({ thumbnailError: !isUrlInput });
|
||||||
|
}
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
@ -157,7 +163,7 @@ function SelectThumbnail(props: Props) {
|
||||||
onFileChosen={(file) =>
|
onFileChosen={(file) =>
|
||||||
openModal(MODALS.CONFIRM_THUMBNAIL_UPLOAD, {
|
openModal(MODALS.CONFIRM_THUMBNAIL_UPLOAD, {
|
||||||
file,
|
file,
|
||||||
cb: (url) => !publishForm && updateThumbnailParams({ thumbnail_url: url }),
|
cb: (url) => updateThumbnailParams && updateThumbnailParams({ thumbnail_url: url }),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
|
|
Loading…
Reference in a new issue