From 16b1605a3582d57dcf234ac8ebae0d280af10db9 Mon Sep 17 00:00:00 2001 From: infiinte-persistence Date: Tue, 11 Aug 2020 17:54:09 +0800 Subject: [PATCH] Add SETTINGS.ENABLE_PUBLISH_PREVIEW This option allows users to bypass the "publish preview" modal. Users can disable it by checking "don't show this again" in the modal, and re-enable it in the Settings Page. --- ui/component/publishForm/index.js | 3 +++ ui/component/publishForm/view.jsx | 4 +++- ui/component/publishSettings/index.js | 15 +++++++++++++ ui/component/publishSettings/view.jsx | 31 +++++++++++++++++++++++++++ ui/constants/settings.js | 1 + ui/modal/modalPublishPreview/index.js | 7 ++++-- ui/modal/modalPublishPreview/view.jsx | 18 +++++++++++++++- ui/page/settingsAdvanced/view.jsx | 3 +++ ui/redux/reducers/settings.js | 1 + 9 files changed, 79 insertions(+), 4 deletions(-) create mode 100644 ui/component/publishSettings/index.js create mode 100644 ui/component/publishSettings/view.jsx diff --git a/ui/component/publishForm/index.js b/ui/component/publishForm/index.js index 4635972b3..dd89ae1ca 100644 --- a/ui/component/publishForm/index.js +++ b/ui/component/publishForm/index.js @@ -11,10 +11,12 @@ import { doUpdatePublishForm, doPrepareEdit, doCheckPublishNameAvailability, + SETTINGS, } from 'lbry-redux'; import { doPublishDesktop } from 'redux/actions/publish'; import { selectUnclaimedRewardValue } from 'redux/selectors/rewards'; import { selectModal } from 'redux/selectors/app'; +import { makeSelectClientSetting } from 'redux/selectors/settings'; import PublishPage from './view'; const select = state => ({ @@ -29,6 +31,7 @@ const select = state => ({ isResolvingUri: selectIsResolvingPublishUris(state), totalRewardValue: selectUnclaimedRewardValue(state), modal: selectModal(state), + enablePublishPreview: makeSelectClientSetting(SETTINGS.ENABLE_PUBLISH_PREVIEW)(state), }); const perform = dispatch => ({ diff --git a/ui/component/publishForm/view.jsx b/ui/component/publishForm/view.jsx index e45bf0ef8..34aa5ffb9 100644 --- a/ui/component/publishForm/view.jsx +++ b/ui/component/publishForm/view.jsx @@ -79,6 +79,7 @@ type Props = { checkAvailability: string => void, ytSignupPending: boolean, modal: { id: string, modalProps: {} }, + enablePublishPreview: boolean, }; function PublishForm(props: Props) { @@ -116,6 +117,7 @@ function PublishForm(props: Props) { checkAvailability, ytSignupPending, modal, + enablePublishPreview, } = props; // Used to check if name should be auto-populated from title @@ -287,7 +289,7 @@ function PublishForm(props: Props) { } // Publish file if (mode === PUBLISH_MODES.FILE) { - if (isStillEditing) { + if (isStillEditing || !enablePublishPreview) { publish(filePath, false); } else { setPreviewing(true); diff --git a/ui/component/publishSettings/index.js b/ui/component/publishSettings/index.js new file mode 100644 index 000000000..7233f4994 --- /dev/null +++ b/ui/component/publishSettings/index.js @@ -0,0 +1,15 @@ +import { SETTINGS } from 'lbry-redux'; +import { connect } from 'react-redux'; +import { makeSelectClientSetting } from 'redux/selectors/settings'; +import { doSetClientSetting } from 'redux/actions/settings'; +import PublishSettings from './view'; + +const select = state => ({ + enablePublishPreview: makeSelectClientSetting(SETTINGS.ENABLE_PUBLISH_PREVIEW)(state), +}); + +const perform = dispatch => ({ + setEnablePublishPreview: value => dispatch(doSetClientSetting(SETTINGS.ENABLE_PUBLISH_PREVIEW, value)), +}); + +export default connect(select, perform)(PublishSettings); diff --git a/ui/component/publishSettings/view.jsx b/ui/component/publishSettings/view.jsx new file mode 100644 index 000000000..d59d4e6ea --- /dev/null +++ b/ui/component/publishSettings/view.jsx @@ -0,0 +1,31 @@ +// @flow +import React from 'react'; +import { FormField } from 'component/common/form'; +import { withRouter } from 'react-router'; + +type Props = { + enablePublishPreview: boolean, + setEnablePublishPreview: boolean => void, +}; + +function PublishSettings(props: Props) { + const { enablePublishPreview, setEnablePublishPreview } = props; + + function handleChange() { + setEnablePublishPreview(!enablePublishPreview); + } + + return ( +
+ +
+ ); +} + +export default withRouter(PublishSettings); diff --git a/ui/constants/settings.js b/ui/constants/settings.js index 56bfae976..34da2209b 100644 --- a/ui/constants/settings.js +++ b/ui/constants/settings.js @@ -23,3 +23,4 @@ export const FLOATING_PLAYER = 'floating_player'; export const DARK_MODE_TIMES = 'dark_mode_times'; export const ENABLE_SYNC = 'enable_sync'; export const TO_TRAY_WHEN_CLOSED = 'to_tray_when_closed'; +export const ENABLE_PUBLISH_PREVIEW = 'enable-publish-preview'; diff --git a/ui/modal/modalPublishPreview/index.js b/ui/modal/modalPublishPreview/index.js index 68cd22599..f6d8de221 100644 --- a/ui/modal/modalPublishPreview/index.js +++ b/ui/modal/modalPublishPreview/index.js @@ -1,19 +1,22 @@ import { connect } from 'react-redux'; import { doHideModal } from 'redux/actions/app'; import ModalPublishPreview from './view'; -import { makeSelectPublishFormValue, selectPublishFormValues } from 'lbry-redux'; -import { selectFfmpegStatus } from 'redux/selectors/settings'; +import { makeSelectPublishFormValue, selectPublishFormValues, SETTINGS } from 'lbry-redux'; +import { selectFfmpegStatus, makeSelectClientSetting } from 'redux/selectors/settings'; import { doPublishDesktop } from 'redux/actions/publish'; +import { doSetClientSetting } from 'redux/actions/settings'; const select = state => ({ ...selectPublishFormValues(state), isVid: makeSelectPublishFormValue('fileVid')(state), ffmpegStatus: selectFfmpegStatus(state), + enablePublishPreview: makeSelectClientSetting(SETTINGS.ENABLE_PUBLISH_PREVIEW)(state), }); const perform = dispatch => ({ publish: (filePath, preview) => dispatch(doPublishDesktop(filePath, preview)), closeModal: () => dispatch(doHideModal()), + setEnablePublishPreview: value => dispatch(doSetClientSetting(SETTINGS.ENABLE_PUBLISH_PREVIEW, value)), }); export default connect(select, perform)(ModalPublishPreview); diff --git a/ui/modal/modalPublishPreview/view.jsx b/ui/modal/modalPublishPreview/view.jsx index f90f0b901..a2a390668 100644 --- a/ui/modal/modalPublishPreview/view.jsx +++ b/ui/modal/modalPublishPreview/view.jsx @@ -1,7 +1,7 @@ // @flow import React from 'react'; import Button from 'component/button'; -import { Form } from 'component/common/form'; +import { Form, FormField } from 'component/common/form'; import { Modal } from 'modal/modal'; import Card from 'component/common/card'; import Tag from 'component/tag'; @@ -31,6 +31,8 @@ type Props = { previewResponse: PublishResponse, publish: (?string, ?boolean) => void, closeModal: () => void, + enablePublishPreview: boolean, + setEnablePublishPreview: boolean => void, }; class ModalPublishPreview extends React.PureComponent { @@ -58,6 +60,11 @@ class ModalPublishPreview extends React.PureComponent { ); } + togglePreviewEnabled() { + const { enablePublishPreview, setEnablePublishPreview } = this.props; + setEnablePublishPreview(!enablePublishPreview); + } + render() { const { filePath, @@ -78,6 +85,8 @@ class ModalPublishPreview extends React.PureComponent { ffmpegStatus = {}, previewResponse, closeModal, + enablePublishPreview, + setEnablePublishPreview, } = this.props; const modalTitle = __('Confirm Publish'); @@ -145,6 +154,13 @@ class ModalPublishPreview extends React.PureComponent {